Home » SQL & PL/SQL » SQL & PL/SQL » Greatest Function (oracle 9i)
Greatest Function [message #389008] Fri, 27 February 2009 00:07 Go to next message
ramesh55.sse
Messages: 262
Registered: December 2008
Location: Hyderabad
Senior Member
select GRATEST('1','22','23') as "text" FROM Dual;
o/p 23
Why it's returning 23.
Re: Greatest Function [message #389012 is a reply to message #389008] Fri, 27 February 2009 00:12 Go to previous messageGo to next message
BlackSwan
Messages: 25050
Registered: January 2009
Location: SoCal
Senior Member
huh?

You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
So we can help you & please be consistent & correct in your postings.

Post DDL for tables.
Post DML for test data.

Post expected/desired results.
Re: Greatest Function [message #389018 is a reply to message #389008] Fri, 27 February 2009 00:25 Go to previous messageGo to next message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> select GRATEST('1','22','23') as "text" FROM Dual;
select GRATEST('1','22','23') as "text" FROM Dual
       *
ERROR at line 1:
ORA-00904: "GRATEST": invalid identifier

It is NOT returning 23.

Quote:
adj. great·er, great·est

1. Very large in size.
2. Larger in size than others of the same kind.
3. Large in quantity or number: A great throng awaited us. See Synonyms at large.
4. Extensive in time or distance: a great delay.
5. Remarkable or outstanding in magnitude, degree, or extent: a great crisis.
6. Of outstanding significance or importance: a great work of art.
7. Chief or principal: the great house on the estate.
8. Superior in quality or character; noble: "For he was great, ere fortune made him so" (John Dryden).
9. Powerful; influential: one of the great nations of the West.
10. Eminent; distinguished: a great leader.
11. Grand; aristocratic.
12. Informal Enthusiastic: a great lover of music.
13. Informal Very skillful: great at algebra.
14. Informal Very good; first-rate: We had a great time at the dance.
15. Being one generation removed from the relative specified. Often used in combination: a great-granddaughter.
16. Archaic Pregnant.


Regards
Michel
Re: Greatest Function [message #389020 is a reply to message #389008] Fri, 27 February 2009 00:33 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
ramesh55.sse wrote on Fri, 27 February 2009 07:07
select GRATEST('1','22','23') as "text" FROM Dual;
o/p 23
Why it's returning 23.


What did you expect it to return?

Additionally, an example for your amusement:
SQL> select greatest('100', '23') from dual;

GR
--
23

SQL>

Why is it returning 23 as well?
Re: Greatest Function [message #389022 is a reply to message #389008] Fri, 27 February 2009 00:36 Go to previous messageGo to next message
BlackSwan
Messages: 25050
Registered: January 2009
Location: SoCal
Senior Member
'2' > '1'
strings are NOT numbers!
Re: Greatest Function [message #389024 is a reply to message #389022] Fri, 27 February 2009 00:49 Go to previous messageGo to next message
MarcS
Messages: 312
Registered: March 2007
Location: Antwerp
Senior Member
BlackSwan wrote on Fri, 27 February 2009 07:36
'2' > '1'
strings are NOT numbers!


Well answered Wink

But I guess Littlefoot was hoping the OP would think about the question.

Furthermore: is it really necessary in this case to have DDL & DML to help OP?
Re: Greatest Function [message #389025 is a reply to message #389008] Fri, 27 February 2009 00:54 Go to previous messageGo to next message
BlackSwan
Messages: 25050
Registered: January 2009
Location: SoCal
Senior Member
>Furthermore: is it really necessary in this case to have DDL & DML to help OP?

It is like giving chicken soup to a dead man,
it can not hurt & just may help.

Re: Greatest Function [message #389029 is a reply to message #389024] Fri, 27 February 2009 01:12 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
MarcS
But I guess Littlefoot was hoping the OP would think about the question.

Yes, but my efforts weren't recognized ./fa/1637/0/
Re: Greatest Function [message #389043 is a reply to message #389025] Fri, 27 February 2009 01:58 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
BlackSwan wrote on Fri, 27 February 2009 07:54
>Furthermore: is it really necessary in this case to have DDL & DML to help OP?

It is like giving chicken soup to a dead man,
it can not hurt & just may help.



No, it most certainly will not help and it's a waste of a perfectly good soup!
Better choose your analogies a bit more careful Razz
Re: Greatest Function [message #389044 is a reply to message #389043] Fri, 27 February 2009 02:02 Go to previous messageGo to next message
MarcS
Messages: 312
Registered: March 2007
Location: Antwerp
Senior Member
Frank wrote on Fri, 27 February 2009 08:58
BlackSwan wrote on Fri, 27 February 2009 07:54
>Furthermore: is it really necessary in this case to have DDL & DML to help OP?

It is like giving chicken soup to a dead man,
it can not hurt & just may help.



No, it most certainly will not help and it's a waste of a perfectly good soup!
Better choose your analogies a bit more careful Razz


  SELECT GREATEST( 'CHICKEN SOUP' ,
                   'CULLEN SKINK' ,
                   'ONION SOUP' , 
                   'TOMATE SOUP' )
  FROM DUAL ;


Laughing
Re: Greatest Function [message #389062 is a reply to message #389044] Fri, 27 February 2009 02:50 Go to previous messageGo to next message
pablolee
Messages: 2836
Registered: May 2007
Location: Scotland
Senior Member
Got to be Cullen Skink every time.
Re: Greatest Function [message #389288 is a reply to message #389020] Sat, 28 February 2009 01:58 Go to previous message
ajiks143
Messages: 1
Registered: February 2009
Junior Member
select GREATEST('100','23') as "text" FROM Dual;

checks for the ascii values and then decided which is greatest among them..

select ascii('100') from dual; gives 49 and
select ascii('23') from dual; gives 50

so 50>49 thats why the above sql::
select GREATEST('100','23') as "text" FROM Dual; gives 23 as o/p Smile
Previous Topic: oscmd.sql
Next Topic: Writing Hierarchical data into another table
Goto Forum:
  


Current Time: Sun Dec 11 03:58:25 CST 2016

Total time taken to generate the page: 0.11704 seconds