Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

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.



  


 Title: Simple Query
 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

  




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 Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik387
  Vinoth Kumar379
  Gopu Gopi350
  Gitesh Trivedi322
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software