Listen Software解決方案 "How To" 系列2:存儲(chǔ)過程
2024-07-21 02:08:45
供稿:網(wǎng)友
,歡迎訪問網(wǎng)頁設(shè)計(jì)愛好者web開發(fā)。
listen software解決方案 “how to” 系列2:存儲(chǔ)過程
參照:
參照定義和使用游標(biāo)
參照定義和使用函數(shù)
存儲(chǔ)過程
create or replace procedure {procedure name}
( {argument} in {datatype} ) is v_variable {datatype};
--變量類型
varchar(x);
varchar2(x);
varchar2;
char(x);
number(p,s);
--p-數(shù)字的位數(shù)
--s-數(shù)字的精度
number(x);
number;
long;
--容納32,760字節(jié)數(shù)據(jù)
double precision;
float;
int;
real;
date;
raw(x)
--容納32,760字節(jié)數(shù)據(jù)
long raw;
--容納32,760字節(jié)數(shù)據(jù)
--注意數(shù)據(jù)庫類型為long raw
--容納20億字節(jié)數(shù)據(jù)
record;
table;
varray;
lob;
clob;
v_variable_c1 varchar2(20);
--創(chuàng)建20個(gè)字符長的變量
v_variable_c2 char(10);
--創(chuàng)建固定長度為10個(gè)字符的變量
- 最大長度255
v_variable_c3 varchar2;
--變量長度不能超過2000個(gè)字符
v_variable_n1 table_name.field_name%type;
--定義參照方案中表字段類型的變量類型
v_variable_n2 number;
v_variable_n3 number := 3;
v_variable_n4 number(10);
v_variable_n5 number(10,2);
v_variable_n6 long;
v_variable_n7 float;
v_variable_n8 real;
type t_my_record is record
(
v_variable1 varchar2(8)
,v_variable2 number(10)
,v_variable3 date
);
my_record t_my_record;
type t_my_table is table of varchar2(10)
--與vb中的數(shù)據(jù)結(jié)構(gòu)相似
index by binary_integer;
my_table t_my_table;
begin
--這兒插入代碼
v_variable_c1 := 'hello world';
v_variable_n2 :=10;
--條件邏輯
if v_variable_n2 = 1 then
v_variable_c2 := 'exact match';
elsif v_variable_n3 > 2 then
v_variable_c2 := 'greater than match';
else
v_variable_c3 := 'none of the above';
end if;
my_record.v_variable1:='abc';
my_record.v_variable2:=3;
my_record.v_variable3:=to_date('11-jan-1999','dd-mon-yyyy');
my_table(1)='a';
my_table(2)='b';
/* v_variable_n2的值為10,因此第一個(gè)條件為false.
v_variable_n3初始為3,因此條件為true,
v_variable_c2的值就為'greater than match'
循環(huán) */
v_variable_n2:=0;
loop
v_variable_n2:=v_variable_n2+1;
exit when v_variable_n2 > 10;
end loop;
v_variable_n2:=0;
while v_variable_n2<10 loop
v_variable_n2:=v_variable_n2+1;
end loop;
for v_variable_n2 in 1..10 loop
end loop;
end {procedure name};