Pholoso Mams
Pholoso Mams

Reputation: 477

Define %ROWTYPE with fewer columns than the actual table

I declared emp_obj as rowtype of emp_table (which has x number of columns), however I want emp_obj to have x minus y columns (i.e. fewer colunms). How do I go about? My code is:

DECLARE emp emp_table%ROWTYPE; 
BEGIN   
    SELECT name,
           surname
    INTO emp_obj 
    FROM emp_table 
    WHERE emp_ID='89545585' 
    AND ROWNUM=1; 
END;

Upvotes: 1

Views: 70

Answers (1)

Boneist
Boneist

Reputation: 23588

You can specify the fields to store the columns in, e.g.:

DECLARE emp emp_table%ROWTYPE; 
BEGIN   
     SELECT name,
            surname
     INTO   emp_obj.name,
            emp.surname
     FROM   emp_table
     WHERE  emp_ID='89545585'
     and    ROWNUM=1; 
END;

Upvotes: 3

Related Questions