PL/SQL Bulk collect not enough values error

302 views Asked by At

I have a users-table with values id, uname, pwd, email and more. Now i wanna create a nested table with only some of these values(id, uname, pwd - but no email):

create or replace TYPE type_u as object(type_id number(4,0), type_uname varchar(32), type_pwd varchar(16));

create or replace TYPE u_tbl as table of type_u;

now i want to fill this nested table with the data (id,uname,pwd) of the users table. I tried to use bulk collect for that:

SELECT  u.id,u.uname,u.pwd BULK COLLECT INTO u_tbl FROM user_table u;

But i keep getting the error "not enough values". What is the error in that select statement? Thanks in advance!

Full Code:

create or replace TYPE type_u as object(type_id number(4,0), type_uname varchar(32), type_pwd varchar(16));
        
create or replace TYPE u_tbl as table of type_u;
    
create or replace PROCEDURE RET_STRING_TAB(o_cursor OUT SYS_REFCURSOR) IS
    v_u_tbl u_tbl;
BEGIN
SELECT u.id, u.name, u.pwd BULK COLLECT INTO v_u_tbl FROM user_table u;

-- For each found User do something
FOR i IN 1 .. v_u_tbl.count
LOOP
-- do something
END LOOP;

OPEN o_cursor FOR SELECT * FROM TABLE(v_u_tbl);
END RET_STRING_TAB;
1

There are 1 answers

0
gogocho On

Please try this one

SELECT  type_u(u.id,u.uname,u.pwd) BULK COLLECT INTO u_tbl FROM user_table u;