zoukankan      html  css  js  c++  java
  • OCM读书笔记(2)

    1. % type 用法,提取% type所在字段的类型


    declare
        myid dept.deptno % type;
        myname dept.dname % type;
    begin
        select deptno, dname into myid, myname from dept where deptno = 10;
        dbms_output.put_line(myid);
        dbms_output.put_line(myname);
    end;2. % rowtype 用法,提取% rowtype所在字段的类型


    declare
        type type_dept is table of dept % rowtype index by binary_integer;
        tb type_dept;
    begin
        tb(1).deptno:='001';
        tb(2).deptno:='002';
        dbms_output.put_line(tb.COUNT);
    end;
    /3. TYPE用法,相当于结构体


    declare
        lv_order_date DATE:=sysdate;
        lv_last_tr varchar2(5) default '001';
        lv_last varchar2(10) not null:='us';
        TYPE type_test is record(
            myid dept.deptno % type,
            myname dept.dname % type
        );
        rec type_test;
    begin
        dbms_output.put_line(lv_last);
        select deptno, dname into rec from dept where deptno=10;
        dbms_output.put_line(rec.myid);
        dbms_output.put_line(rec.myname);
    end;
    /4. 游标的使用


    declare
        g_id number(2) := 20;
        find_not char(1) := 'N';
        cursor cur is select * from dept;
        TYPE type_dept is record(
            myid dept.deptno % type,
            myname dept.dname % type,
            myaddr dept.loc % type
        );
        rect type_dept;
    begin
        open cur;
        loop
            fetch cur into rect;
            exit when cur%     NOTFOUND;
            if rect.myid = g_id then
                dbms_output.put_line('Find it!!');
                dbms_output.put_line('DEPT NO: ' || rect.myid);
                dbms_output.put_line('DNAME: ' || rect.myname);
                dbms_output.put_line('LOC: ' || rect.myaddr);
            end if;
        end loop;
        close cur;
       
        if find_not = 'N' then
            dbms_output.put_line('No Record');
        end if;
    end;
    /5. for循环

    begin
        for i in 1..5 loop
            dbms_output.put_line(i);
        end loop;
    end;
    /6. loop循环


    declare
        v number := 1;
    begin
        loop
            exit when v > 5;
            dbms_output.put_line(v);
            v := v+1;
        end loop;
    end;
    / 7. while循环


    declare
        v number := 1;
    begin
        while v <= 5 loop
            dbms_output.put_line(v);
            v := v+1;
        end loop;
    end;
    /

  • 相关阅读:
    RabbitMQ和Kafka的区别
    如何在 Vim 中复制,剪切,粘贴
    python中的堆支持自定义的比较函数
    LLDP协议(笔记草稿)
    You may have an infinite update loop in a component render function,vue模板报错
    修改element ui样式,el-dialog__header样式,并且不影响全局
    js,小数字符串去除右边零显示
    egg-sequelize创建表
    Cyclic dependency found. Users is dependent of itself,mysql表循环依赖问题
    eggjs sequelize操作多个数据,表名不加s,不默认加创建和修改时间字段
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3357884.html
Copyright © 2011-2022 走看看