Home » SQL & PL/SQL » SQL & PL/SQL » pl sql error (oracle 11g,windows 7)
pl sql error [message #635283] Thu, 26 March 2015 03:13 Go to next message
hcdba
Messages: 34
Registered: March 2015
Member
hi
i am very new to DBA field and i learn pl/sql by my self
here i paste my very basic simple code of program which display which number is max among three of them.

SET SERVEROUTPUT ON


DECLARE

A NUMBER(5);
B NUMBER(5);
C NUMBER(5);
MAX NUMBER(5);


BEGIN

A:= 10;
B:= 20;
C:= 100;


IF A> B THEN

IF A > C THEN

MAX := A ;

ELSE

MAX := C ;

END IF;

ELSE

IF B > C THEN

MAX := B ;

ELSE

MAX := C ;

END IF;

END IF;

DBMS_OUTPUT.PUT_LINE('MAX IS:',MAX);

END;
/

when i run this sql file it give me this error

DBMS_OUTPUT.PUT_LINE('MAX IS:',MAX);
*
ERROR at line 42:
ORA-06550: line 42, column 35:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
(

thanx in advance
Re: pl sql error [message #635285 is a reply to message #635283] Thu, 26 March 2015 03:15 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Invalid usage of DBMS_OUTPUT.PUT_LINE. It accepts only one parameter, which means that you'll have to concatenate 'MAX IS:' with MAX.
Re: pl sql error [message #635286 is a reply to message #635285] Thu, 26 March 2015 03:21 Go to previous messageGo to next message
hcdba
Messages: 34
Registered: March 2015
Member
sir t tried that too


SQL> @C:\USERS\DBA\PRO5.SQL
DBMS_OUTPUT.PUT_LINE('MAX IS:'|| MAX);
*
ERROR at line 42:
ORA-06550: line 42, column 37:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
(

but it gives same error.

i also tried
DBMS_OUTPUT.PUT_LINE(MAX);
give same eroor.
Re: pl sql error [message #635287 is a reply to message #635286] Thu, 26 March 2015 03:24 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Ah! MAX is a reserved word, you shouldn't use it as a name for your variables. Modify it to, say, L_MAX.
Re: pl sql error [message #635288 is a reply to message #635283] Thu, 26 March 2015 03:26 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
MAX is being inerpreted as a function, not as a variable name.

--update: as LF just said....

[Updated on: Thu, 26 March 2015 03:27]

Report message to a moderator

Re: pl sql error [message #635289 is a reply to message #635288] Thu, 26 March 2015 03:57 Go to previous messageGo to next message
hcdba
Messages: 34
Registered: March 2015
Member
pk sir done thanx a lot
Re: pl sql error [message #635290 is a reply to message #635289] Thu, 26 March 2015 05:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Before your next question, Please How to use [code] tags and make your code easier to read.

Re: pl sql error [message #635291 is a reply to message #635290] Thu, 26 March 2015 05:29 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
This could just be written as:
DECLARE

  A NUMBER(5);
  B NUMBER(5);
  C NUMBER(5);
  l_max NUMBER(5);

 BEGIN

  A:= 10;
  B:= 10;
  C:= 100;

  l_max := GREATEST(a,b,c);

  DBMS_OUTPUT.PUT_LINE('l_max IS: '||l_max);

END;
Re: pl sql error [message #635293 is a reply to message #635291] Thu, 26 March 2015 07:35 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Not exactly.

SY.
Re: pl sql error [message #635301 is a reply to message #635293] Thu, 26 March 2015 08:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Just because OP's code is wrong, I think. Wink

Re: pl sql error [message #635317 is a reply to message #635301] Thu, 26 March 2015 10:48 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
OP's code ignores (to some extent) NULLS.

SY.
Previous Topic: Using TYPE within an SQL IN statement
Next Topic: insert statement w/o having unique constraint error
Goto Forum:
  


Current Time: Thu Apr 18 22:01:34 CDT 2024