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;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值