问题描述
我无法使更新正常工作。选择工作正常。
create or replace type rec_emp is object( EMP_ID number, EMP_F_N varchar2(20), EMP_L_N varchar2(50), DEPT number, emp_salary number); / create or replace type T_EMP as table of rec_emp; / create or replace type rec_emp_upd is object ( EMP_F_N varchar2(20), EMP_L_N varchar2(50), emp_salary NUMBER); / create or replace type T_EMP_UPD as table of REC_EMP_UPD; / DECLARE L_EMP T_EMP; L_EMP_UPD T_EMP_UPD; begin select REC_EMP(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, DEPARTMENT_ID, SALARY) BULK COLLECT INTO L_EMP from employees; forall I in L_EMP.first..L_EMP.last update employees set salary = salary + 1000 where EMPLOYEE_ID = L_EMP(I).EMP_ID RETURNING FIRST_NAME, LAST_NAME, SALARY bulk collect into L_EMP_UPD; For I in 1..L_EMP_UPD.COUNT loop DBMS_OUTPUT.PUT_LINE('New salary of '||L_EMP_UPD(I).FIRST_NAME || L_EMP_UPD(I).LAST_NAME ||' is '||L_EMP_UPD(I).SALARY); END LOOP; end; / Error report - ORA-06550: line 12, column 149: PL/SQL: ORA-00947: not enough values ORA-06550: line 12, column 1: PL/SQL: SQL Statement ignored ORA-06550: line 16, column 53: PLS-00302: component 'FIRST_NAME' must be declared ORA-06550: line 16, column 1: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error.复制
专家解答
返回rec_emp_upd的实例:
这给出了:
returning rec_emp_upd ( first_name, last_name, salary ) bulk collect into l_emp_upd复制
这给出了:
declare l_emp t_emp; l_emp_upd t_emp_upd; begin select rec_emp (employee_id,first_name,last_name,department_id,salary) bulk collect into l_emp from hr.employees; forall i in l_emp.first..l_emp.last update hr.employees set salary = salary + 1000 where employee_id = l_emp (i).emp_id returning rec_emp_upd ( first_name, last_name, salary ) bulk collect into l_emp_upd ; for i in 1..l_emp_upd.count loop dbms_output.put_line ('New salary of ' || l_emp_upd (i).emp_f_n || l_emp_upd (i).emp_l_n || ' is ' || l_emp_upd (i).emp_salary); end loop; end; / New salary of DonaldOConnell is 3600 New salary of DouglasGrant is 3600 New salary of JenniferWhalen is 5400 New salary of MichaelHartstein is 14000 New salary of PatFay is 7000 ...复制
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1359次阅读
2025-03-13 11:40:53
Oracle RAC ASM 磁盘组满了,无法扩容怎么在线处理?
Lucifer三思而后行
835次阅读
2025-03-17 11:33:53
RAC 19C 删除+新增节点
gh
512次阅读
2025-03-14 15:44:18
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
479次阅读
2025-03-13 14:38:19
Oracle 如何修改 db_unique_name?强迫症福音!
Lucifer三思而后行
375次阅读
2025-03-12 21:27:56
Oracle DataGuard高可用性解决方案详解
孙莹
329次阅读
2025-03-26 23:27:33
墨天轮个人数说知识点合集
JiekeXu
272次阅读
2025-04-01 15:56:03
一键装库脚本3分钟极速部署,传统耗时砍掉95%!
IT邦德
262次阅读
2025-03-10 07:58:44
切换Oracle归档路径后,不能正常删除原归档路径上的归档文件
dbaking
256次阅读
2025-03-19 14:41:51
风口浪尖!诚通证券扩容采购Oracle 793万...
Roger的数据库专栏
253次阅读
2025-03-24 09:42:53