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;
    /

  • 相关阅读:
    前端 fetch 通信
    编写高质量的JavaScript代码(一)
    Redis学习笔记1-Redis的介绍和认识
    gitignore不起作用解决的方法
    【我的面经】说说简历的细节——软件开发岗位
    菜鸟的mongoDB学习---(七)MongoDB 备份(mongodump)与恢复(mongorerstore)
    HDU 4927 Series 1
    树状数组求第K小值 (spoj227 Ordering the Soldiers &amp;&amp; hdu2852 KiKi&#39;s K-Number)
    git和SVN的差别
    KVM-Introduce
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3357884.html
Copyright © 2011-2022 走看看