Home » SQL & PL/SQL » SQL & PL/SQL » Procedure creation error - PLS-00103 (Oracle 11.2.0.3, Linux x86 64)
Procedure creation error - PLS-00103 [message #637442] Mon, 18 May 2015 01:32 Go to next message
hitesh.bhatt
Messages: 84
Registered: February 2014
Location: INDIA
Member
Hello,

I am new to pl/sql writing, so can you please help me with following, as I have created following procedure -

CREATE OR REPLACE procedure REFRESH
cursor c1 is
select table_name from DBA_TABLES WHERE SUBSTR(TABLE_NAME, -2) in('_A');
BEGIN
for r1 in c1 loop
      MERGE INTO TEST P
              ON (P.TABLE_NAME = r1.TABLE_NAME)
      WHEN MATCHED
      THEN
	UPDATE set P.UPDATE = SYSTIMESTAMP;
      WHEN NOT MATCHED
      THEN
         INSERT     (P.UPD_TYPE,
                     P.UPDATE,
                     P.DB_NAME,
                     P.TABLE_NAME)
             VALUES (1,
                     SYSTIMESTAMP,
                     'DB01',
                     r1.TABLE_NAME);
   END loop;
commit;
END;
/


But it shows following error -


LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1      PLS-00103: Encountered the symbol "CURSOR" when expecting one of
         the following:
         ( ; is with authid as cluster compress order using compiled
         wrapped external deterministic parallel_enable pipelined
         result_cache





Can you please help me on this?

Also I will have to add other columns as well in UPDATE, so how to add that as well?

Many thanks in advance.
Re: Procedure creation error - PLS-00103 [message #637443 is a reply to message #637442] Mon, 18 May 2015 01:34 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Missing IS (or AS) at the end of the first line. There might be other errors later (but I'm sure you'll ask for assistance if you can't fix it).
Re: Procedure creation error - PLS-00103 [message #637444 is a reply to message #637443] Mon, 18 May 2015 01:37 Go to previous messageGo to next message
hitesh.bhatt
Messages: 84
Registered: February 2014
Location: INDIA
Member
Many Thanks for quick reply, yes now it gives following error -

Errors for PROCEDURE REFRESH:

LINE/COL ERROR
-------- -----------------------------------------------------------------
6/7      PL/SQL: SQL Statement ignored
7/15     PL/SQL: ORA-02012: missing USING keyword
11/7     PLS-00103: Encountered the symbol "WHEN" when expecting one of
         the following:
         ( begin case declare end exit for goto if loop mod null
         pragma raise return select update while with <an identifier>
         <a double-quoted delimited-identifier> <a bind variable> <<
         continue close current delete fetch lock insert open rollback
         savepoint set sql execute commit forall merge pipe purge
         The symbol "case" was substituted for "WHEN" to continue.


LINE/COL ERROR
-------- -----------------------------------------------------------------
13/21    PLS-00103: Encountered the symbol "(" when expecting one of the
         following:
         into <a SQL statement>

14/24    PLS-00103: Encountered the symbol "UPDATE" when expecting one of
         the following:
         <an identifier> <a double-quoted delimited-identifier>
         current delete exists prior
         The symbol "<an identifier> was inserted before "UPDATE" to
         continue.


LINE/COL ERROR
-------- -----------------------------------------------------------------
17/14    PLS-00103: Encountered the symbol "VALUES" when expecting one of
         the following:
         , * & - + / at mod remainder rem <an identifier>
         <a double-quoted delimited-identifier> <an exponent (**)> as
         from into || multiset bulk year day
         The symbol ", was inserted before "VALUES" to continue.

20/36    PLS-00103: Encountered the symbol ";" when expecting one of the
         following:
         , * & - + / at mod remainder rem <an identifier>
         <a double-quoted delimited-identifier> <an exponent (**)> as

LINE/COL ERROR
-------- -----------------------------------------------------------------
         from into || multiset bulk year day
Re: Procedure creation error - PLS-00103 [message #637445 is a reply to message #637444] Mon, 18 May 2015 01:41 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Well, I didn't mean that you should just copy/paste errors you got. I was hoping that you'll do some effort in trying to fix them. Shortly: wrong syntax. Check the documentation once again.
Re: Procedure creation error - PLS-00103 [message #637446 is a reply to message #637442] Mon, 18 May 2015 01:41 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
There are multiple errors:

1. As LF pointed out, IS or AS keyword is missing.
2. USING clause is missing in the MERGE statement.
3. You have terminated the update clause while insert clause follows.

Isn't that while procedure a single MERGE statement?

MERGE INTO TEST P 
USING
(SELECT table_name FROM DBA_TABLES WHERE SUBSTR(TABLE_NAME, -2) = '_A'
) r1 
ON (P.TABLE_NAME = r1.TABLE_NAME)
WHEN MATCHED THEN
  UPDATE SET P.UPDATE = SYSTIMESTAMP
WHEN NOT MATCHED THEN
  INSERT
    (
      P.UPD_TYPE,
      P.UPDATE,
      P.DB_NAME,
      P.TABLE_NAME
    )
    VALUES
    (
      1,
      SYSTIMESTAMP,
      'DB01',
      r1.TABLE_NAME
    );


I don't know what you are trying to achieve, so you need to explain in words the business logic.
Re: Procedure creation error - PLS-00103 [message #637447 is a reply to message #637446] Mon, 18 May 2015 02:04 Go to previous messageGo to next message
hitesh.bhatt
Messages: 84
Registered: February 2014
Location: INDIA
Member
Many thanks for reply, yes I want to write procedure for following requirements -

We need to automatically update this table (TEST) whenever there is update in the "_A" tables
Re: Procedure creation error - PLS-00103 [message #637453 is a reply to message #637447] Mon, 18 May 2015 03:00 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
hitesh.bhatt wrote on Mon, 18 May 2015 12:34
We need to automatically update this table (TEST) whenever there is update in the "_A" tables


A procedure doesn't automatically gets executed on some action. You need a triggering event.
Previous Topic: vpd condition with joins in DataWarehouse
Next Topic: Asp.Net Application hangs until oracle package is recompiled
Goto Forum:
  


Current Time: Thu Apr 18 23:51:53 CDT 2024