Concatenate various column values into one
How can I concatenate all values in a column to a single value for VARCHAR2 column datatype, with a delimeter between the values.
SET LINESIZE 1000
SET SERVEROUTPUT ON
DECLARE
v_name VARCHAR2 (1000) := NULL;
CURSOR cursor_name
IS
SELECT ename
FROM emp;
BEGIN
FOR c_rec IN cursor_name
LOOP
v_name := v_name | | ',' | | c_rec.ename;
END LOOP;
v_name := SUBSTR (v_name, 2)
DBMS_OUTPUT.PUT_LINE (v_name);
END;
null
Similar Messages
-
SELECT
CONTROLLER_MODEL_NUMBER_1,
SERIAL_NUMBER_1,
CONTROLLER_MODEL_NUMBER_2,
SERIAL_NUMBER_2,
CONTROLLER_MODEL_NUMBER_3,
SERIAL_NUMBER_3,
CONTROLLER_MODEL_NUMBER_4,
SERIAL_NUMBER_4,
CONTROLLER_MODEL_NUMBER_5,
SERIAL_NUMBER_5
FROM controller
I need to get above query as two columns as controller_model and serial_number all the controler_model_number_1 to 5 must come under controller_model similary serial_number as well
I am currently using union to get into one but this is affecting the performance please suggest me an alternative way
Thanks
SudhirHi,
Thank you so much this actually worked for me but only issue i found was not able add the cross join please check the below code
Select
distinct
'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
Null "Location_id",
Null "Product_id",
DECODE(rn,1,controller_model_number_1,
2,CONTROLLER_MODEL_NUMBER_2,
3,CONTROLLER_MODEL_NUMBER_3,
4,CONTROLLER_MODEL_NUMBER_4
) as CONTROLLER_MODEL_NUMBER
,DECODE(rn,1,TRIM (UPPER (serial_number_1)),
2,TRIM (UPPER (serial_number_2)),
3,TRIM (UPPER (serial_number_3)),
4,TRIM (UPPER (serial_number_4))
) AS SERIAL_NUMBER
From Edb_Assets C,
Edb_Accounts A,
(Select Rownum Rn From Dual Connect By Rownum <= 4)
where C.Amid = A.Amid(+)
AND (
( controller_model_number_1 != 'NULL'
AND Serial_Number_1 != 'NULL'
OR
( controller_model_number_2 != 'NULL'
AND Serial_Number_2 != 'NULL'
OR
( controller_model_number_3 != 'NULL'
AND Serial_Number_3 != 'NULL'
OR
( controller_model_number_4 != 'NULL'
AND Serial_Number_4 != 'NULL'
OR
( controller_model_number_5 != 'NULL'
AND Serial_Number_5 != 'NULL'
and c.sales_order_number = '1000179'
order by c.sales_order_number
The above query works perfect but one extra null row is getting populated because of not adding the cross join . Please help me in adding the cross join
Thanks
Sudhir -
Combine 2 specific column values into one column
Is there an easy solution to combine column values that is in a group?
In my report I have 1 column group named Activity_Area which has 5 different values Activity 1, Activity2...Activity5.
Let's say I want to merge Activity 4 and Activity 5 and call it ActivityX and gives me the output as below
Activity 1 | Activity 2 | Activity 3 | ActivityXHi Jhonny86,
According to your description, you create a field in database and it contains five values. Then you want to only display four values in report column group, and the last two values should be replaced by “ActivityX”, right?
In your scenario, you can create an table like below:
create table Act(id int,activity varchar(99))
insert into Act select 1,'Activity 1'
insert into Act select 2,'Activity 2'
insert into Act select 3,'Activity 3'
insert into Act select 4,'Activity 4'
insert into Act select 5,'Activity 5'
Then query the table with code like below in query designer, then add the field [Act] into the column group.
If you have any question, please feel free to ask.
Best regards,
Qiuyun Yu
Qiuyun Yu
TechNet Community Support -
How to store all the columns values into one single column
Hi All,
this is my file layout,i am receiving the data in below format only
emp_no,c1,c2,c3,c4,c5
100 ,1 ,0 ,1 ,0,1
200 ,1 ,0 ,1 ,0,1
300 ,1 ,0 ,1 ,0,1
but i want to store that above data into my table like(from c1 to c5 columns values i want to store in period column)
emp_no,period
100 ,1
100 ,0
100 ,1
100 ,0
100 ,1
200 ,1
200 ,0
200 ,1
200 ,0
200 ,1
300 ,1
300 ,0
300 ,1
300 ,0
300 ,1
please help meStrange but this is it
Processing ...
with original as (
select 100 as id ,1 as v1,0 as v2,1 as v3,0 as v4,1 as v5
from dual
union all
select 200 ,1 ,0 ,1 ,0,1
from dual
union all
select 300 ,1 ,0 ,1 ,0,1
from dual
select id,v1 as res_row
from original
union all
select id,v2
from original
union all
select id,v3
from original
union all
select id,v4
from original
union all
select id,v5
from original
ID RES_ROW
100 1
200 1
300 1
100 0
200 0
300 0
100 1
200 1
300 1
100 0
200 0
300 0
100 1
200 1
300 1
15 row(s) retrievedBye Alessandro -
Concatenate multiple row values into single column value
Hello,
Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
SELECT a.application_id, a.membership_number,
r.reason_text AS denial_reason,
a.appl_receipt_date AS application_receipt_date,
a.plan_request_1 AS application_plan_code,
a.adjudication_date AS application_denial_date
FROM application a, PLAN p, application_reason ar, reason r
WHERE a.plan_request_1 = p.plan_cd
AND a.application_id = ar.application_id
AND ar.reason_id = r.reason_id
AND a.adjudication_cd = 'D'
AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
AND p.plan_type_id = 12 and a.application_id = :appId
ORDER BY application_id
Any help is greatly appreciated.
Thanks,
-Christinefound the following
SELECT deptno,
LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM (SELECT deptno,
ename,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
FROM emp)
GROUP BY deptno
CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
START WITH curr = 1;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php -
Merging different values into one column
Hi all,
If my report has two columns A and B. For one value of A, there are multiple values coming from database for B.
So, report displays them like this:
A B
1 x
1 y
1 z
Is it possible somehow that i can merge all possible values of B in one row instead of many. i.e. report should look like this:
A B
1 x,y,z
Please reply with your suggestions.Hi,
It is possible that can merge all B column values in one row.
Steps:-
1. First you create an object for B using @aggregate_Aware() function like
@Aggregate_Aware(TableName.B,TableName.B)+', '
Object qualification should be measure. Here B is the column name.
2. In WebI report drag and drop A and B objects
3. Run the report
Now you will get the result.
Edited by: Swarna K on Mar 11, 2011 5:27 AM
Edited by: Swarna K on Mar 11, 2011 7:20 AM -
How to insert column values into database as rows
Hi,
I have 8 columns and some not null columns. Based on not null columns I want to insert into table as rows. The 8 columns may contain values or no value. If the first column contains data, then I have to insert into one row. if the second column contains data I have to insert a row and in second column. respectively...So How can I insert column values into rows. Can I write 8 insert statements. (OR) is it possible to insert data from columns using where clause.
Please help me out....
Thanks in AdvanceLines Table:
line_id, orcl_bank_account_num, product_type, service_type, lease_type,
funding_type, cpi, billing_frequency_unit_cd , annual_due_date ,
pricing_start_date, pricing_end_date, install_date, contract_end_date ,
prdct_replacement_cost_amt, cradle_replacement_amt, supranet_contract,
issuance_fee, board_inactive_date, header_id, creation_date, last_modified_date,
created_by_nam, modified_by_nam, activeinactive_flg, prdct_bill_amt_yr1,
prdct_bill_amt_yr2, prdct_bill_amt_yr3, prdct_bill_amt_yr4, prdct_bill_amt_yr5,
prdct_bill_amt_yr6, prdct_bill_amt_yr7, prdct_bill_amt_yr8, activation_fee_yr1,
activation_fee_yr2, activation_fee_yr3, activation_fee_yr4, activation_fee_yr5,
activation_fee_yr6, activation_fee_yr7, activation_fee_yr8,
In this table the columns structure is :
-- PRDCT_BILL_AMT_YR (1 to 8) NUMBER(14,4)
-- ACTIVATION_FEE_YR (1 to 8) NUMBER(8,2)
I have one more table:
PRDCT_INS_AMT NUMBER(14,4)
ACTIVATION_FEE_AMT NUMBER(14,4)
I want to insert prdct_bill_amt_yr (1 to 8) columns data into PRDCT_INS_AMT column. similarly activation_fee (1 to 8) columns data.
But the data should be inserted based product_type, service_type, lease_type columns values. (These 3 columns may contain upto 45 combinations). -
Problem in Showing multiple values into one text box.
Hi all,
How can show i multiple row values into one text box. here text box is multi line type.
i have one table it has content column, it has number of rows. i need to show those data into one text box in form. how can i solve it?
my sample code here,
egin
--:block3.txt_to := :parameter.p_current_user||''||':'||:block3.txt_From;
-- go_item('txt_from');
insert into chat(fromid,toid,content)values(:block3.fromid,:block3.toid,:block3.txt_From);
:block3.txt_From:= null;
commit;
:block3.txt_to := :parameter.p_current_user||''||':'||:block3.txt_From;
go_item('txt_from');
declare
cursor c4 is select content from chat where toid = :block3.fromid;
rec1 c4%rowtype;
begin
open c4;
loop
fetch c4 into rec1;
exit when c4%notfound;
null;
end loop;
end;
--select content into :block3.txt_to from chat where toid= :block3.fromid;
end;
please give me some tips to solve it.
thanks
gurusHi,
Try giving CHR(10) for line feed.
DECLARE
CURSOR C4 IS SELECT CONTENT FROM CHAT WHERE TOID = :BLOCK3.FROMID;
Str_Temp VARCHAR2(20);
BEGIN
:BLOCK3.TXT_TO := '';
OPEN C4;
LOOP
FETCH C4 INTO Str_Temp;
EXIT WHEN C4%NOTFOUND;
:BLOCK3.TXT_TO := :BLOCK3.TXT_TO || CHR(10) || Str_Temp;
END LOOP;
CLOSE C4;
END;Regards,
Manu.
If this answer is helpful or correct, please mark it. Thanks. -
Storing and retrieving multiple values into one cookie.
Hi Everyone,
I am wondering if anybody knows of any good tutorials involving storing multiple values into one cookie. Any URLs will be greatly apprecated. Thanks heaps.
Regards
DavoThese are normally delimted in HTTP by a semicolon. You can concatenate the string yourself and on the reverse trip use StringTokenizer to get the values back out.
- Saish -
Concatenate a column value across multiple rows - PDW
We are using PDW based on SQL2014. We require an efficient logic on how to concatenate a column value across multiple rows. We have the following table
T1
(CompanyID, StateCD)
Having following rows:
1 NY
1 NJ
1 CT
2 MA
2 NJ
2 VA
3 FL
3 CA
We need a code snippet which will return following result set:
1
CT,NJ,NY
2
MA,NJ,VA
3
CA,FL
We have tried built-in function STUFF with FOR XML PATH clause and it is not supported in PDW. So, we need a fast alternative.Hi Try this:
SELECT * INTO #ABC
FROM
SELECT 1 AS ID,'NY' AS NAME
UNION
SELECT 1 AS ID,'NJ' AS NAME
UNION
SELECT 1 AS ID,'CT' AS NAME
UNION
SELECT 2 AS ID,'MA' AS NAME
UNION
SELECT 2 AS ID,'NJ' AS NAME
UNION
SELECT 2 AS ID,'VA' AS NAME
UNION
SELECT 3 AS ID,'FL' AS NAME
UNION
SELECT 3 AS ID,'CA' AS NAME
)A
CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800))
DECLARE @TMP VARCHAR(MAX),
@V_MIN INT,
@V_MAX INT,
@V_COUNT INT
SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC
SET @V_COUNT=@V_MIN
WHILE @V_COUNT<=@V_MAX
BEGIN
SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC
WHERE ID=@V_COUNT
INSERT INTO ##CDB (ID, NAME) SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME
SET @V_COUNT=@V_COUNT+1
END
SELECT * FROM ##CDB
OR
SELECT * INTO #ABC
FROM
SELECT 1 AS ID,'NY' AS NAME
UNION
SELECT 1 AS ID,'NJ' AS NAME
UNION
SELECT 1 AS ID,'CT' AS NAME
UNION
SELECT 2 AS ID,'MA' AS NAME
UNION
SELECT 2 AS ID,'NJ' AS NAME
UNION
SELECT 2 AS ID,'VA' AS NAME
UNION
SELECT 3 AS ID,'FL' AS NAME
UNION
SELECT 3 AS ID,'CA' AS NAME
UNION
SELECT 5 AS ID,'LG' AS NAME
UNION
SELECT 5 AS ID,'AP' AS NAME
)A
CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800))
DECLARE @TMP VARCHAR(MAX),
@V_MIN INT,
@V_MAX INT,
@V_COUNT INT
SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC
SET @V_COUNT=@V_MIN
WHILE @V_COUNT<=@V_MAX
BEGIN
SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC
WHERE ID=@V_COUNT
SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME INTO #TEMP
INSERT INTO ##CDB (ID, NAME) SELECT ID, NAME FROM #TEMP WHERE NAME<>''
DROP TABLE #TEMP
SET @V_COUNT=@V_COUNT+1
END
SELECT * FROM ##CDB
Thanks Shiven:) If Answer is Helpful, Please Vote -
How to integrate existing value into one in hierarchy char.
I have a char. hierarchy call ZCOMP_CODE. ZLEADER is compounding with ZCOUNTRY.
The master data in ZCOMP_CODE looks like
ZLEADER;ZCOMP_CODE;
010;1000;
010;1001;
010;1002;
020;1000;
021;1000;
In query I have char. ZCOMP_CODE in row and one KF ZREVENUE in column. Previously we calculated ZLEADER 010,020,021 separately. But, now I want to calculated ZLEADER 020 and 021 together. Does anyone know how to integrate two existing value into one and display it in query? Do I need to create a new hierarchy node for including 020,021?
Thanks!
rajatina.don't know how you can achieve this in the query...
but in the workbench there's a solution. Just add a routine in the transformation to change 021 to 020.
if you need to have still the 021 info somewhere, create a ZCOMPANY_CODE2 where you store only the values needed (010, 020)... use this company code as hierarchy in the report, and use the other company code for displaying the 021...
hope it's clear,
M. -
Concacenate Many Columns text into one Column
Hi,
I have many columns with text in it. I would like to ideally concatenate these column content into just ONE column.
Please help work out how to do this as I have no idea.
I am somewhat familiar with CMD so if you can help with this urgently that would be SO awesome.
Thanks
:)890635 wrote:
Thanks again...
So I want to display this data eventually on forms. So I think I do need to create a blank column.
so let's say I want the concatenated data to end up in "Final_Delivery".
How to do that?
Thank youI dont have any idea about Forms...But just a guess that for form as well you must be writing some SQL, and you can use the sql there directly. Otherwise if you want to get it inserted into new column in existing table....First you have to add a new column to your table and then run update Statement to populate that data..similar to this
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO TEST INFO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO TEST INFO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> update emp set info=to_char(empno)||' '||ename||' '||job;
14 rows updated.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO TEST INFO
7369 SMITH CLERK 7902 17-DEC-80 800 20 7369 SMITH CLERK
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7499 ALLEN SALESMAN
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7521 WARD SALESMAN
7566 JONES MANAGER 7839 02-APR-81 2975 20 7566 JONES MANAGER
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7654 MARTIN SALESMAN
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7698 BLAKE MANAGER
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7782 CLARK MANAGER
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7788 SCOTT ANALYST
7839 KING PRESIDENT 17-NOV-81 5000 10 7839 KING PRESIDENT
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7844 TURNER SALESMAN
7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7876 ADAMS CLERK
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO TEST INFO
7900 JAMES CLERK 7698 03-DEC-81 950 30 7900 JAMES CLERK
7902 FORD ANALYST 7566 03-DEC-81 3000 20 7902 FORD ANALYST
7934 MILLER CLERK 7782 23-JAN-82 1300 10 7934 MILLER CLERK
14 rows selected.
SQL>Regards,
Navneet -
How to import column values into SharePoint 2013 Term Store Using Powershell(CSOM)
Hi,
I do have SharePoint 2013 list with more than 500 items in it.Now I am trying to import column values into SharePoint 2013 Term Set A using Powershell scripts.
I am new to Powershell(csom) and can anybody help me out to accomplish this task?
Any help would be greately appreciated.
Thank you,
AA.
AA.Hi
check this doc
http://wellytonian.com/2012/10/sharepoint-2010-2013-term-store-importer-using-csv/
Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you. -
Concatenate multiple pdf files into one single postscript file
Hi,
Could anyone help me with a code to "Concatenate Multiple pdf files into one single postscript file" ?
Thanks for the helpThanks for your reply! Actually the main purpose is to allow user to select multiple pdf documents on a single web page and then he should be able to print all of them at once by hitting the print button on the web page instead of selecting each document seperately to print it. Also he should be able to see all the printing services available to print those documents.
Thanks, -
Sql loader - mutiple values into one column
Hi,
Is it possible to load multiple fields into one column. Eg, my table structure has two columns COL1, COL2 and my data file is comma delimted with 3 fields A,B,C.
How could i use sql loader to achieve (without the use of temp tables)
COL1 = A
COL2 = BC
ThanksI don't understand why you can't modify the input fille.
But anyway, i have 2 ways to help you
1. Make new inputfile online using pipe and awk(or something your are familiar with) and use it as new input file.
This is a traditional and powerful method in Unix environment.
For instance:
oracle> $ mknod pipe.dat p
oracle> cat input.dat | awk '{print ...}' > pipe.dat &
oracle> sqlldr ctl=.. data=pipe.dat
Using this method, you don't need to modify original input file physically, but by some magical trick you can modify it on the fly.
2. Use before trigger
For instance:
create table load(a int, b int, c int, d int);
create or replace trigger load_trigger
before insert on load
for each row
begin
:new.d := :new.b + :new.c;
:new.b := null;
:new.c := null;
end;
load data
infile *
append
into table load
fields terminated by "," optionally enclosed by '"'
(a, b, c)
begindata
1, 1, 1
2, 2, 2
3, 3, 3
4, 4, 4
sqlldr userid=... ctl=load.ctl
SQL> select * from load;
A B C D
1 2
2 4
3 6
4 8
You won't like the existence of unnecessary columns(B, C) but don't have choice. ^^;
I think there is another simple way provided by SQL*Loader. But i've never tried it myself. Read following doc and try it yourself:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1008153
Maybe you are looking for
-
Applications there but not there
Small problem. Just bought a new iMac. Copied my iTunes library in totality from my work MacBook Pro onto the new machine. Plugged my iPhone in to sync. Everything works fine - it asked me to authorise new computer with my iTunes store account. Then
-
Acrobat Pro 8.0 Windows - No Disk Using Organizer
I am running 2 desktop systems a GTW 840GM with XP Pro SP2 and a HP a6245n with Vista SP1, both have drive bay mounted Multimedia Card Readers with 4 devices. I store my PDFs on CF and SD cards. GTW 840GM( base load with system drivers and Acrobat Pr
-
Audio problems - can anyone help?
(continuation of a previous thread in which people were very helpful) background: installed a bluetooth headset. suddenly video files would play but audio only through the headset, if the headset wasnt connected i'd get "LUETOOTH AUDIO FAILED. THERE
-
When I try to extend network, doesn't find my network
Hi, My Airport Extreme is connected to my modem via ethernet. When I use the Airport utility and try to extend my network, it only gives me the option to extend a different network - I'm assuming a wireless one in my neighborhood - but does not give
-
CD --previous sessions invisible
We've been using a CD to transfer files between computers, both Macs and PC's. This CD had files burned with Windows XP. I added a file using Toast 7 on my iMac G5, recently updated to 10.4.6 with Software Update. After that the previous files were i