PL/SQL程序简要

declare

    --声明变量
    test integer:=0;
    test1 varchar2(100);
    field1 yourtable.tablefield%type;

    /*变量类型
    CHAR(Character String Rowid Nchar)定长
    VARCHAR2(Varchar, String NVARCHAR2)可变
    BINARY_INTEGER 带符号整数,
    NUMBER(p,s)
        1.Dec 小数, NUMBER的子类型
        2.Double precision 双精度浮点126位实数
        3.Integer 整数, NUMBER的子类型
        4.Int Numeric与NUMBER等价
        5.Real 精度达到63的实数类型
        6.Small int  整数,比 integer小    
    LONG 变长字符串
    DATE BOOLEAN
    ROWID 存放数据库行号 UROWID 通用行标识符,字符类型*/

    --数组类型
    type array1 is varray(5) of varchar(100);
    arrayname array1;

    --记录类型
    type record1 is record(
         test integer:=0;
         test1 varchar2(100);
    recordname record1;


    --游标类型
    cursor curors(parameter1,parameter2)
           return returnVal
    is
      select * from yourtable
      where conditions is null;
    self_record curors%rowtype;


begin


    --数组赋值
    arrayname := array1('val1', 'val2', 'val3', 'val4', 'val5');


    --隐式游标
    for t in()loop
    end loop;


    --显式游标
    open curors(parameter1 => value1, parameter2 => value2)
      loop
        fetch curors into self_record;

          if curors%found then
             null;
          else
             null;
             exit;

          end if;
      end loop;   
   close curors;


   --游标for循环
   for t in curors(parameter1,parameter2) loop
       null;
   end loop;


   --隐式游标名为sql
   type1:=sql%rowcount;

   --条件表达式
   if conditions then
      null;
   end if;


   if conditions then
      null;
   else
      null;
   end if;


   if conditions then
      null;
   elsif
conditions then
      null;
   elsif
conditions then
      null;
   else
      null;
   end if;



   --查询赋值
   select field into parameter1
   from yourtable
   where conditions is null;

   --内置函数
   field1 := to_number('100.0') + 1;
   field2 := to_char('123.45') ||'元';
   field3 := to_date('1999-99-99','yyyy-mm-dd hh24:mi:ss');
   field4 := to_char(sysdate,'yyyy-mm-dd hh24:mi:ss');
   str:=substr(field,startpos,length);


   --输出字段和字符串
   dbms_output.put_line(field1||'string'||field2);


   --异常处理
   Exception
       when
exception1 then  null;
       when exception2 then  null;
       when others then  null;
end;

猜你喜欢

转载自zonghengmodao.iteye.com/blog/1425286