CURSOR 游标
游标属性:
cur_tmp%found 至少影响到一行数据为true;
cur_tmp%notfound 与%found相反
cur_tmp%rowcount 返回受SQL语句影响的行数
cur_tmp%isopen 游标打开时为true
- 显示 cursor
--显示cursor
set serveroutput on
declare
cursor cur_emp(var_name in varchar2:='lili')
is select cust_no,cust_name,address from t_cscustomer where cust_name like var_name||'%';
type record_emp is record
(
var_empno t_cscustomer.cust_no%type,
var_empname t_cscustomer.cust_name%type,
var_empaddress t_cscustomer.address%type
);
emp_row record_emp;
begin
DBMS_OUTPUT.ENABLE(buffer_size => null); --表示输出buffer不受限制
open cur_emp('刘');
fetch cur_emp into emp_row;
while cur_emp%found loop
dbms_output.put_line(emp_row.var_empname||'的编号是'||emp_row.var_empno||',地址是'||emp_row.var_empaddress);
fetch cur_emp into emp_row;
end loop;
close cur_emp;
end;
/
- for 中使用cursor 不用进行打开游标、读取游标、关闭游标 oracle内部自动完成
declare cursor cur_emp is select cust_name var_ename,linkphone var_phone,address var_sal from t_cscustomer where address like '%招南%0402室%'; begin DBMS_OUTPUT.ENABLE(buffer_size => null); --表示输出buffer不受限制 for empinfo in cur_emp loop dbms_output.put_line('雇员'||empinfo.var_ename||'的电话是'||empinfo.var_phone||'、地址是'||empinfo.var_sal); end loop; end; /
- 自定义异常
--自定义异常
declare
v_num number := 0;
myexc exception; --定义一个异常变量
begin
v_num := 1 + 1;
raise myexc;
exception
when myexc then
dbms_output.put_line('自定义异常');
retrun;
end;
/
- 存储过程、函数、触发器、包