Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Finding largest key in Oracle using SQL commands?

Re: Finding largest key in Oracle using SQL commands?

From: Martin Doherty <martin.doherty_at_oorraaccllee.com>
Date: Wed, 04 Dec 2002 12:22:06 -0800
Message-ID: <fytH9.11$T1.113@news.oracle.com>


Billy's answer is great for date or number keys, but if you are looking for the longest VARCHAR2 key then use
SELECT MAX(LENGTH(key_column_name) FROM table_name

Or, to find the distribution of key lengths, try this: SELECT LENGTH(key_column_name) keylength, COUNT(*) quantity FROM table_name
GROUP BY LENGTH(key_column_name)
ORDER BY keylength DESC

Martin Doherty

Billy Verreynne wrote:

>Keith Lee wrote:
>
>
>
>>Does anyone know how to find the largest key in an Oracle database using
>>SQL commands? I could open use a PL/SQL procedure to loop through the
>>table until I get to the largest key; but, I was wondering if there was
>>any SQL command to do this.
>>
>>
>
>You're looking for the MAX() function.
>
>Something like:
>SELECT MAX(age) FROM employees
>
>..which will give you the age of the oldest employee(s).
>
>I suggest that you spend some time with the Oracle SQL manual - SQL can do
>some pretty impressive stuff without needing to resort to PL/SQL or other
>languages.
>
>Remember that the secret of data processing in a database, is to let the
>database do all the work. SQL does exactly that. As soon as you use PL/SQL
>or any other language, _you_ do the processing with your code. Most of the
>time, this will be row-by-row processing. And several orders of magnitude
>slower than using SQL.
>
>So little grasshopper, the better you know SQL, the better your database
>kung fu. ;-)
>
>
>--
>Billy
>
Received on Wed Dec 04 2002 - 14:22:06 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US