bulk of the 用法_oracle学习之bulk collect用法

--在select into语句中使用bulk collect

DECLARE

TYPE SalList IS TABLE OF emp.sal%TYPE;

sals SalList;

BEGIN

-- Limit the number of rows to 100.

SELECT sal BULK COLLECT INTO sals FROM emp

WHERE ROWNUM <= 100;

-- Retrieve 10% (approximately) of the rows in the table.

SELECT sal BULK COLLECT INTO sals FROM emp SAMPLE 10;

END;

/

--在fetch into中使用bulk collect

DECLARE

TYPE DeptRecTab IS TABLE OF dept%ROWTYPE;

dept_recs DeptRecTab;

CURSOR c1 IS

SELECT deptno, dname, loc FROM dept WHERE deptno > 10;

BEGIN

OPEN c1;

FETCH c1 BULK COLLECT INTO dept_recs;

END;

/

--在returning into中使用bulk collect

CREATE TABLE emp2 AS SELECT * FROM employees;

DECLARE

TYPE NumList IS TABLE OF employees.employee_id%TYPE;

enums NumList;

TYPE NameList IS TABLE OF employees.last_name%TYPE;

names NameList;

BEGIN

DELETE FROM emp2 WHERE department_id = 30

RETURNING employee_id, last_name BULK COLLECT INTO enums, names;

dbms_output.put_line('Deleted ' || SQL%ROWCOUNT || ' rows:');

FOR i IN enums.FIRST .. enums.LAST

LOOP

dbms_output.put_line('Employee #' || enums(i) || ': ' || names(i));

END LOOP;

END;

/

DROP TABLE emp2;

--在select into语句中使用bulk collect

DECLARE

TYPE SalList IS TABLE OF emp.sal%TYPE;

sals SalList;

BEGIN

-- Limit the number of rows to 100.

SELECT sal BULK COLLECT INTO sals FROM emp

WHERE ROWNUM <= 100;

-- Retrieve 10% (approximately) of the rows in the table.

SELECT sal BULK COLLECT INTO sals FROM emp SAMPLE 10;

END;

/

--在fetch into中使用bulk collect

DECLARE

TYPE DeptRecTab IS TABLE OF dept%ROWTYPE;

dept_recs DeptRecTab;

CURSOR c1 IS

SELECT deptno, dname, loc FROM dept WHERE deptno > 10;

BEGIN

OPEN c1;

FETCH c1 BULK COLLECT INTO dept_recs;

END;

/

--在returning into中使用bulk collect

CREATE TABLE emp2 AS SELECT * FROM employees;

DECLARE

TYPE NumList IS TABLE OF employees.employee_id%TYPE;

enums NumList;

TYPE NameList IS TABLE OF employees.last_name%TYPE;

names NameList;

BEGIN

DELETE FROM emp2 WHERE department_id = 30

RETURNING employee_id, last_name BULK COLLECT INTO enums, names;

dbms_output.put_line('Deleted ' || SQL%ROWCOUNT || ' rows:');

FOR i IN enums.FIRST .. enums.LAST

LOOP

dbms_output.put_line('Employee #' || enums(i) || ': ' || names(i));

END LOOP;

END;

/

DROP TABLE emp2;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值