PLS-00103: Encountered the symbol "|" when expecting one of the following:

CREATE OR REPLACE PROCEDURE PROC_Test  IS

tmpVar NUMBER;
prev_owner      VARCHAR2(50);
current_owner      VARCHAR2(50);
sql_stmt                    VARCHAR2(200) ;


BEGIN

     --RETRIEVE THE VALUE FOR THE CURRENT OWNER
       BEGIN
               SELECT DISTINCT TABLE_OWNER
               INTO current_owner
               FROM USER_SYNONYMS
               WHERE SYNONYM_NAME = 'Test_Tab';
             
       EXCEPTION  
              WHEN OTHERS THEN
                tmpVar := 99;
       END;  
     


       IF current_owner = 'TEST12' THEN
          prev_owner := 'Owner1';
       ELSE
          prev_owner := 'Owner2';
       END IF;  
      
       'INSERT INTO Temp_Table  SELECT Column1, "Literal1","Literal2" FROM' || current_owner || '.TableName1  MINUS   SELECT Column1, ''Literal1'',''Literal2''    FROM  ' || prev_owner  || '.TableName2';

I have the above sql in my procedure, the schema/owner is determined at run time. I am trying to retrieve the value and append it to the table name, but i keep getting this error message

PLS-00103: Encountered the symbol "|" when expecting one of the following:

   := . ( @ % ;

Can somebody tell me what i m doing wrong with the syntax?

Thanks

      
dayikuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you missed the EXECUTE IMMEDIATE?!
   
      EXECUTE IMMEDIATE 'INSERT INTO Temp_Table  SELECT Column1, ''Literal1'',''Literal2'' FROM ' || current_owner || '.TableName1  MINUS   SELECT Column1, ''Literal1'',''Literal2''    FROM  ' || prev_owner  || '.TableName2';

...
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Harish_RajaniCommented:
Are you not suppose to assign the string ( INSERT INTO .....) to a variable ?




Try following

sql_stmt :=  'INSERT INTO Temp_Table  SELECT Column1, "Literal1","Literal2" FROM' || current_owner || '.TableName1  MINUS   SELECT Column1, ''Literal1'',''Literal2''    FROM  ' || prev_owner  || '.TableName2';


Rgds,
HR
0
 
Harish_RajaniCommented:
If you want to execute the insert then :


sql_stmt :=  'INSERT INTO Temp_Table  SELECT Column1, "Literal1","Literal2" FROM' || current_owner || '.TableName1  MINUS   SELECT Column1, ''Literal1'',''Literal2''    FROM  ' || prev_owner  || '.TableName2';


EXECUTE IMMEDIATE sql_stmt;

Rgds,
HR
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.