Oracle的PL_SQL的结构

--PL/SQL的结构
declare --声明变量和常量关键字
       v_name nvarchar2(20);
       v_age integer;--常规变量声明
       v_product table_name.column_name%type;--根据表字段的类型来生命变量
       v_con constant int:=12;
       v_convar constant nvarchar2(20):='常量';--声明常量必须添加关键字constant
       --声明复合类型变量
       type product_rec is record (
       id int,
       name table_name.column_name%type,
       age number(10,2)
       );
       
       v_prod product_rec;
       
       --利用rowtype声明复合变量
       --v_prod_d table_name%rowtype;
       
       --索引表类型声明
       type productinfo is table of varchar2(40) index by pls_integer;--pls_integer和Binary_integer效果是一样的,指定索引类型。
       type producttype is table of table_name%rowtype index by binary_integer;
       --生命索引表类型的变量
       v_procinfo productinfo;
       v_producttype producttype;
       
       --vArray变量数组
       type v_array is varray(100) of varchar2(20);
       
       v_arry v_array:=v_array('1','2');--v_array('1','2')初始化两个下标数据
       
       

begin
--代码执行的开始部分
 v_name:='小马';
 
 select 'xiaoxiao' into v_name from dual;
 
 --复合变量的使用
 v_prod.id:=1;
 v_prod.name:='小黑';
 v_prod.age:=34;
 --索引变量的使用
 v_procinfo(1):='xixix';
 --给变长数组的赋值
 v_arry(1):='this';
 v_arry(2):='this aa';
 
 
 
exception--程序出现异常执行部分
when NO_DATA_FOUND then
 dbms_output.put_line('程序异常。');

end;

原文地址:https://www.cnblogs.com/gynbk/p/6556118.html