desc book_data;
Name Null Type
---------- ---- ------------
BOOK_NAME VARCHAR2(50)
BOOK_PRICE NUMBER
BOOK_SSN VARCHAR2(50)
DECLARE
TYPE book_rec is record(
book_name varchar2(50),
book_price number,
book_ssn varchar2(50)
);
type book_tbl_type is table of book_rec;
book_tbl1 book_tbl_type := book_tbl_type();
BEGIN
SELECT BOOK_NAME, BOOK_PRICE/*,book_ssn,1*/ BULK COLLECT INTO book_tbl1 FROM book_data;
DBMS_OUTPUT.put_line(book_tbl1(1).book_name);
END;
Error report -
ORA-06550: line 11, column 75:
PL/SQL: ORA-00913: too many values
ORA-06550: line 11, column 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
问题:这里我们将两列插入三列收集表然后我们应该得到“ORA-00947:没有足够的值”错误。但是我们得到“ORA-00913:太多的值”。为什么?
DECLARE
TYPE book_rec is record(
book_name varchar2(50),
book_price number,
book_ssn varchar2(50)
);
type book_tbl_type is table of book_rec;
book_tbl1 book_tbl_type := book_tbl_type();
BEGIN
SELECT BOOK_NAME, BOOK_PRICE,book_ssn,1 BULK COLLECT INTO book_tbl1 FROM book_data;
DBMS_OUTPUT.put_line(book_tbl1(1).book_name);
END;
Error report -
ORA-06550: line 11, column 71:
PL/SQL: ORA-00947: not enough values
ORA-06550: line 11, column 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
问题:这里我们将四列插入三列收集表中。然后我们得到“ORA-00913:太多的价值”错误。 但我们得到的是“ORA-00947:没有足够的价值”。为什么?
答案 0 :(得分:0)
ORA-00913太多的值了 原因:SQL语句需要两组值相等的值。当第二组包含的项目多于第一组时,会发生此错误。例如,WHERE或HAVING子句中的子查询可能返回太多列,或者VALUES或SELECT子句可能返回的列数多于INSERT中列出的列数。 操作:检查每个集中的项目数,并更改SQL语句以使它们相等。
在BULK COLLECT的情况下,似乎错误消息是指集合表中的列数,而不是所选列的数量。
为避免类似问题,您可以使用%ROWTYPE,类似:
DECLARE
type book_tbl_type is table of book_data%ROWTYPE;
book_tbl1 book_tbl_type := book_tbl_type();
BEGIN
SELECT b.* BULK COLLECT INTO book_tbl1 FROM book_data b;
END;
/