How do I write this query?
April 18th, 2006 By arvind
Hi All,
Please extract record from EMP table suppose records are stored in given below
Eno Ename Dept 10 Arvind SW 10 Arvind Prog 10 Ajay SW
Result must be
Eno Ename Dept 10 Arvind SW/Prog 10 Ajay SW
please help me on urgent basis how can solve through SQL or PL/SQL.
Thanks & Regards,
Arvind

April 19th, 2006 at 7:35 am
head to http://asktom.oracle.com and search for stragg. load that in your db, then
will give you what you want. Otherwise write your owne plsql function to do the concat.
HTH
Raj
June 12th, 2006 at 5:05 am
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:= ”;
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 || ‘/’ || 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;