Join string from multiple rows sorry doublepost
Hi,
my table looks like the following:
id | count | val
1 1 Message
1 2 over
1 3 Rows
2 1 Second Message
3 1 Third
3 2 Message
I need a Querry so the output looks like this:
1 Message over Rows
2 Second Message
3 Third Message
Can anyone help me? Hope the solution is not very complex, cause i'm new to sql.
Thank You.
Edited by: user9371064 on 01.06.2010 09:01
Hi,
That's called String Aggregation .
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
is a good page on the subject, with deifferent techniques suitable for differetn versions of Oracle.
Similar Messages
-
Join string from multiple rows
Hi,
my table looks like the following:
id | count | val
1 1 Message
1 2 over
1 3 Rows
2 1 Second Message
3 1 Third
3 2 Message
I need a Querry so the output looks like this:
1 Message over Rows
2 Second Message
3 Third Message
Can anyone help me? Hope the solution is not very complex, cause i'm new to sql.
Thank You.Try this:
WITH SRC AS(
select '1' id, '1' cnt, 'Message' val from dual union all
select '1', '2', 'over' from dual union all
select '1', '3', 'Rows' from dual union all
select '2', '1', 'Second Message' from dual union all
select '3', '1', 'Third' from dual union all
SELECT '3', '2', 'MESSAGE' FROM DUAL
SELECT ID, substr(replace(SYS_CONNECT_BY_PATH(VAL, '#sep#'),'#sep#', ' '),2)
FROM SRC
where connecT_by_isleaf = 1
START WITH CNT = 1
CONNECT BY PRIOR CNT + 1 = CNT AND ID = PRIOR ID
;On 11g a recursive common table expression also works:
WITH SRC AS(
select '1' id, '1' cnt, 'Message' val from dual union all
select '1', '2', 'over' from dual union all
select '1', '3', 'Rows' from dual union all
select '2', '1', 'Second Message' from dual union all
select '3', '1', 'Third' from dual union all
SELECT '3', '2', 'MESSAGE' FROM DUAL
RECURSIVE(id, cnt, val) AS(
SELECT ID, CNT, VAL FROM SRC
WHERE CNT = 1
UNION ALL
SELECT SRC.ID, SRC.CNT, REC.VAL || ' ' || SRC.VAL
FROM RECURSIVE REC
JOIN SRC ON (REC.ID = SRC.ID AND REC.CNT + 1 = SRC.CNT)
SELECT ID, VAL
FROM RECURSIVE R1
WHERE NOT EXISTS( SELECT 1 FROM RECURSIVE
WHERE R1.ID = ID AND r1.cnt < cnt
ORDER BY ID
; -
How can i select some row from multiple row in the same group of data
I want to select some row from multiple row in the same group of data.
ColumnA
Column B
1 OK
1 NG
2 NG
2 NG
3 OK
3 OK
I want the row of group of
ColumnA if ColumnB contain even 'NG'
row , select only one row which Column B = 'NG'
the result i want =
ColumnA Column B
1 NG
2 NG
3 OK
Thank youThat's some awful explanation, but I think this is what you were driving at:
DECLARE @forumTable TABLE (a INT, b CHAR(2))
INSERT INTO @forumTable (a, b)
VALUES
(1, 'OK'),(1, 'NG'),
(2, 'NG'),(2, 'NG'),
(3, 'OK'),(3, 'OK')
SELECT f.a, MIN(COALESCE(f2.b,f.b)) AS b
FROM @forumTable f
LEFT OUTER JOIN @forumTable f2
ON f.a = f2.a
AND f.b <> f2.b
GROUP BY f.a -
Easy Question: How to split concatenated string into multiple rows?
Hi folks,
this might be an easy question.
How can I split a concatenated string into multiple rows using SQL query?
INPUT:
select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
Expected output:
data
AAA
BBB
CCC
DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
Thanks,
TomasHere is the SUBSTR/INSTR version of the solution:
SQL> WITH test_data AS
2 (
3 SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
4 )
5 SELECT SUBSTR
6 (
7 DATA
8 , INSTR
9 (
10 DATA
11 , ','
12 , 1
13 , LEVEL
14 ) + 1
15 , INSTR
16 (
17 DATA
18 , ','
19 , 1
20 , LEVEL + 1
21 ) -
22 INSTR
23 (
24 DATA
25 , ','
26 , 1
27 , LEVEL
28 ) - 1
29 ) AS NEW_STRING
30 FROM test_data
31 CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
32 /
NEW_STRING
AAA
BBB
CC
DDDD -
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
Creating stacked graph from multiple rows
Hi!
I am trying to create a stacked bar graph from multiple rows. My data looks like this:
Date_Time Error_Code Count
16-01-2011 12:00 100 10
16-01-2011 12:00 200 15
16-01-2011 12:10 100 5
16-01-2011 12:10 200 7
16-01-2011 12:20 300 20
16-01-2011 12:20 400 6
I want to stack the count of each error_code on top of each other for every time group.
Is this possible?
Br
CasperHi,
can you try
- select the graph in the Structure Window or the visual editor
- open Property Inspector
- Press Pencil Icon
- Click "Swap Bars with x-Axis"
Frank -
Concatenate strings from more rows into one row.
Hi,
what's the name of that analytical function (or connect by) that
would return strings from more rows as one row concatenated. i.e.:
(I know this is possible using regular pipelined functions.)
ROW1: STR1
ROW2: STR2
ROW3: STR3
select tadah().... from ...
result:
ROW1: STR1 STR2 STR3Thanks.Hi,
Here's a basic example of SYS_CONNECT_BY_PATH.
The query below produces one row of output per department, containing a list of the employees in that department, in alphabetioc order.
WITH got_rnum AS
SELECT ename
, deptno
, ROW_NUMBER () OVER ( PARTITION BY deptno
ORDER BY ename
) AS rnum
FROM scott.emp
-- WHERE ... -- Any filtering goes here
SELECT deptno
, LTRIM ( SYS_CONNECT_BY_PATH ( ename
, ',' -- Delimiter, must never occur in ename
) AS ename_list
FROM got_rnum
WHERE CONNECT_BY_ISLEAF = 1
START WITH rnum = 1
CONNECT BY rnum = PRIOR rnum + 1
AND deptno = PRIOR deptno
;Output:
. DEPTNO ENAME_LIST
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARDThe basic CONNECT BY query would produce one row per employee, for example:
. DEPTNO ENAME_LIST
10 ,CLARK
10 ,CLARK,KING
10 ,CLARK,KING,MILLER
20 ,ADAMS
20 ,ADAMS,FORD
...The WHERE clause: <tt>WHERE CONNECT_BY_ISLEAF = 1</tt> means that we'll only see the last row for every department.
SYS_CONNECT_BY_PATH (which is a row function, by the way, not an analytic fucntion) puts a delimiter (',' in the example above) before every item on the list, including the first one.
The query above uses LTRIM to remove the delimiter at the very beginning.
WM_COMCAT (or the equivalent user-defined STRAGG, which you can copy from AskTom) is much more convenient if order is not important. -
Collecting data from multiple rows into one column
I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
"CORE 10.2.0.5.0 Production"
TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
CREATE TABLE "SKIP"."INGREDIENTS"
( "INGRED_ID" NUMBER,
"INGRED_NAME" VARCHAR2(20 BYTE),
"STORES" VARCHAR2(20 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGREDIENTS
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
CREATE TABLE "SKIP"."PRETZELS"
( "PRETZEL_ID" NUMBER,
"PRETZEL_NAME" VARCHAR2(20 BYTE),
"PRETZEL_DESC" VARCHAR2(100 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.PRETZELS
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
CREATE TABLE "SKIP"."INGRED_XREF"
( "PRETZEL_ID" NUMBER,
"INGRED_ID" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGRED_XREF
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
-- Constraints for Table INGRED_XREF
ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
{code}
Desired output (note how the ingredients are all listed in one column, separated by commas):
{code}
PRETZEL_ID PRETZEL_NAME PRETZEL_DESC INGREDIENTS
1 CLASSIC Classic knot pretzel SEA SALT, TABLE SALT, YEAST
2 THICK STICK Straight pretzel, abt 1/2" in dia TABLE_SALT, FLOUR, BEERSee the FAQ : {message:id=9360005}
Especially links concerning string aggregation. -
Saving string from multiple clients on a server data structue
I have a server which receives updates from multiple clients ( in this example, football scores which are updated periodically by the clients.)
When the server receives the scores it needs to store them and at certain time intervals send the complete list of scores to multiple terminals at various locations.
I am approaching this task in stages...
stage 1.
..create the clients and server ...test the clients can send the data and the server can receive the data and output to screen..
this is completed
stage 2...
a/ on the server side store the received scores in a data structure (ArrayList<String> is what I'm thinking.)
b/ periodically output all scores to the screen (maybe every 30 seconds) and empty the ArrayList..am looking at the Timer class for this part..
stage 3
create the monitors and output scores to monitors periodically..
======================================================
right now I'm at stage 2a ie trying to store the received scores in a data structure.
i've created a method saveScore in the StoreScore class which is called by the StoreScore run method...
The saveScore method creates an ArrayList and adds the score to it...
Question
does every thread create a new instance of storedScores and therefore the scores are stored in a multitude of data structures?
I think the answer is yes and if so then this is not the solution...
What I'm thinking is , as all scores can be outputted to the server screen via System.out.println, is there not a way of saving all these scores in a single data structure?
The code below is the server code..
any advice much appreciated....thank you
/*=============================================================== */
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
class ScoresServer1{
final static int portNum = 1234; // any number > 1024
final static int numThreads = 10;
static ExecutorService pool;
public static void main(String[] args){
pool = Executors.newFixedThreadPool(numThreads);
System.out.println("Server running ...");
try{
ServerSocket servesock = new ServerSocket(portNum);
// for service requests on port
while (true){
// wait for a service request on port portNum
Socket socket = servesock.accept();
// submit request to pool
pool.submit(new StoreScore(socket));
}catch(IOException e){}
class StoreScore implements Runnable {
BufferedReader reader;
Socket sock;
public StoreScore(Socket clientSOcket) {
try {
sock = clientSOcket;
InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(isReader);
} catch (Exception ex) { ex.printStackTrace(); }
public void run() {
String message;
try {
while ((message = reader.readLine()) != null) {
// System.out.println("latest score: " + message);
saveScore(message);
} catch (Exception ex) { ex.printStackTrace(); }
public void saveScore(String message){
ArrayList<String> storedScores = new ArrayList<String>();
storedScores.add(message);
Iterator<String> t = storedScores.iterator();
while(t.hasNext()){
String s = t.next();
System.out.println(s);
}does every thread create a new instance of storedScores and therefore the scores are stored in a multitude of data structures?
I think the answer is yes and if so then this is not the solution...The answer is yes. However, threads can share data, if they were properly synchronized. You should read the threading tutorial before creating a lot of hard to debug mistakes.
[http://java.sun.com/docs/books/tutorial/essential/concurrency/] -
How to return a single datetime from multiple rows of MAX(value) in DAX
Hi
I have a Results table with ResultTime, Balance, Equity which is updated with a new row every 5 minutes. I've used SUMX to find opening and closing balances and it has worked so far.
Res_OpeningBalance:=SUMX(TOPN(1,Results,Results[ResultTime],1),[Balance])
Res_ClosingBalance:=SUMX(TOPN(1,Results,Results[ResultTime],0),[Balance])
But when I tried it with dates, the whole thing fell apart.
Res_MaxBalance_Date:=SUMX(TOPN(1,Results,Results[Balance],0),[ResultTime])
Since the highest Balance is likely to be represented through many rows due to it lasting more than 5 minutes, ResultTime (which is unique to each row) is summed up and returns messed up dates well into the future. How to return only one date (first or last
datetime) from the rows where Balance is at max?
I tried a TOPN of TOPN, but Excel was not amused.
=SUMX(TOPN(1,Results,Results[Balance],0),TOPN(1,Results,Results[ResultTime],0))
TIA!
Re
DennisI still don't understand RANKX, but I figured it out anyway. I get the correct data by using:
Res_MaxBalance:=MAX(Results[Balance])
Res_MaxBalanceDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Balance]=MAX(Results[Balance])))
Res_MinBalance:=MIN(Results[Balance])
Res_MinBalanceDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Balance]=MIN(Results[Balance])))
Res_MaxEquity:=MAX(Results[Equity])
Res_MaxEquityDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Equity]=MAX(Results[Equity])))
Res_MinEquity:=MIN(Results[Equity])
Res_MinEquityDate:=CALCULATE(MAX(Results[ResultTime]),FILTER(Results, Results[Equity]=MIN(Results[Equity])))
Re
D -
How to genereate multiple IDOCs from multiple rows in a single flat file
HI,
I am working on a scenario where I need to genereate a IDOC per one row in a flat file.
I created DT of following strcuture:
DT_TYPE
--DETAILS -
0..Unbound
F1------0..Unbound
F2------0..Unbound
F3------0..Unbound
IDOC is
ZIDOC
IDOC----1..1
-BEGIN-Required
-SEGMENT1---1..1
-SEGEMENT2-1..1
-SEGMENT3-1..999
To create multiple IDOCs if there are multiple rows in a flat file in MM i choosed occurances as 0..unbound in Signiture tab
Source structure:
Messages------1...1
-Message1--1....1
DT_TYPE------0..Unbound
DETAILS -
0..Unbound
F1------0..Unbound
F2------0..Unbound
F3------0..Unbound
Target Strcuture:
Messages----1....1
-Message--1....1
ZIDOC----1....1
IDOC------1..1
BEGIN---Required
SEGMENT1-----1..1
SEGEMENT2---1..1
SEGMENT3---1..999
I am unable to generate two IDOCs if there are two rows:
Am I missing some thing?
Thanks
RajeevHI,
I am working on a scenario where I need to genereate a IDOC per one row in a flat file.
I created DT of following strcuture:
DT_TYPE
--DETAILS -
0..Unbound
F1------0..Unbound
F2------0..Unbound
F3------0..Unbound
IDOC is
ZIDOC
IDOC----1..1
-BEGIN-Required
-SEGMENT1---1..1
-SEGEMENT2-1..1
-SEGMENT3-1..999
To create multiple IDOCs if there are multiple rows in a flat file in MM i choosed occurances as 0..unbound in Signiture tab
Source structure:
Messages------1...1
-Message1--1....1
DT_TYPE------0..Unbound
DETAILS -
0..Unbound
F1------0..Unbound
F2------0..Unbound
F3------0..Unbound
Target Strcuture:
Messages----1....1
-Message--1....1
ZIDOC----0....unbound
IDOC------1..1
BEGIN---Required
SEGMENT1-----1..1
SEGEMENT2---1..1
SEGMENT3---1..999
I am unable to generate two IDOCs if there are two rows:
Am I missing some thing?
It isnt possible with out BPM?
Thanks
Rajeev -
How to create XML from multiple rows in a table?
Hi All,
I have a table where it has multiple rows as below which I need to send as a XML.. can any one let me know how to create?
Table:
PRDID,NAME,DESCRIPTION,SUPPLIER,PRICE
2012,AAA,ADESC,SUPPLIER1,1.8
2012,AAA,ADESC,SUPPLIER2,2.5
XML should be :
<ROOT>
<PRDID>2012</PRDID>
<NAME>AAA</NAME>
<DESCRIPTION>ADESC</DESCRIPTION>
<PRICE>
<REGION>SUPPLIER1</REGION>
<PRICE>1.8</PRICE>
<REGION>SUPPLIER2</REGION>
<PRICE>2.5</PRICE>
</PRICE>
</ROOT>
Thanks
RajeevHi
This white paper shows how to do it - http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/101c974c-11f9-2b10-4da5-cd350b7eeda0
Michael -
Return 2 values (string, number) multiple rows, from java stored function
I would like to return 2 values (String, number prefered but String, String will work) from a java stored function.
I was able to successfully return a varray of varchar2 values but I was wondering if it is possible to return 2 values by using a varray?
Is it even possible? I tried using combinations of types which included a varray of objects (with 2 attributes) or a type as table of objects but I couldn't figure out how in my java code to set these values. Also what would my java function return type be and what Oracle type would map to it?
Any help and examples or pointers would be great.
Thanks,
DennisThanks to all. I finally figured it out through all the pieces on the web.
Here is what worked for me. First create 2 oracle types. One object type to represent the "columns" I will pass back:
CREATE OR REPLACE TYPE COST_OBJ AS OBJECT (COST_NAME NVARCHAR2(50), COST_VALUE number ) NOT FINAL
note: make sure the "strings" are defined as NVARCHAR2 or Java will puke if it is just VARCHAR2.
Then create a table type to hold your objects defined as following:
CREATE OR REPLACE TYPE COST_OBJ_TABLE is table OF COST_OBJ
Then create the oracle stored function that is a wrapper to the java function:
CREATE OR REPLACE FUNCTION get_Costs(Name VARCHAR2, evalDate VARCHAR2, fuelCodeID NUMBER) return COST_OBJ_TABLE
is language java name
'com.costs.storedProcedures.Cost.getCosts(java.lang.String, java.lang.String, int) return oracle.sql.ARRAY'
Once that is done, Oracle is ready. The Java function looks something like this:
public ARRAY getCosts(String name, String evalDate, int fuelCodeID) {
DBAccess da = getDBAccess();
// get a handle on the connection
Connection conn = da.getConnection();
// The stuff that will be returned should be as type object array
// make it to the size of the number of fuelcomponents passed in
Object[] returnStuff = new Object[3];
// create the type of struct that is defined on the database
StructDescriptor structDesc =
StructDescriptor.createDescriptor("CY_UMAP.COST_OBJ", conn);
for (int i = 0; i < returnStuff .size(); i++) {
Object[] costValues = new Object[]{
"This is object " + i,
new Integer ( i ) };
STRUCT cost_obj = new STRUCT(structDesc, conn, costValues);
returnStuff[i] = cost_obj;
ArrayDescriptor x_ad = ArrayDescriptor.createDescriptor (
"CY_UMAP.COST_OBJ_TABLE", conn);
ARRAY x_array = new ARRAY(x_ad, conn, returnStuff);
return x_array;
I hope this helps others.
Dennis -
Create a view to shows data from multiple rows in a single column
Hi all - this is probably posted in the wrong forum but I couldn't find which was the correct one.
I am almost a complete novice at sql but I have a need to create a view which can be developed at 10g (which runs efficiently as the volumes are likely to be high) which will do the following.
Original table with columns Parent_code, Child_code
Parent_Code Child_Code
1000 2000
1000 3000
1000 4000
2000 3000
2000 5000
(note Parents can have multiple children and a child can have multiple parents!)
What I need to end up with in my view is the following
Child_Code Parent_List
2000 '1000 (3)'
3000 '1000 (3), 2000 (2)'
4000 '1000 (3)'
5000 '2000 (2)'
Note the number in parantheses is the number of children that the parent has - ie in the original table parent 1000 has 3 rows (one for each child)
This view is then to be used as a look up (on child code) for a business objects report.
Is there anyone who could PLEASE, PLEASE help me fairly quickly on this as I have very little time to find a solution?Hi,
You can test these ones :
select child_code
, ltrim(sys_connect_by_path(parent_info,', '), ', ') as parent_list
from (
select child_code
, to_char(parent_code) ||
' (' ||
count(*) over(partition by parent_code) ||
')' as parent_info
, row_number() over(partition by child_code order by parent_code) rn
from your_table
where connect_by_isleaf = 1
connect by prior rn = rn-1
and prior child_code = child_code
start with rn = 1
select child_code,
rtrim(
extract(
xmlagg(xmlelement("e",parent_info||', ') order by parent_info)
, '//text()'
) as parent_list
from (
select child_code,
to_char(parent_code) ||
' (' ||
count(*) over(partition by parent_code) ||
')' as parent_info
from your_table
group by child_code
;What you need is called "string aggregation".
See here for various techniques, including the two above : http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php -
Problem to get one row from multiple rows
Hi,
i have master detail form.
for one entry in master, i have multiple in detail table.
and in report i want to join both to get the single row.
is it possible in D2k forms(Oracle)
Eg.
I have table hotel
id name location
101 taj delhi
and another table hoteldetail
id roomtype price
101 single 1000
101 double 2000 etc
now in d2k report i want to show data as
id 101
name taj
location delhi
single 1000
double 2000
please help if there is any way
Thanks
kammy
Edited by: user629129 on Dec 16, 2009 5:03 AM
Edited by: user629129 on Dec 16, 2009 5:05 AMhi
if i got u then
try something like this.
SQL> select emp.empno,emp.ename,dept.deptno,dept.loc from emp,dept where emp.deptno=dept.deptno;
EMPNO ENAME DEPTNO LOC
7369 SMITH 20 DALLAS
7499 ALLEN 30 CHICAGO
7521 WARD 30 CHICAGO
7566 JONES 20 DALLAS
7654 MARTIN 30 CHICAGO
7698 BLAKE 30 CHICAGO
7782 CLARK 10 NEW YORK
7788 SCOTT 20 DALLAS
7839 KING 10 NEW YORK
7844 TURNER 30 CHICAGO
7876 ADAMS 20 DALLAS
EMPNO ENAME DEPTNO LOC
7900 JAMES 30 CHICAGO
7902 FORD 20 DALLAS
7934 MILLER 10 NEW YORK
14 rows selected.sarah
Maybe you are looking for
-
Bitwise logical ops on src/dest. bitmaps
Those familar with the C/C++ world should understand what I mean by bitwise logical operations, i.e. performing logical AND, OR, NOT on the bits of a src and destination value to get a result. Those familiar with Win32 GDI and BitBlt know that it all
-
Enterprise Portal 6.0 - Iviews not refreshing.
We are using Single Sign On using logon tickets with EP 6.0. This had been working fine until a couple of weeks ago when Microsoft patch MS06-067 was applied. This is an Internet Explorer patch applying Active X controls. Now, when we launch the port
-
My ipod nano 1gb plays, but the center button won't allow me to select specific songs. It doesn't recognize when I press to select from the menu (ie., "music >"). I've reset it several times... any ideas? dell Windows XP dell Windows XP
-
Default Photo is accidentally deleted?
When I set up my Macbook, I took a picture. Just now, System Preferences/Accounts/Picture, I clicked on a different picture and now I can't get back the original one I had- the one that appears on my emails. Where did it go. I thought I had to click
-
Transport Query generated program using SQ01
Dear All, Please let me know how to transport a query generated program using SQ01. I have created a program from SQ01 query creation and assign a tcode to this program. When the program was generated there was no request create so how to make a requ