sql - 删除嵌套表中的记录 (plsql)
问题描述
我想删除记录类型中的列(emp_sal)有 5000+ 的元素,但这给了我一个错误。我不知道我是否将 .DELETE 方法放在正确的区域。代码:
DECLARE
TYPE rec IS RECORD (
emp_id HR.EMPLOYEES.EMPLOYEE_ID%TYPE,
emp_fname HR.EMPLOYEES.FIRST_NAME%TYPE,
emp_lname HR.EMPLOYEES.LAST_NAME%TYPE,
emp_job HR.EMPLOYEES.JOB_ID%TYPE,
emp_sal HR.EMPLOYEES.SALARY%TYPE );
TYPE rec_table IS TABLE OF rec;
rec_list rec_table := rec_table();
BEGIN
SELECT HR.EMPLOYEES.EMPLOYEE_ID,
HR.EMPLOYEES.FIRST_NAME,
HR.EMPLOYEES.LAST_NAME,
HR.EMPLOYEES.JOB_ID,
HR.EMPLOYEES.SALARY
BULK COLLECT INTO rec_list
FROM HR.EMPLOYEES;
FOR i IN rec_list.FIRST..rec_list.LAST LOOP
IF (rec_list(i).emp_sal > 5000) THEN
rec_list(i).DELETE();
END IF;
DBMS_OUTPUT.PUT_LINE('element: '||i||' '||
'emp id: '||rec_list(i).emp_id||
' full name: '||rec_list(i).emp_fname||
' '||rec_list(i).emp_lname||
' job: '||rec_list(i).emp_job||
' salary: '||rec_list(i).emp_sal);
END LOOP;
END;
输出:
ORA-06550: line 28, column 20: PLS-00302: component 'DELETE' must be declared
谢谢!
解决方案
如果你想从集合中删除一个元素,那么你使用错了
DELETE with no parameters removes all elements from a collection, setting COUNT to 0.
DELETE(n) removes the nth element from an associative array with a numeric key or a nested table. If the associative array has a string key, the element corresponding to the key value is deleted. If n is null, DELETE(n) does nothing.
DELETE(m,n) removes all elements in the range m..n from an associative array or nested table. If m is larger than n or if m or n is NULL, DELETE(m,n) does nothing.
所以在你的例子中正确的是
IF (rec_list(i).emp_sal > 5000) THEN
rec_list.DELETE(i);
END IF;
推荐阅读
- python - 使用adjustText避免标签重叠与Python王子对应分析
- python - 敌人.rect 不更新
- ios - 服务管理器未填充 ViewModel
- firebase - Firebase 通知中的权限
- node.js - 当我尝试使用 --depth 21 更新包时,NPM 崩溃
- indexing - h2 数据库支持前缀索引吗?
- python - 使用 grid_forget() - Python tkinter 后帧大小不再显示
- ios - How to apply MPSImageGuidedFilter in Swift
- machine-learning - 深度学习中的准确性和损失问题
- c - 在 C 中使用 void 指针存储整数的最佳方法是什么?