Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6905861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:14:09+00:00 2026-05-27T08:14:09+00:00

I am trying to get the sql query below to work but I am

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:14:09+00:00Added an answer on May 27, 2026 at 8:14 am

    I’ve seen it done this way; but not the select with return value embeded in the condition

    https://forums.oracle.com/forums/thread.jspa?threadID=177035

    DECLARE 
    STANDARD_LINK_ID TABLEB.LINK_ID%type;
    DECLARE W_LINK_COUNT NUMBER (1,0);
    
    BEGIN   
          FOR LINK_ROW IN ( SELECT LINKTEXT, LINKURL, CORPID FROM OLD_DATA)
          LOOP
              SELECT COUNT(URL) INTO W_LINK_COUNT FROM TABLEA WHERE URL = LINK_ROW.LINKURL;
              IF  W_LINK_COUNT = 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;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get my linq query to replicate my t-sql but I
I'm trying to get the code below to work..... The error: ERRORSQLSTATE[42000]: Syntax error
I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET
I've been trying to construct a sql query with ZendFW, but I cant seem
The below is query is similar to what I am trying to achieve but
I'm trying to get a paged query to work properly using LINQ and NHibernate.
I get the error: Column 'Time' cannot be null when using the query below,
I'm trying to get SQL Server to order by a column from a nested
I am trying to get LINQ to SQL to persist changes to an attached
I have been trying for a long time to get SQL Server Express on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.