Multilple row in one column ( sql as well as pl/sql)
hi sir,Madam
i have a table emp . it contains 3 column and 5 rows that are following
empno
months
salary
100
jan
8000
100
feb
10000
100
mar
12000
101
jan
20000
101
feb
10000
my desired output should be like below
empno
months
100
jan,feb, mar
101
jan,feb
Please help me
thanks in advanced
kPrem
Hi,
That's called String Aggregation. This page:
ORACLE-BASE - String Aggregation Techniques
shows several ways to do it.
Which way is best for your data ,your requirements and your version of Oracle? That depends on your data ,your requirements and your version of Oracle.
LISTAGG is especially useful.
Similar Messages
-
Hi all,
I want to display the rows as one column
Source Amount
A 100
A 200
B 300
B 400
C 500
C 600
I want to display like below
Sum(A) Sum(B) Sum(C)
300 700 1100
Is it possible to do in SQL
ThanksSELECT
SUM(DECODE(source, 'A', amount, 0)) sum_a,
SUM(DECODE(source, 'B', amount, 0)) sum_b,
SUM(DECODE(source, 'C', amount, 0)) sum_c
FROM
t
SUM_A SUM_B SUM_C
300 700 1100 -
How to suppress row when one column has zero using condition
Hi Experts,
How do I suppress row when one column has zero.
I read it is possible using conditions.
How ?
Thankyou.Check this
1. for Query Properties, go to the Display tab and Supress Zeros is "Active"
2. select the Structure, right-click, select Properties, then click "on" Also Use Zero Suppression for Structure Elements
http://help.sap.com/saphelp_nw04/helpdata/en/a4/dd3841d132d92be10000000a1550b0/frameset.htm
Hope it Helps
Chetan
@CP.. -
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. -
How to select rows whose one column contains some specific characters ?
These is a table say T1 with a column say C1
Let the field C1's values be:
row 1)DE/SPT/A/FWD
row 2)G/SPT/DE/DE/SPT
row 3)R/FWD/SPT/A/FWD/FWD
row 4)A/A/DE/SPT/FWD
row 5)FWD/SPT/E/DE/A
How to get only those rows whose C1 column contains FWD in last ?We can solve this with the simple use of a wildcard:
select *
from t1
where c1 like '%FWD'
/Note that this query will execute a full table scan, because any index you may have on C1 will be ignored: indexes are organised on the leading characters.
cheers, APC -
Multiple Rows Into One Column Field
Hi All,
Today I tried one query:
select wm_concat(ename) from emp
group by deptno;
I have a data that looks like this.
CLARK,KING,MILLER,SREE
JONES,FORD,ADAMS,SCOTT
ALLEN,MARTIN,BLAKE,TURNER,JAMES,WARD
Can someone help me to build an SQL command that would have the output as follows:
I need per column 3 values....
CLARK,KING,MILLER,
SREE,JONES,FORD,
ADAMS,SCOTT,ALLEN,
MARTIN,BLAKE,TURNER,
JAMES,WARDStewAshton wrote:
That's funny, I don't get the same answer
Why do you think you should?
Besides, you're not the only one.
ENAMES
KING,BLAKE,CLARK
JONES,SCOTT,FORD
SMITH,ALLEN,WARD
MARTIN,TURNER,ADAMS
JAMES,MILLER
Regards
Etbin
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
It's from my APEX Workspace: first select from the emp table (not touched until now)
Message was edited by: Etbin -
Dynamic table - some fields of different rows in one column
Hey guys,
i have the following problem:
i habe a itab with some data like:
name | id | date | number
pete | 1 | 27.07 | 2
pete | 1 | 28.07 | 2
pete | 1 | 30.07 | 2
ann | 1 | 28.07 | 3
ann | 2 | 30.07 | 2
the user can define a period of time, e.g. 28-29.07
so my dynamic table will consist of the "hard" columns name and id and the dynamic added columns for every day:
name | id | 28.07 | 29.07
that's what i already have!
so my problem is, that i have to read the data from the itab into the new dynamic table (field-symbol) like:
name | id | 28.07 | 29.07
pete | 1 | 2 | 2
ann | 1 | 3 | -
i hope you can understand what i want! please give me code sample or a example report!
many thanks in adance!
best regards,
ludwighey Asik, you have understand what i want!
here is my table:
http://img181.imageshack.us/my.php?image=wh20080916113004ym8.png
after the loop, the 4 rows should be in my field-symbol only one row (no sum)!
but after the loop, there are to many rows! only one row is needed!
Look at the screenshot:
http://img185.imageshack.us/my.php?image=wh20080916113547wl0.png
So the second row at column "tag20080801" should be initial and with the next loop, the next day "tag20080730" should be filled with the number!
LOOP AT LT_OUT INTO LS_OUT.
ASSIGN COMPONENT 'RESSOURCEN' OF STRUCTURE <FS_LINE> TO <fs_field>.
<fs_field> = 'Ressource'.
ASSIGN COMPONENT 'NAME' OF STRUCTURE <FS_LINE> TO <fs_field>.
<fs_field> = LS_OUT-name.
ASSIGN COMPONENT 'PROJEKT' OF STRUCTURE <FS_LINE> TO <fs_field>.
<fs_field> = LS_OUT-PROJECTID.
CONCATENATE 'DATE' LS_OUT-DATE INTO LF_DATE_COL.
ASSIGN COMPONENT LF_DATE_COL OF STRUCTURE <FS_LINE> TO <fs_field>.
<fs_field> = LS_OUT-COUNT.
COLLECT <FS_LINE> INTO <FS_TABLE>.
ENDLOOP.
the right output data should look like this:
Ressourcen | Ludwig Heinz | 20080702LHZ | 4 | 4 | 4 | 1 -
Highlight complete row if one column is null
Hi,
i want to highlight a complete row in my publisher report if a certain column of the
row is empty (no value at all). I already tried to get forward using the examples in the
XML Publisher developer guide (i checked the samples installed by xml publisher desktop
as well) but none of them delivered the desired result.
Any hints are welcome.
regards
ThomasHi,
You can write the following code to highlight a row if a certain column is null:
<?if@row:COLUMN-NAME=''?><xsl:attribute name="background-color" xdofo:ctx="incontext">red</xsl:attribute><?end if?>
You can place this code in a text form field and place in the first column after the for-each statement.
Hope this helps.
Thanks. -
Returning two rows with one column containing only one place
Dear all;
I have a query that returns two rows similar to this below
ID PLACE PROGRAM
A NEWYORK PROGRAM A
A NEWYORK PROGRAM B
I would like this instead
ID PLACE PROGRAM
A NEWYORK PROGRAM A
PROGRAM B
All help is appreciated. Thank you.Edited by: user13328581 on Mar 22, 2011 11:52 AMuser13328581 wrote:
WOW...THanks a lot Solomon, I have never used partitions and row_number in such a manner...can you please explain your logic.Sure:
row_number() over(partition by id order by place,program)This will take all rows returned by the query andsplit them into buckets (partitions) by id. Inside each bucket it will order rows by place and program and assign them row numbers. So for each ID row number 1 will be row with first (alphabetically) place first programt. And this is the row where we want ID to show up. That is why we wrap the above analytic function in CASE statement which will do exactly that. Now:
row_number() over(partition by id,place order by program)does pretty much the same just bucket is ID and PLACE combination. So for each such combination we want to show only for the first (alphabetically) programt.
Now notice in ORDER BY clause I prefix ID and PLACE with table alias. You must do it since otherwise query alias ID and PLACE will take precedence resulting in wrong sort order (remember we nulled all ID and PLACE except for row number 1).
SY. -
sample my table test:
create table test (
idsearch number,
idtest number,
p_nome varchar2(50),
p_value varchar2(50),
primary key(idsearch,idtest)
insert into test values(1,1,'name','alex');
insert into test values(1,2,'age','21');
insert into test values(1,3,'nick','alex');
select * from test;
return :
IDSEARCH IDTEST P_NOME P_VALUE
1 1 name alex
1 2 age 21
1 3 nick alex
how i return so ?
STRING
name=alex&age=21&nick=alex
thanksA summary of different string aggregation techniques can be found here
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php -
Search one column for value in another column
Hello,
I am trying to take the whole value from one column, and see if that string appears anywhere in another colmn. So if one row in one column has the value "cat", I want to see if that string appears anywhere in any row in another column: so a row with the value "The cat sat on the mat" would return true.
I have tried:
select term from pic_lib_keywords, csv
where contains (csv.nhm_field_asset_description,pic_lib_keywords.term) >0;
But I get the error:
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1, column 32
20000. 00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
*Action: Correct the problem as described in the error message or contact
the application administrator or DBA for more information.
Can you use 2 columns in this way, or does the search term have to be a literal? Any suggestions would be appreciated.
Thank you.It works for me, as shown below.
SCOTT@orcl_11gR2> select * from v$version
2 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
5 rows selected.
SCOTT@orcl_11gR2> create table csv
2 (nhm_field_asset_description clob)
3 /
Table created.
SCOTT@orcl_11gR2> insert all
2 into csv values ('The cat sat on the mat.')
3 into csv values ('The dog sat on the mat.')
4 select * from dual
5 /
2 rows created.
SCOTT@orcl_11gR2> create table pic_lib_keywords
2 (term varchar2(30))
3 /
Table created.
SCOTT@orcl_11gR2> insert all
2 into pic_lib_keywords values ('cat')
3 into pic_lib_keywords values ('mouse')
4 select * from dual
5 /
2 rows created.
SCOTT@orcl_11gR2> create index test_idx
2 on csv (nhm_field_asset_description)
3 indextype is ctxsys.context
4 /
Index created.
SCOTT@orcl_11gR2> select term
2 from pic_lib_keywords, csv
3 where contains
4 (csv.nhm_field_asset_description,
5 pic_lib_keywords.term) >0
6 /
TERM
cat
1 row selected.
SCOTT@orcl_11gR2> -
DataGrid alternating row colors per column
Is there a way to set different alternating colors to each
column in a DataGrid. I have a datagrid where I want two of the
columns to have different alternating row colors, one column (red
and light red) and the other (green and light green).
Many thanksYou can simply set the DataGridColumn property to the
approprate colors.
ex.
<mx:DataGrid y="0" x="0" width="100%">
<mx:columns>
<mx:DataGridColumn id="col1" backgroundColor="0x640000"
dataField="col1"/>
<mx:DataGridColumn id="col1" backgroundColor="0xFF0000"
dataField="col1"/>
<mx:DataGridColumn id="col1" backgroundColor="0x006600"
dataField="col1"/>
<mx:DataGridColumn id="col1" backgroundColor="0x33CC33"
dataField="col1"/>
</mx:columns>
</mx:DataGrid>
or you can use the setStyle:
col1.setStyle("backgroudColor", 0x640000) -
Dropdownbykey. data is missing in one column
Hi,
I am facing issue in dropdownbykey UI element.
When pushbutton is clicked, there is table showing up. but the first column in the table is missing. There is no value. This column values are expected to be like hyperlink so that when any one is clicked that is selected and the field is populated by this value.
I have found the dropdownbykey UI element on the view and trying to find the code for this UI element.
I dont know anything about the dropdownbykey ui element as i am new to web dynpro. I am reading the sap help material but its not addressing very basic understanding
Could you please help get answers to following
1) When we click pushbutton of dropdownbykey ui element we see a table from which we can click on one of the rows (only one column of the table is link which we can click) How are the columns in the table determined ?
2) Which key of the table is selectable ?
3) From where are the values of the table fetched ? u2013 backend. so obviously will have to pick data type linked to the ui element from some model rite ? it cant be string.
4) Why is there a value-set ? is it for the dropdown part of the ui element ? is it mandatory to code them as contants when we make a ui element dropdownbykey on our view or there is any other way of fetching this value-set data?
thank youHi Yogesh,
Its perfectly alright.
Could you please tell me what is SVS code ?
Is it so that by using this I will have all the methods needed for coding required for dropdownbykey ui element ?
I dont want to go by dropdownbyindex because I am not developing any application, there is this problem in an already developed application which I have to investigate
My above questions were based on understanding that when we include dropdownbykey ui element in our view , the dropdown list, pushbutton and screen with all values are inbuilt. This is written in the sap help on the link -
http://help.sap.com/saphelp_nw04/helpdata/en/5c/1b76bc3da0504e8b535cf3e154eaa7/frameset.htm
But now I have seen in my system that there is actually a separate view for displaying values is created for the pop up.
there is linktoaction ui element in the view where the dropownbykey is put and this linktoaction calls the view for displaying values.
I am now checking inside the code which passes data to this pop up view , why the first column in the table is missing.
thanks -
My Example :
Before:
Columns
name
address
jon DFG
has NULL
adil DER
After:
Column
Total
name : jon , address : DFG
name : has
name : adil , address : DERWhy not doing such reports on the client site?
create table #t (name varchar(10),address varchar(20))
insert into #t values ('jon','dfg'),('has',null),('adil','der')
select n,case when right(n,1)=':' then replace(n,'address:','') else n end
from
select concat('name:',name, ' address:',address ) n from #t
) as der
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How to get multiple records in one row and different column
Hi All,
I am using oracle database 11g
and i have a two tables table_1, table_2
table_1 having columns
emp_no
first_name
middle_name
last_name
email
and table_2 having columns
emp_no
phone_type
phone_number
and having entires
emp_no phone_type phone_number
1001 MOB 9451421452
1001 WEMG 235153654
1001 EMG 652341536
1002 MOB 9987526312
1003 WEMG 5332621456
1004 EMG 59612356
Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
emp_no first_name middle_name last_name email mobile officeno
1001 mark null k [email protected] 9451421452 235153654
1002 john cena gary [email protected] 9987526312 null
1003 dany null craig [email protected] null 5332621456
1004 donald finn sian [email protected] null null
can i have any inputs to achive this???
Regards
$sidFrank Kulash wrote:
sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
with table_1 as (
select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
select 1002,'john','cena','gary','[email protected]' from dual union all
select 1003,'dany',null,'craig','[email protected] null' from dual union all
select 1004,'donald','finn','sian','[email protected]' from dual
table_2 as (
select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
select 1001,'WEMG',235153654 from dual union all
select 1001,'EMG',652341536 from dual union all
select 1002,'MOB',9987526312 from dual union all
select 1003,'WEMG',5332621456 from dual union all
select 1004,'EMG',59612356 from dual
SELECT *
FROM table_1 t1
JOIN table_2 t2 ON t1.emp_no = t2.emp_no
PIVOT ( max(t2.phone_number)
FOR t2.phone_type IN ( 'MOB' AS mob
, 'WEMG' AS wemg
FOR t2.phone_type IN ( 'MOB' AS mob
ERROR at line 19:
ORA-01748: only simple column names allowed hereYou need to:
with table_1 as (
select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
select 1002,'john','cena','gary','[email protected]' from dual union all
select 1003,'dany',null,'craig','[email protected] null' from dual union all
select 1004,'donald','finn','sian','[email protected]' from dual
table_2 as (
select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
select 1001,'WEMG',235153654 from dual union all
select 1001,'EMG',652341536 from dual union all
select 1002,'MOB',9987526312 from dual union all
select 1003,'WEMG',5332621456 from dual union all
select 1004,'EMG',59612356 from dual
table_3 as (
select t1.emp_no,first_name,middle_name,last_name,email,
phone_type,phone_number
FROM table_1 t1
LEFT JOIN table_2 t2 ON t1.emp_no = t2.emp_no
SELECT *
FROM table_3
PIVOT ( max(phone_number)
FOR phone_type IN ( 'MOB' AS mob
, 'WEMG' AS wemg
EMP_NO FIRST_ MIDD LAST_ EMAIL MOB WEMG
1004 donald finn sian [email protected]
1003 dany craig [email protected] null 5332621456
1001 mark k [email protected] 9451421452 235153654
1002 john cena gary [email protected] 9987526312
SQL>SY.
Maybe you are looking for
-
How can i get my wife set up in iTunes - Same computer
Hi guys I'm trying to figure out the best way to get my wife set up using her own iTunes accounts. She has an iPhone and iPad but her laptop is pretty rubbish so i set up a user account on my MBA for her. I use iTunes match under my account, under he
-
I've watched several of the tutorials. I was able to upload a video yesterday to YouTube, but today, I made a new video, and after three tries, never could get it to upload. Kept getting an error asking if I wanted to TRY AGAIN. As I was editing
-
I need help updating my iphone. After I upgraded the software, it then told me to connect to itunes. I have updated my itunes, and then connected. then a box popped up saying my iphone is corrupted... what do i do now? i also deleted my iphone backup
-
How do i recompile whole system with glibc and gcc from test
I always run testing and hence upgraded all my system a couple of days back. How ever one pprogram i use very often, BLENDER isn't working after i upgraded glibc and gcc4. I have recompiled it but when I get all this errors when i start it http://bbs
-
Two seles price in one pricing procedure
Hi Gurus I have a program where I can create SO automatically and also can create SO in VA01 In case of automatic SO creation price should pick from file, if it is manual (VA01) price should pick from condition records(VK11) which should not be non