oracle 笔记 VI 之游标 (CURSOR)
游标(CURSOR),很重要
游标:用于处理多行记录的事务
游标是一个指向上下文的句柄(handle)或指针,简单说,游标就是一个指针
1 处理显式游标
显式游标处理需 4个 PL/SQL 步骤,显示游标主要用于处理查询语句
(1) 定义游标
格式: CURSOR cursor_name [(partment[,parameter]...)] IS select_statement;
定义的游标不能有 INTO 子句
(2) 打开游标
OPEN cursor_name[...];
PL/SQL 程序不能用 OPEN 语句重复打开一个游标
(3)提取游标数据
FETCH cursor_name INTO {variable_list | record_variable};
(4) 关闭游标
CLOSE cursor_name;
例 1 查询前 10 名员工的信息
declare
--定义游标
cursor c_cursor is select last_name,salary from employees where rownum < 11 order by salary;
v_name employees.last_name%type;
V_sal employees.salary%type;
begin
--打开游标
open c_cursor;
-- 提取游标数据
fetch c_cursor into v_name,v_sal;
while c_cursor %found loop
dbms_output.put_line(v_name || ':' || v_sal);
fetch c_cursor into v_name,v_sal;
end loop;
--关闭游标
close c_cursor;
end;
----------------------------------
练习: 输入部门号 dep_id,查询该部门的平均工资 : avg_sal,员工工资为 salary
若 salary < avg_sal - 500 工资涨 500
若 avg_sal - 500 <= salary < avg_sal + 500 工资涨 300
若
相关文档:
DML(Manipulation):数据操作语言
CRUD
DDL(Definition): 数据定义语言,与表,索引,同义词有关
create,alter,drop,rename,truncate(清空)
DCL(Control): 数据控制语言,与权限有关
grant,revoke
TCL(Transaction Control): 事务控制语言,与事务有关
commit,rollback,savepoint
==========================
存储 ......
This course is aim to train the great DBA with good English speaking.
In recent years, more demands of Oracle DBA, but most of Senior DBAs are required to speak good English.
English has become the great barrier for more peoples in their career development, you must have the deep feeling about it ......
1、用dblink链接oracle
(1)与平台无关的写法:
create public database
link cdt connect to apps
identified by apps using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.31.205.100)(PORT = 1541))
)
(CONNECT_DATA =
(SERVICE_NAME = CDT)
)
)'
(2)可以将单引号内的内容 ......
Oracle中USERENV和SYS_CONTEXT用来返回当前session的信息,其中,userenv是为了保持向下兼容的遗留函数,推荐使用sys_context函数调用userenv命名空间来获取相关信息。
1、 USERENV(OPTION)
返回当前的会话信息.
OPTION='ISDBA'若当前是DBA角色,则为TRUE,否则FALSE.
OPTION='LANGUAGE'返回数据库的 ......
1. flashback table table_test to timestamp to_timestamp('20091103000000','yyyymmddhh24miss');
2.如果報錯ORA-08189: cannot flashback the table because row movement is not enabled
3.alter table table_test enable row movement;
4.OK ......