Topic: SQL*Plus and PL/SQL >> Simple Query
|
Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property.
You may review the entire Oracle Certification Program Candidate Agreement online Here.
|
|
|
|
| focusora |
Posted: Jun 27, 2008 04:28:03 AM |
Total Post: 18
Joined: May, 2008
|
Hi all.,
i need assist in simplyfying my sql query :
my tablename : XYZ having columns with data as
sql> select * from XYZ;
srno id name
---- -- ----
1 1 aa
2 1 bb
3 1 cc
4 X dd
Query : select distinct id from xyz group by id;
i get as :
id
--
1
X
But i don't want alphabetic ID = [ X ] entry in my Qusery .,
how to rewrite this query to get only id which as unique id like
id
--
1
|
|
|
shake |
| Posted: Jun 27, 2008 05:19:05 AM | |
|
Total Post: 85
Joined: Jun, 2008
|
Firstly, Create this function and execute it.
CREATE OR REPLACE FUNCTION isNumeric(n CHAR) RETURN BOOLEAN
IS
num NUMBER;
res BOOLEAN := TRUE;
BEGIN
num := TO_NUMBER(n);
RETURN res;
EXCEPTION WHEN OTHERS THEN
res := FALSE;
retun res;
END;
Now write this:
SQL>SET SERVEROUTPUT ON
SQL>DECLARE
CURSOR c1 IS SELECT DISTINCT(id) FROM XYZ;
BEGIN
FOR item IN c1 LOOP
IF isNumeric(item.id) THEN
dbms_output.put_line(item.id);
END IF;
END LOOP;
END;
You can find the results as you like.
|
|
|
|
|
focusora |
| Posted: Jun 27, 2008 05:36:36 AM | |
|
Total Post: 18
Joined: May, 2008
|
it works,
Thanks Shake ,
cheers !!
|
|
|
|
|
| Time Zone: EDT |
Send this thread to your friend |
|
|
|
|
Forum Rules & Description
Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user
|
| |
Get FREE Magazines
|
Top 10 Forum User
|
| Murtuja Khokhar | 857 |
| Mohammed Taj | 746 |
| positive fanatic | 483 |
| Jayanta Sur | 479 |
| Vigyan Kaushik | 387 |
| Vinoth Kumar | 379 |
| Gopu Gopi | 350 |
| Gitesh Trivedi | 322 |
| neeraj sharma | 258 |
| Ramesh Jois | 246 |
|
|