PLSQLについて
- PL / SQLプログラミング言語
- PL / SQLのSQLプログラミング言語、言語の拡張であり、複数のSQL手続き型言語プログラミングする特性を有しています
- PL / SQLプログラミング言語は、より一般的な手続き型言語より柔軟かつ効率的です
- PL / SQLプログラミング言語は、主に、ストアドプロシージャと他の関数を記述するために使用します
定義と出力
declare
i number(2) :=15;
begin
dbms_output.put_line(i);
end;
结果:
15
declare
i number(2) :=15;
s varchar2(10) := '小明';
begin
dbms_output.put_line(i);
dbms_output.put_line(s);
end;
结果
15
小明
declare
i number(2) :=15;
s varchar2(10) := '小明';
eb E_BOOK.name%type; --引用型变量
begin
dbms_output.put_line(i);
dbms_output.put_line(s);
select name into eb from E_BOOK where id=1;
dbms_output.put_line(eb);
end;
结果
15
小明
文学类书1
declare
i number(2) :=15;
s varchar2(10) := '小明';
eb E_BOOK.name%type; --引用型遍历
bookrow E_BOOK%rowtype; --记录型变量
begin
dbms_output.put_line(i);
dbms_output.put_line(s);
select name into eb from E_BOOK where id=1;
dbms_output.put_line(eb);
select * into bookrow from E_BOOK where id=1;
dbms_output.put_line('id为:' ||bookrow.id ||' name为:' || bookrow.name);
end;
结果
15
小明
文学类书1
id为:1 name为:文学类书1
裁判官の場合
トピック:
- デジタル入力、マイナー以下18以上の出力
- 18未満、40デジタル入力よりも大きい、中年の出力
- 40は、高齢者の出力ディジタル入力よりも大きいです
declare
i number(3) := 19;
begin
if i<18 then
dbms_output.put_line('未成年');
elsif i<40 then
dbms_output.put_line('中年人');
else
dbms_output.put_line('老年人');
end if;
end;
结果
中年人
循環
3つの方法で出力1-10
whileループ
declare
i number(2) := 1;
begin
while i<11 loop
dbms_output.put_line(i);
i := i+1;
end loop;
end;
结果:
1
2
3
4
5
6
7
8
9
10
出口ループ(共通)
declare
i number(2) := 1;
begin
loop
exit when i>10;
dbms_output.put_line(i);
i := i+1;
end loop;
end;
结果:
1
2
3
4
5
6
7
8
9
10
forループ
declare
begin
for i in 1..10 loop
dbms_output.put_line(i);
end loop;
end;
结果:
1
2
3
4
5
6
7
8
9
10
カーソル
カーソル:あなたは複数のオブジェクトを格納することができ、(Javaドメインのセットと同様に)複数の行
出力テーブル名のすべての行
declare
cursor c is select * from e_book;
--定义了一个名为c的游标 并把表中的所有数据存入游标中
bookrow e_book%rowtype;
begin
open c;
loop
fetch c into bookrow;
exit when c%notfound;
dbms_output.put_line(bookrow.name);
end loop;
close c;
end;
结果:
文学类书1
文学类书2
文学类书3
社会科学书1
社会科学书2
社会科学书3
小说书1
小说书2
小说书3
価格指定されたブックを大きくするには
...
ストアドプロシージャ
ストアドプロシージャ:PL / SQL言語のために事前にコンパイルされたストアドプロシージャは、データベースに入れは、直接呼び出すことができます。このセクションでは、PL / SQL操作は、一般的に固定されている手順
--给指定书的价格加100块钱
create or replace procedure p1(bid e_book.id%type)
is
begin
update e_book set price = price+100 where id=bid;
commit;
end;
--测试
declare
begin
p1(1);
end;
ストレージ機能(理解)
ストアドプロシージャとストレージ機能を服用しないでください
一般的には、プロシージャと関数差関数が値を返すことができ、そしてプロセスは値を返しませんが、プロシージャと関数は、1つまたは複数の出力パラメータを指定することができ、我々はパラメータ、プロシージャと関数を使用することができます複数の値を返す達成
--通过储存函数实现计算指定书籍的10本的价格
--存储过程和存储函数的参数都不能带长度
--存储函数的返回值类型不能带长度
create or replace function x(bid e_book.id%type) return number --不能带长度
is
s number(10);
begin
select price*10 into s from e_book where id=bid;
return s;
end;
--测试
--存储函数在调用的时候,返回值需要接收
declare
s number(10);
begin
s := x(1);
dbms_output.put_line(s);
end;
typeパラメータを使用する方法を
--out类型参数如何使用
--使用存储过程来算10*价格
create or replace procedure z(bid e_book.id%type, p out number)
is
s number(10);
begin
select price*10 into s from e_book where id=bid;
p := s;
end;
--测试
declare
pp number(10);
begin
z(1,pp);
dbms_output.put_line(pp);
end;
结果
22000
ある型パラメータ内外に何かを取ってはいけませんか?
の他に、=パラメータ割り当て、アウト変更するために使用する必要がありますまたは任意のデザインは、クエリにコピーします