How do I use an INSERT INTO with this PL/SQL code block?

11,094

Solution 1

This worked.

INSERT INTO previously_made_table VALUES(c.name, d.customer_id, d.alt_name, '101');

I cut the column names. Hope that helps.

Solution 2

You don't need pl\sql here

insert into previously_made_table
  (name, customer_id, alt_name, customer_code) 
 select c.name, d.customer_id, d.alt_name, '101'
 from   clients c , customers d
 where  d.alt_name LIKE '%' || c.name || '%'
Share:
11,094
duber
Author by

duber

I try to make cool things and hang around smart people.

Updated on June 04, 2022

Comments

  • duber
    duber about 2 years

    I'm fairly new to the procedural language side of PL/SQL, so forgive me if this is basic.

    I'm trying to put values in a table I've previously created outside of this code block. This code is currently getting an error on the sixth line. Any idea why?

    BEGIN
      FOR c IN (SELECT name FROM clients) LOOP
        FOR d IN (SELECT customer_id, alt_name FROM customers) LOOP 
          IF d.alt_name LIKE '%' || c.name || '%'
          THEN
                INSERT INTO previously_made_table(name, customer_id, alt_name, customer_code) VALUES(c.name, d.customer_id, d.alt_name, '101');
                COMMIT;
           END IF;
        END LOOP;
    END LOOP;
    END;
    
  • duber
    duber almost 11 years
    True, but I'd prefer to know how to do it in the PL/SQL format I delivered the question in.
  • haki
    haki almost 11 years
    you probably don't have a column named customer_code in previously_made_table.
  • duber
    duber almost 11 years
    It's there, as mentioned in my comment above.
  • Danilo Piazzalunga
    Danilo Piazzalunga almost 11 years
    Please, always use a column list in your INSERT INTO statements.