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 || '%'
Comments
-
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 almost 11 yearsTrue, but I'd prefer to know how to do it in the PL/SQL format I delivered the question in.
-
haki almost 11 yearsyou probably don't have a column named
customer_code
inpreviously_made_table
. -
duber almost 11 yearsIt's there, as mentioned in my comment above.
-
Danilo Piazzalunga almost 11 yearsPlease, always use a column list in your INSERT INTO statements.