標籤:declare row rowtype data bms 初始化 rom char type
--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;
Oracle的PL_SQL的結構