I am trying to get the sql query below to work but I am getting an error, my problem is as follows:
I need to loop through a results set from a select statement (this part is fine). Inside the loop for each row I need to check if the URL exists in tableA. If it does then insert a mapping into tableB, otherwise insert a new row into tableC.
This is what I have but when I try to execute I get an error on the line with the IF saying ORA-06550: line 8, column 15:PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:( - + case mod new no.....
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;