Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2006
    Posts
    26

    Unanswered: insert into table from Record

    I have a record type say as

    Code:
    table_record        table_name%rowtype

    now there are values which i need to insert into table from record. there are like 30 values. now one approach is to write those value xplicitly like this

    Code:
    insert into table_name values (table_record.val1, table_record.val2, table_record.val3, table_record.val4, table_record.val5, ...)
    I am looking for some syntax which insert all values from record into the table. somewhat like this

    Code:
    insert into table_name values (table_record.*)
    is there something like this i can do in PLSQL?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,296
    The basic answer is YES. However, you might be a little confused.
    %rowtype is to declare a record of the same types as defined in a table.
    you would still need to pass in the values for each type in the table.

    If you just want to insert records from one table to another. you would:
    PHP Code:
    insert into tableA (
      
    col1col2)
    select col1col2 from tableB
    if you want to use the %rowtype record then you would need to pass the values from tableB into the record first (with a loop or something).

    PHP Code:
    declare
      
    myTableA tablea%rowtype;
      
    cursor myCursor is select ownertable_name from dba_tables;
    begin
      
    for myTableA in myCursor loop
          insert into tableA values myTableA
    ;
      
    end loop;
    end;

    - The_Duck
    you can lead someone to something but they will never learn anything ...

  3. #3
    Join Date
    Jul 2006
    Posts
    26
    well the record has already been filled up with the business logic written above the pl/sql code (i didn't paste that here). I am sure there are values in the record but i still didn't get how to insert into the table.

    I want to insert values from *record* into the table.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by hYph3n
    I want to insert values from *record* into the table.
    Isn't the the_duck's example:
    Code:
    insert into tableA values myTableA;
    exactly what you need?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,296
    What Shammat said. I gave you a perfect example (and verified that it works).
    - The_Duck
    you can lead someone to something but they will never learn anything ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •