[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2099
  • Last Modified:

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

      
0
dayiku
Asked:
dayiku
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now