Home » Developer & Programmer » Reports & Discoverer » multiples rows into one row. (Oracle 10XE , form 6i)
multiples rows into one row. [message #675368] |
Sun, 24 March 2019 10:48 |
shahzad-ul-hasan
Messages: 643 Registered: August 2002
|
Senior Member |
|
|
create table student (stuid number(6) primary key,name varchar2(30),mob varchar2(20));
insert into student (1,'abc','92333444444');
insert into student (2,'aac','92333004444');
insert into student (3,'avc','92333004444');
insert into student (4,'afc','92333233444');
insert into student (5,'atc','92333233444');
insert into student (6,'arc','92333444444');
insert into student (7,'aec','92333444444');
insert into student (8,'atc','92333123444');
insert into student (9,'arc','92332334444');
insert into student (10,'aec','92333444444');
i want to get the result as:
mob Stuid
---------------------------------------------------
92333444444 (1,6,7,10)
92333004444 (2,3)
92332334444 (4,5,9)
Quote:
SQL> CREATE TYPE number_7_2_ntt AS TABLE OF NUMBER(7,2);
2 /
Type created.
SQL> SELECT mob
2 , CAST(COLLECT(stuid) AS number_7_2_ntt) AS sals
3 FROM student
4 GROUP BY
5 mob;
mob SALS
---------- -------------------------------------------------------------------------
92333444444 Number_ntt(1,6,7,10)
92333004444 Number_ntt(2,3)
92332334444 Number_ntt(4,5,9)
how i can use this query in reports.it return error:
00-600: internal error code : argument [17069]/
please advised.
|
|
|
Re: multiples rows into one row. [message #675369 is a reply to message #675368] |
Sun, 24 March 2019 13:39 |
John Watson
Messages: 8964 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
I am not any sort of Forms bloke, but I have heard that if Forms doesn't understand something the answer may be to create a view that does the work and in Forms query the view.
|
|
|
Re: multiples rows into one row. [message #675370 is a reply to message #675368] |
Sun, 24 March 2019 14:06 |
|
Michel Cadot
Messages: 68732 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Apart that the test case is not correct:
SQL> insert into student (1,'abc','92333444444');
insert into student (1,'abc','92333444444')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword
And that the result from it is not correct
And that in your more than 200 topics you fed back and thanked people who spent time to help you only (about) once, here's how you can do it:
SQL> select mob,
6 /
MOB STUID
-------------------- ------------------------------
92332334444 (9)
92333004444 (2,3)
92333123444 (8)
92333233444 (4,5)
92333444444 (1,6,7,10)
|
|
|
Re: multiples rows into one row. [message #675371 is a reply to message #675370] |
Sun, 24 March 2019 21:05 |
shahzad-ul-hasan
Messages: 643 Registered: August 2002
|
Senior Member |
|
|
create table student (stuid number(6) primary key,name varchar2(30),mob varchar2(20));
insert into student values (1,'abc','92333444444');
insert into student values (2,'aac','92333004444');
insert into student values (3,'avc','92333004444');
insert into student values (4,'afc','92333233444');
insert into student values (5,'atc','92333233444');
insert into student values (6,'arc','92333444444');
insert into student values (7,'aec','92333444444');
insert into student values (8,'atc','92333123444');
insert into student values (9,'arc','92332334444');
insert into student values (10,'aec','92333444444');
i want to get the result as:
mob Stuid
---------------------------------------------------
92333444444 (1,6,7,10)
92333004444 (2,3)
92332334444 (4,5,9)
|
|
|
Re: multiples rows into one row. [message #675373 is a reply to message #675371] |
Sun, 24 March 2019 23:21 |
shahzad-ul-hasan
Messages: 643 Registered: August 2002
|
Senior Member |
|
|
SQL> select
2 p.mob,
3 (select xmlagg(xmlelement(E, d.stuid || ',')).extract('//text()') AS SE
from student d where d.mob = p.mob)
4 from student p;
ERROR:
ORA-22922: nonexistent LOB value
WANT TO USE THIS QUERY IN REPORT BUILDER.
|
|
|
|
Re: multiples rows into one row. [message #675376 is a reply to message #675374] |
Mon, 25 March 2019 07:20 |
shahzad-ul-hasan
Messages: 643 Registered: August 2002
|
Senior Member |
|
|
i have created a view. but i found this after using it.
MOB SEE
923056733136 [datatype]
923042039519 [datatype]
923063375586 [datatype]
923063375586 [datatype]
923337663357 [datatype]
923337663357 [datatype]
923016301936 [datatype]
Quote:
CREATE OR REPLACE FORCE VIEW "MAS" ("MOB", "SEE") AS
select p.mob,
(select xmlagg(xmlelement(E, d.stuid || ',')).extract('//text()')
from student d where d.mob = p.mob) as see
from student p
/
[Updated on: Mon, 25 March 2019 07:21] Report message to a moderator
|
|
|
|
|
|
Re: multiples rows into one row. [message #675382 is a reply to message #675381] |
Mon, 25 March 2019 14:02 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Create your own function. For such a simple task, the function is simple as well. For example:
SQL> select * From student;
STUID NAME MOB
------------ ------------------------------ --------------------
1 abc 92333444444
2 aac 92333004444
3 avc 92333004444
4 afc 92333233444
5 atc 92333233444
6 arc 92333444444
7 aec 92333444444
8 atc 92333123444
9 arc 92332334444
10 aec 92333444444
10 rows selected.
SQL> create or replace function f_mob (par_mob in varchar2)
2 return varchar2
3 is
4 retval varchar2(30);
5 begin
6 for cur_r in (select stuid from student
7 where mob = par_mob)
8 loop
9 retval := retval ||','|| cur_r.stuid;
10 end loop;
11
12 retval := ltrim(rtrim(retval, ','), ',');
13 return retval;
14 end;
15 /
Function created.
SQL> select f_mob('92333004444') one,
2 f_mob('92333444444') two
3 from dual;
ONE TWO
-------------------- --------------------
2,3 1,6,7,10
SQL>
|
|
|
|
|
|
Re: multiples rows into one row. [message #677624 is a reply to message #675396] |
Tue, 01 October 2019 08:36 |
shahzad-ul-hasan
Messages: 643 Registered: August 2002
|
Senior Member |
|
|
HERE IS ANOTHER ANSWER FOR Michel cadot
CREATE OR REPLACE TYPE t_string_agg AS OBJECT
(
g_string VARCHAR2(32767),
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER
);
/
SHOW ERRORS
CREATE OR REPLACE TYPE BODY t_string_agg IS
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER IS
BEGIN
sctx := t_string_agg(NULL);
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER IS
BEGIN
SELF.g_string := self.g_string || ',' || value;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER IS
BEGIN
returnValue := SUBSTR(SELF.g_string, 2);
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER IS
BEGIN
SELF.g_string := SELF.g_string || ctx2.g_string;
RETURN ODCIConst.Success;
END;
END;
/
SHOW ERRORS
CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;
/
SHOW ERRORS
The aggregate function is implemented using a type and type body, and is used within a query.
COLUMN employees FORMAT A50
SELECT /*+ PARALLEL(2) */ deptno, string_agg(ename) AS employees
FROM emp
GROUP BY deptno;
|
|
|
|
|
Goto Forum:
Current Time: Thu Jan 30 18:25:24 CST 2025
|