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 >> Can anybody solve this Challenging 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: Can anybody solve this Challenging Query.....?
 prasad  Posted: Apr 05, 2007 12:56:24 AM

 Total Post: 35
 Joined: Jan, 2007






 solve this query

table x
=====

id name
= =====
1 a
2 b
3 c
1 d
4 h
2 i
1 j
3 k
1 l
7 e
2 f

the output shoud be

id name
= ====

1 a,d,j,l

2 b,i,f

3 c,k

4 h

7 e


 sanju
Posted: Apr 05, 2007 02:29:21 AM  

 Total Post: 3
 Joined: Mar, 2007






 
sir i have a student of mca. i have become dba. i have no idea of dba so please advice me . iam starting preparing to dba.

 prasad
Posted: Apr 05, 2007 03:05:00 AM  

 Total Post: 35
 Joined: Jan, 2007






 
Hi Sanju,

It's good thing that you want to be a DBA. but for that you have to work really very hard. Its not like .....completing a course for 2-3 months......and you will become a DBA.

I am just making you aware what it takes to be a DBA.

As a fresher you have to keep reading books, articles and at the same time you should constantly practice lots of SQL/PL SQL queries.

All the Best.



 snehalatha
Posted: Apr 05, 2007 05:36:47 AM  

 Total Post: 169
 Joined: Apr, 2006






 
In ORACLE COALESCE funtion is there for concatenating the similar things.

i am giving the sample (it's works fine in SQL SERVER) change the syntax according to ORACLE and try it. This function gives exactly what you want


CREATE function fnCreateCSVString
(
@id INT)
returns varchar(1000)
AS
BEGIN
DECLARE @sMyString varchar(1000)
select @sMyString = COALESCE(@sMyString + ',', ' ') + NAME from sample where id = @id
RETURN @sMyString
END

Select A.id,dbo.fncreatecsvstring(A.id) from
(Select distinct id from sample) A

 busi
Posted: May 08, 2007 04:42:45 AM  

 Total Post: 13
 Joined: Jan, 2007






 
I think it will work

SELECT deptno,
get_employees(deptno) AS employees
FROM emp
GROUP by deptno;

or

SELECT deptno, string_agg(ename) AS employees
FROM emp
GROUP BY deptno;

or

SELECT deptno,
tab_to_string(CAST(COLLECT(ename) AS t_varchar2_tab)) AS employees
FROM emp
GROUP BY deptno;


regards
busi

 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 Khokhar856
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gitesh Trivedi322
  Gopu Gopi281
  neeraj sharma254
  Ramesh Jois245
  Bishal Khetan207






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