Java----使用者互動Scanner
阿新 • • 發佈:2021-06-28
<!doctype html>
Oracle
儲存過程
是儲存在資料庫裡的
pl/sql語言基礎
- 遊標
xxxxxxxxxx
10
1
declare
2
cursor name is select......
3
begin
4
open name;
5
loop
6
fetch name into ....
7
exit when name%notfound;
8
end loop;
9
close name;
10
end;
xxxxxxxxxx
11
1
declare
2
cursor name is ...
3
begin
4
open name;
5
fetch name into ....
6
while name%found loop
7
...
8
fetch name into ......;
9
end loop;
10
close loop;
11
end;
%found:判斷最近一次使用fetch語句是否從快取中檢索導資料,如果檢索到資料,返回true,否則返回false;(經常與while連用)
%notfound:判斷最近一次使用fetch語句是否從快取中檢索導資料,如果沒有檢索到資料,返回true,否則返回false;(經常與when連用)
pl/sql程式開發
- 儲存過程
xxxxxxxxxx
10
1
create or replace procedure lisi(
2
id student.studentId%type,
3
na student.name%type)
4
as
5
begin
6
update student set studentId=id, name=na where studentId=id;
7
exception
8
when others then
9
DBMS_OUTPUT.PUT('無法修改');
10
end;
- 函式
xxxxxxxxxx
8
1
create or replace function jindao
2
return number
3
as
4
c number;
5
begin
6
select COUNT(*) into c from student where name='金導';
7
return c;
8
end jindao;
- 包
xxxxxxxxxx
5
1
create or replace package pkg
2
as
3
procedure hello;
4
FUNCTION getid(id number) return number;
5
end pkg;
- 包體
xxxxxxxxxx
13
1
create or replace package body pkg
2
as
3
procedure hello
4
as
5
begin
6
dbms_output.put_line('hello');
7
end hello;
8
FUNCTION getid(id number) return number
9
as
10
begin
11
return id;
12
end getid;
13
end pkg;
- 呼叫包
xxxxxxxxxx
7
1
declare
2
c number;
3
begin
4
pkg.hello;
5
c:=pkg.getid(1);
6
DBMS_OUTPUT.put_line(c);
7
end;
- 觸發器
xxxxxxxxxx
5
1
create or replace trigger jindaogrant
2
after update or delete on student
3
begin
4
DBMS_OUTPUT.put_line('觸發器發現你了');
5
end;