Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to fill custom record type with default values?

Blue BirdJul 4 2018 — edited Jul 5 2018

Hello,

I created my custom record type (t_Emp) where for example last two fields contain default values. If I insert values into record fields separately predefined default values are inserted ok. But if I want to insert same values directly into the record (r_Emp) I get error. Do you have to list all fields (as in case1) if you have some predefined values for some fields, or I use some wrong syntax? If you have many fields with some predefined values, code is then that way much longer.

Declare

  Type t_Emp Is Record(

    Nr Number,

    Name VarChar2(20),

    Job VarChar2(15) Not Null := 'Unknown',

    Sal Number Default 111

  );

 

  r_Emp t_Emp;

Begin

  -- This working

  Select 1000, 'Doe'

  Into

    r_Emp.Nr,

    r_Emp.Name

  From Dual;

  DBMS_OutPut.Put_Line('r_Emp: ' || r_Emp.Nr || ', ' || r_Emp.Name || ', ' || r_Emp.Job  || ', ' || r_Emp.Sal);

  -- Return Ok: r_Emp: 1000, Doe, Unknown, 111

 

  -- Why this doesn't working?

  Select 1000, 'Doe', 'Sales'

  Into r_Emp

  From Dual;

  DBMS_OutPut.Put_Line('r_Emp: ' || r_Emp.Nr || ', ' || r_Emp.Name || ', ' || r_Emp.Job  || ', ' || r_Emp.Sal);

  -- Return Error: PL/SQL: ORA-00913: too many values

 

End;

/

BB

This post has been answered by odie_63 on Jul 4 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 2 2018
Added on Jul 4 2018
8 comments
1,227 views