<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How do I write this query?</title>
	<atom:link href="http://oraqa.com/2006/04/18/how-do-i-write-this-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2006/04/18/how-do-i-write-this-query/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Tue, 13 Mar 2012 16:20:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: shunya</title>
		<link>http://oraqa.com/2006/04/18/how-do-i-write-this-query/comment-page-1/#comment-186</link>
		<dc:creator>shunya</dc:creator>
		<pubDate>Mon, 12 Jun 2006 13:05:51 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/04/18/how-do-i-write-this-query/#comment-186</guid>
		<description><![CDATA[Try this


CREATE TABLE TMP_EMP
(
  EMP_NO     NUMBER,
  EMP_NAME   VARCHAR2(20),
  DEPT_NAME  VARCHAR2(20)
);
commit;


create or replace function con_dept(vEMP_NO in number) 
Return varchar2
is 
   cursor cs is
   		  select distinct e.DEPT_NAME
		  from tmp_emp e
		  where  e.EMP_NO = vEMP_NO;	   
   
   vDEPT varchar2(40);
   vTMP_DEPT varchar2(20);
 
begin
	 
    vDEPT:= &#039;&#039;;

	IF cs%ISOPEN THEN
		CLOSE cs;
	END IF;
	
	
	 open cs;
	 loop
	 	
		 fetch cs into vTMP_DEPT;
 	 	 dbms_output.put_line(vTMP_DEPT);
		 exit when cs%notfound;
		 vDEPT:=vDEPT &#124;&#124; &#039;/&#039; &#124;&#124; vTMP_DEPT;
		  
	 end loop;
	 CLOSE cs;
	 
	 vDEPT := substr(vDEPT,2,length(vDEPT));
	 
	 return vDEPT;
	 	 
end;



select distinct t.EMP_NO,t.EMP_NAME,con_dept(t.EMP_NO)
from tmp_emp t;]]></description>
		<content:encoded><![CDATA[<p>Try this</p>
<p>CREATE TABLE TMP_EMP<br />
(<br />
  EMP_NO     NUMBER,<br />
  EMP_NAME   VARCHAR2(20),<br />
  DEPT_NAME  VARCHAR2(20)<br />
);<br />
commit;</p>
<p>create or replace function con_dept(vEMP_NO in number)<br />
Return varchar2<br />
is<br />
   cursor cs is<br />
   		  select distinct e.DEPT_NAME<br />
		  from tmp_emp e<br />
		  where  e.EMP_NO = vEMP_NO;	   </p>
<p>   vDEPT varchar2(40);<br />
   vTMP_DEPT varchar2(20);</p>
<p>begin</p>
<p>    vDEPT:= &#8221;;</p>
<p>	IF cs%ISOPEN THEN<br />
		CLOSE cs;<br />
	END IF;</p>
<p>	 open cs;<br />
	 loop</p>
<p>		 fetch cs into vTMP_DEPT;<br />
 	 	 dbms_output.put_line(vTMP_DEPT);<br />
		 exit when cs%notfound;<br />
		 vDEPT:=vDEPT || &#8216;/&#8217; || vTMP_DEPT;</p>
<p>	 end loop;<br />
	 CLOSE cs;</p>
<p>	 vDEPT := substr(vDEPT,2,length(vDEPT));</p>
<p>	 return vDEPT;</p>
<p>end;</p>
<p>select distinct t.EMP_NO,t.EMP_NAME,con_dept(t.EMP_NO)<br />
from tmp_emp t;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rjamya</title>
		<link>http://oraqa.com/2006/04/18/how-do-i-write-this-query/comment-page-1/#comment-177</link>
		<dc:creator>rjamya</dc:creator>
		<pubDate>Wed, 19 Apr 2006 15:35:34 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/04/18/how-do-i-write-this-query/#comment-177</guid>
		<description><![CDATA[head to http://asktom.oracle.com and search for &lt;b&gt;stragg&lt;/b&gt;. load that in your db, then
&lt;pre&gt;
select eno, ename, stragg(dept) as dept
  from emp
  group by eno,ename
/
&lt;/pre&gt;

will give you what you want. Otherwise write your owne plsql function to do the concat.

HTH
Raj]]></description>
		<content:encoded><![CDATA[<p>head to <a href="http://asktom.oracle.com" rel="nofollow">http://asktom.oracle.com</a> and search for <b>stragg</b>. load that in your db, then</p>
<pre>
select eno, ename, stragg(dept) as dept
  from emp
  group by eno,ename
/
</pre>
<p>will give you what you want. Otherwise write your owne plsql function to do the concat.</p>
<p>HTH<br />
Raj</p>
]]></content:encoded>
	</item>
</channel>
</rss>
