I am trying to get the sql query below to work, but I get an error message, my problem is this:
I need to scroll through the result set from the select statement (this part is fine). Inside the loop for each row, I need to check if the URL exists in table A. If so, then insert the mapping into tableB, otherwise insert a new row in tableC.
This is what I have, but when I try to execute, I get an error message in a line with IF saying that ORA-06550: line 8, column 15: PLS-00103: met the character “SELECT”, expecting that one of the following :( - + case mod no new .....
DECLARE STANDARD_LINK_ID TABLEB.LINK_ID%type; BEGIN FOR LINK_ROW IN ( SELECT LINKTEXT, LINKURL, CORPID FROM OLD_DATA) LOOP IF (SELECT COUNT(URL) FROM TABLEA WHERE URL = LINK_ROW.LINKURL) = 1 THEN SELECT LINKID INTO STANDARD_LINK_ID FROM TABLEA WHERE URL = LINK_ROW.URL; INSERT INTO TABLEB(LINK_ID, CORP_ID) VALUES (STANDARD_LINK_ID, LINK_ROW.CORPID); ELSE INSERT INTO TABLEB(LINK_ID, LINK_NAME, URL, CORP_ID) VALUES (SEQ_LINK.NEXTVAL, LINK_ROW.LINKTEXT, LINK_ROW.LINKURL, LINK_ROW.CORP_ID); END IF; END LOOP; COMMIT; END;
source share