?
?? insert
into
t1
values
(
90
,
'SERVICE'
,
'
?? Returning
rowid
,
name
into
row_id,info;
?
??? SQL> variable x number ;
??? SQL> exec :x := 8600 ;
??? SQL> select * from ldcom where comcode= :x ;
?
??? variable
x
number
;
??? declare
????? v_date
date
;
??? begin
????? for
i
in
?
1
..
10
loop
??? ??? :x := i;
???
???
select
sysdate
+:x
into
v_date
from
dual;
??? ??? dbms_output.put_line(v_date);
???
?
end
loop
;
???
end
;
??? /
?
??? declare
??? v_x t1.num%
type
;
??? begin
??? execute
immediate
'update t1 set num=8888 where id=:a returning num into :b'
??? using
2
returning
into
v_x;
??? dbms_output.put_line(v_x);
??? end ;
??? 注意returning的返回值在動態SQL中的操作格式
?
??? for i in reverse 10 .. 100 loop
??? cursor
c2(dept_no
number
default
10
)
is----注意定義dept_no的方法
??? select
name
,agentcode
from
laagent
where
rownum <= dept_no;
??? open
c3(dept_no =>
20
);
----
可以重新定義
dept_no
??? fetch
c2
into
dept_name,dept_loc;
----
字符類型、個數相等
??? fetch
c3
into
deptrec;
----deptrec
為
rowtype
??? exit
when
c3%
notfound
;
??? CLOSE c3;
??? %
FOUND
?????
--
布爾型屬性,當最近一次讀記錄時成功返回
,
則值為
TRUE
;
??? %
NOTFOUND
??
--
布爾型屬性,與
%FOUND
相反;
??? %
ISOPEN
????
--
布爾型屬性,當游標已打開時返回
TRUE
;
??? %
ROWCOUNT
??
--
數字型屬性,返回已從游標中讀取的記錄數。
?
??? FOR
c1_rec
IN
c1
LOOP
??? FOR
c1_rec
IN
(
SELECT
dname, loc
FROM
dept)
LOOP
?
??? SQL%
FOUND
?????
--
布爾型屬性,當最近一次讀記錄時成功返回
,
則值為
TRUE
;
??? SQL%
NOTFOUND
??
--
布爾型屬性,與
%FOUND
相反;
??? SQL%
ISOPEN
????
--
布爾型屬性,當游標已打開時返回
TRUE
;
??? SQL% ROWCOUNT ?? -- 數字型屬性,返回已從游標中讀取的記錄數。
????? ?? IF SQL % NOTFOUND THEN ...
?
??? CURSOR
emp_cursor
is
select
empno,sal
??? from
emp
where
deptno=v_deptno
for
update
of
sal
nowait
;
??? for
emp_record
in
emp_cursor
loop
?
??? if
emp_record.sal <
1500
then
?????
?
update
emp
set
sal=
1500
where
current
of
emp_cursor;
?
??? end
if
;
??? end loop ;
??? 但需注意:只能針對for update的表進行修改。