Home » SQL & PL/SQL » SQL & PL/SQL » Compilation error
Compilation error [message #309430] Thu, 27 March 2008 07:20 Go to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
Hi,

While compiling the follwing code i am getting the compilation error

CREATE OR REPLACE PROCEDURE SAT_SUM IS 
SUM NUMBER(5);
BEGIN
SUM := 3;
DBMS_OUTPUT.PUT_LINE('Hi'||SUM);
END;


but if i run the code by changing as below am getting the result(Hi)
CREATE OR REPLACE PROCEDURE SAT_SUM IS 
SUM NUMBER(5);
BEGIN
SUM := 3;
DBMS_OUTPUT.PUT_LINE('Hi');
END;


is there anything needs to be added?
kindly help me...

Regards,
Sathish...
Re: Compilation error [message #309432 is a reply to message #309430] Thu, 27 March 2008 07:26 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
What is "The compilation error"?

Don't use reserved words as variable names.
Re: Compilation error [message #309435 is a reply to message #309432] Thu, 27 March 2008 07:32 Go to previous messageGo to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
Hi Frank,

Thanks for the reply.
The error occured because of reserved keyword. Now i am not getting the error. But if run the below query also no error is produced.

CREATE OR REPLACE PROCEDURE SAT_SUM IS
SUM NUMBER(5);
BEGIN
SUM := 3;
DBMS_OUTPUT.PUT_LINE('Hi');
END;

OUTPUT
Hi
PL/SQL procedure successfully completed

Regards,
Sathish...
Re: Compilation error [message #309438 is a reply to message #309435] Thu, 27 March 2008 08:03 Go to previous messageGo to next message
Michel Cadot
Messages: 64120
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
What is asked is to copy and paste your session and to format it as per OraFAQ Forum Guide, "How to format your post?" section.
Read it and follow it.

Like this:
SQL> CREATE OR REPLACE PROCEDURE SAT_SUM IS 
  2  SUM NUMBER(5);
  3  BEGIN
  4  SUM := 3;
  5  DBMS_OUTPUT.PUT_LINE('Hi'||SUM);
  6  END;
  7  /

Warning: Procedure created with compilation errors.

SQL> sho err
Errors for PROCEDURE SAT_SUM:

LINE/COL
---------------------------------------------------------------------------
ERROR
---------------------------------------------------------------------------
5/31
PLS-00103: Encountered the symbol ")" when expecting one of the following:

   (

Action: Don't use reserved words.

Regards
Michel
Re: Compilation error [message #309441 is a reply to message #309438] Thu, 27 March 2008 08:20 Go to previous messageGo to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
i am asking do you the reason why the code is giving output(Hi) eventhough the code has a reserved keyword.??????

CREATE OR REPLACE PROCEDURE SAT_SUM IS 
SUM NUMBER(5);
BEGIN
SUM := 3;
DBMS_OUTPUT.PUT_LINE('Hi');
END;

BEGIN
sat_sum;
END;

OUTPUT
Hi
PL/SQL procedure successfully completed


PS:code is executed in TOAD.

Regards,
Sathish...
Re: Compilation error [message #309445 is a reply to message #309441] Thu, 27 March 2008 08:29 Go to previous messageGo to next message
Ronald Beck
Messages: 121
Registered: February 2003
Senior Member

See this...

SQL> CREATE OR REPLACE PROCEDURE SAT_SUM IS 
  2  SUM NUMBER(5);
  3  BEGIN
  4  SUM := 3;
  5  DBMS_OUTPUT.PUT_LINE('Hi'||SUM);
  6  END;
  7  /


Line 5 is using a reserved word! BAD IDEA!

See this...

SQL> CREATE OR REPLACE PROCEDURE SAT_SUM IS 
  2  SUM NUMBER(5);
  3  BEGIN
  4  SUM := 3;
  5  DBMS_OUTPUT.PUT_LINE('Hi');
  6  END;
  7  /


No reserved word on line 5! Works like it's supposed to.

Now, try this...

SQL> CREATE OR REPLACE PROCEDURE SAT_SUM IS 
  2  MY_SUM NUMBER(5);
  3  BEGIN
  4  MY_SUM := 3;
  5  DBMS_OUTPUT.PUT_LINE('Hi'||MY_SUM);
  6  END;
  7  /


...and see what happens to your compile error.
Re: Compilation error [message #309451 is a reply to message #309430] Thu, 27 March 2008 08:42 Go to previous messageGo to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
please try to understand my question.

Once again i will explain.

How the below code is executing without any errors eventhough a reserved keyword is used as a variable?

SQL> CREATE OR REPLACE PROCEDURE SAT_SUM IS 
  2  SUM NUMBER(5);
  3  BEGIN
  4  SUM := 3;
  5  DBMS_OUTPUT.PUT_LINE('Hi');
  6  END;
  7  /


PS:from the first reply of this thread itself i understood keywords will give errors.There is nothing use still you are saying 'BAD IDEA!'

Regards,
Sathish...
Re: Compilation error [message #309453 is a reply to message #309451] Thu, 27 March 2008 08:45 Go to previous messageGo to next message
Michel Cadot
Messages: 64120
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
There is no specific reason.
Using reserved word leads to UNPREDICTIBLE result.

Regards
Michel
Re: Compilation error [message #309454 is a reply to message #309430] Thu, 27 March 2008 08:45 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
> i am asking do you the reason why the code is giving output

Maybe you should ask Oracle, how they implemented the PL/SQL parser.

Just a guess (as I do not know its code): as SUM function is not L-Value, it is not expected (and so recognized) in that place.
Re: Compilation error [message #309457 is a reply to message #309430] Thu, 27 March 2008 09:06 Go to previous messageGo to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
No it(Hi) is not unpredictable result.

It is the exact result.

Because instead of Hi,whatever i give in the 5 th line of the below coding segment,

SQL> CREATE OR REPLACE PROCEDURE SAT_SUM IS 
  2  SUM NUMBER(5);
  3  BEGIN
  4  SUM := 3;
  5  DBMS_OUTPUT.PUT_LINE('Hi');
  6  END;
  7  /


the output is also according to the input which i have given.

If you know the answer then post it. Else just finish this thread.

Regards,
Re: Compilation error [message #309458 is a reply to message #309430] Thu, 27 March 2008 09:24 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
What is wrong with my previous deduction?

It may behave differently in different versions (by the way you did not post yours), as the implementation of PL/SQL parser may (and definitely will) change. I would call it unpredictable too.

I am afraid you will not get more precise answer until Oracle issues its source code or you will get involved in its implementation. For both cases, you should start studying Compiler theory.

[Updated on: Thu, 27 March 2008 09:29]

Report message to a moderator

Re: Compilation error [message #309460 is a reply to message #309430] Thu, 27 March 2008 09:36 Go to previous messageGo to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
can you please little more precisely tell me what have to study in compiler thoery.the link you have given is having many sub topics.and also i have an overal knowledge about that.And also you need not worry about me.

Regards,
Re: Compilation error [message #309461 is a reply to message #309460] Thu, 27 March 2008 09:43 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Because only when you have understood everything there is in compiler theory (which will take at least about a decade),

AND all the developers at Oracle are your drinking buddies and tell you every line of code they wrote each day,

THEN you might be able to predict when using a reserved keyword as variable will lead to a problem and when not, and it will no longer be unpredictable to you.

Me, I just believe the Oracle developers that is unpredictable and don't use them as variable names. Wink
Re: Compilation error [message #309463 is a reply to message #309460] Thu, 27 March 2008 09:46 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
sathish.mellow wrote on Thu, 27 March 2008 15:36
can you please little more precisely tell me what have to study in compiler thoery.the link you have given is having many sub topics.and also i have an overal knowledge about that.And also you need not worry about me.

Regards,

Either you are interested in the theory of parsers, then you read everything you can about it, or you just want your code to function.
If it's the latter, then STOP using reserved words. Why? Just because we and Oracle and the whole world say so.
Re: Compilation error [message #309464 is a reply to message #309430] Thu, 27 March 2008 09:59 Go to previous messageGo to next message
sathish.mellow
Messages: 32
Registered: December 2007
Location: Chennai
Member
please understand me i learnt to not use reserved keywords.i think all of you cant understand
Embarassed Embarassed Embarassed Embarassed
Embarassed Embarassed Embarassed Embarassed
Embarassed Embarassed Embarassed Embarassed

and i didnt mentioned anywhere in this thread as oracle developers are my drinking buddies.
and i dont believe in oracle developers will tell thier code.i think you are the only person so.

so dont use the things which are not needed and which are unsaid.
Re: Compilation error [message #309465 is a reply to message #309430] Thu, 27 March 2008 10:02 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
If you are really interested in this area, you shall study at the university specialized to computer theory. This area is very broad, from Formal languages to Compilers and will surely take some semesters to familiarize yourself with it.
Re: Compilation error [message #309466 is a reply to message #309464] Thu, 27 March 2008 10:15 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
sathish.mellow wrote on Thu, 27 March 2008 15:59

> so dont use the things which are not needed and which are unsaid.

Maybe I understood you bad, but I interpreted your question as you want to know WHY the code does not throw error. Then the answer is the same: you have to understand, how Oracle compiles the code and interprets it. As the Oracle source code is not available (as far as I know), you cannot get it without taking it from some Oracle programmer or get hired by Oracle. And before its analysis you really have to understand, how the processing is done. This is nearly impossible without knowing at least basics of language/compiler theory.

By the way, did you understand, what my first post pointed at? And after reading the article about Value in computer science? Reading it twice? Reading about Programming languages and other linked items?
Re: Compilation error [message #309521 is a reply to message #309430] Thu, 27 March 2008 14:52 Go to previous messageGo to next message
joicejohn
Messages: 327
Registered: March 2008
Location: India
Senior Member
Hi Sathish,

First thing as you already know is SUM is a reserved keyword. You have to understand the syntax of SUM built-in function. This keyword can be used with an SQL statement only.

The syntax is
SUM(variable_name or expression)

So naturally whenever you give a reserved keyword, Oracle compiler/parser will check for the syntax errors first. Since in your program wherever the parser/compiler hits the reserved keyword like SUM, the next thing a parser/compiler looks is for a proper syntax which in this case is '('. If it doesn't find '(' it returns an error.

If you want to use a reserved keyword make it unreserved. Below is your code with slight changes done:

CREATE OR REPLACE PROCEDURE SAT_SUM IS
"SUM" NUMBER(5);
BEGIN
"SUM" := 3;
DBMS_OUTPUT.PUT_LINE('Hi'||"SUM");
END;

Hope this helps you. Please feel free to correct me if I am wrong anywhere.

Thanks,
Joice
Re: Compilation error [message #309522 is a reply to message #309521] Thu, 27 March 2008 14:55 Go to previous message
Michel Cadot
Messages: 64120
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It is a VERY bad idea to give tip to workaround good practice, above all in a newbie forum.

There is ONLY ONE thing to do: do not use reserved word. Full stop.

Regards
Michel
Previous Topic: Data restriction at the column level
Next Topic: getting error in Procedure
Goto Forum:
  


Current Time: Tue Dec 06 15:58:39 CST 2016

Total time taken to generate the page: 0.12103 seconds