Man Person
Man Person

Reputation: 1130

PLSQL insert query

While reading bear in mind this is my first time working with PLSQL. So I'm trying to do an insert using a for loop like this

CREATE OR REPLACE PROCEDURE PROCEDURE2 AS 
CURSOR emailUsages IS
SELECT classCode, "ID"
FROM NJTELCOM
WHERE classCode = 'mailto';

BEGIN
FOR i IN emailUsages LOOP
  INSERT INTO NJTELCOMUSAGE 
  (classCode, "TELCOMID")
  VALUES 
  (i.classCode, i."ID");
dbms_output.put_line(i.classCode);
END LOOP;
NULL;
END PROCEDURE2;

While the code compiles, it's not working properly, and I don't even get output to the console(though I'm not sure if this is how to do it). I do have a column called id in the table NJTELCOM, calling it "ID" in the code was the only way I could achieve it not outputting an error. Not sure if that's what's causing it. Any help appreciated

Upvotes: 2

Views: 158

Answers (1)

Juan Diego Godoy Robles
Juan Diego Godoy Robles

Reputation: 14945

This could be written as a simply INSERT statement:

INSERT INTO NJTELCOMUSAGE a (a.classCode, a.telcomid)
SELECT b.classCode, b.id
FROM NJTELCOM b
WHERE b.classCode = 'mailto';

Upvotes: 3

Related Questions