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
Similar Messages
-
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 -
Reg : Concatenation of a column value with multiple rows... URGENT
Hello,
Could any of u help me in concatenating a column value with
multiple rows ???
For ex : I've the following data from emp table :
DEPTNO ENAME
10 KING'S
30 BLAKE
10 CLARK
10 TOM JONES
30 ALLEN
30 JAMES
20 SMITH
20 SCOTT
20 MILLER
10 MILLER
20 rajeev
I want the following output :
deptno Concat_value
10 KING'S,CLARK,TOM JONES,MILLER
20 Rajeev,MILLER,SMITH,SCOTT
30 BLAKE,ALLEN,JAMES
Thanks in Advance,
SriniHello Naveen,
Thanks for ur answer. But I need a single SQL query for getting
what I want. I know the solution in PL/SQL.
Please try it in a single SQL....
Thanks again,
Srini -
How to convert colon separated column values in multiple rows in report
Hi All,
I want to display colon separated values from a column, in a multi row in report.
For example i have a column1 in a table with value 'A:B:C' , column2 has value '1'.
i want to show in a report three rows using these two columns like
column1 column2
A 1
B 1
C 1Here's one way:
SQL> create table test (col1 varchar2(20), col2 number);
Table created.
SQL> insert all
2 into test values ('A:B:C', 1)
3 into test values ('Dg:Ezs', 2)
4 select * from dual;
2 rows created.
SQL> select
2 t.col2,
3 regexp_substr(t.col1, '\w+', 1, t2.column_value) c1
4 from test t,
5 table(cast(multiset(select level
6 from dual
7 connect by level <= length(t.col1) - length(replace(t.col1, ':', '')) + 1
8 ) as sys.odcinumberlist )) t2
9 order by 2, 1;
COL2 C1
1 A
1 B
1 C
2 Dg
2 Ezs
SQL>Edited by: Littlefoot on Jan 31, 2012 10:13 AM -
Finding the minimum value across multiple rows (not in a single column)
Hello,
I am running some ad-hoc SQL to test a website implementation of a spec. The ad-hoc sql gives me a set of date values for a specific widget (called a Task). I need to find the Minimum of either (Task.EndDate + 1 year) or the MAX date from the list
of other dates. I can easily get all of these dates, and compare them visually, but I'm not sure how to make SQL give me just the single value that I want. In the image below, you can see the results. The blue cell is the value I should get if I were to retrieve
a single value.
select
[EndDate+12Mo] = DATEADD(year,1,t.EndDate)
, [TaskEdit] = t.EditTS
, [ResearchEdit] = (select x.editts from Research x where t.researchid = x.researchid)
, [DeliverableEdit] = (select max(x.EditTS) from Deliverable x where t.taskid = x.taskid)
, [RTPEdit] = (select max(x.EditTS) from ResTaskParticipant x where (t.taskid = x.taskid and t.researchid = x.researchid) or (t.researchid = x.researchid and x.TaskID is null) )
, [RelatedTaskEdit] = (select max(x.EditTS) from Task_Related x where t.taskid = x.Task1ID or t.TaskID = x.Task2ID)
, [CrosscutEdit] = (select max(x.EditTS) from Task_Crosscut x where t.taskid = x.taskid)
, [TaskFundingEdit]= (select max(x.EditTS) from TaskFunding x where t.taskID = x.taskID)
, [ContractFundingEdit]= (select max(x.EditTS) from TaskFunding x inner join ContractFunding y on x.ContractFundingID = y.ContractFundingID where t.taskID = x.taskID)
from task t
where
t.tasknumber =
'2123.001'
Thanks!
JenniferSounds like this to me
select CASE WHEN [EndDate+12Mo] < MAX(dt) THEN [EndDate+12Mo] ELSE MAX(dt) END AS YourDateValue
from
SELECT [EndDate+12Mo],dt
from
select
[EndDate+12Mo] = DATEADD(year,1,t.EndDate)
, [TaskEdit] = t.EditTS
, [ResearchEdit] = (select x.editts from Research x where t.researchid = x.researchid)
, [DeliverableEdit] = (select max(x.EditTS) from Deliverable x where t.taskid = x.taskid)
, [RTPEdit] = (select max(x.EditTS) from ResTaskParticipant x where (t.taskid = x.taskid and t.researchid = x.researchid) or (t.researchid = x.researchid and x.TaskID is null) )
, [RelatedTaskEdit] = (select max(x.EditTS) from Task_Related x where t.taskid = x.Task1ID or t.TaskID = x.Task2ID)
, [CrosscutEdit] = (select max(x.EditTS) from Task_Crosscut x where t.taskid = x.taskid)
, [TaskFundingEdit]= (select max(x.EditTS) from TaskFunding x where t.taskID = x.taskID)
, [ContractFundingEdit]= (select max(x.EditTS) from TaskFunding x inner JOINContractFunding y on x.ContractFundingID = y.ContractFundingID where t.taskID = x.taskID)
from task t
where
t.tasknumber =
'2123.001'
)t1
UNPIVOT(dt FOR cat IN ([TaskEdit]
, [ResearchEdit]
, [DeliverableEdit]
, [RTPEdit]
, [RelatedTaskEdit]
, [CrosscutEdit]
, [TaskFundingEdit]
, [ContractFundingEdit]))u
)r
GROUP BY [EndDate+12Mo]
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Please - immediate help needed parsing csv values into multiple rows
Hello, we have a very immediate need to be able to parse out a field of comma separated values into individual rows. The following is an example written in SQL Server syntax which does not work in Oracle.
The tricky part is that each ROUTES can be a different length, and each CSV can have a different number of routes in it.
Here is an example of the table ("Quotes") of CSV values I want to normalize:
TPNUMBER ROUTES
1001 1, 56W, 18
1002 2, 16, 186, 28
Here is an example of what I need it to look like:
TPNUMBER ROUTES
1001 1
1001 56W
1001 18
1002 2
1002 16
1002 186
1002 28
Here is the "Tally" table for the query below:
ID
1
2
3
4
5
6
7
And finally, here is the query which parses CSV values into multiple rows but which does not work in Oralce:
SELECT TPNUMBER,
NullIf(SubString(',' + ROUTES + ',' , ID , CharIndex(',' , ',' + ROUTES + ',' , ID) - ID) , '') AS ONEROUTE
FROM Tally, Quotes
WHERE ID <= Len(',' + ROUTES + ',') AND SubString(',' + Phrase + ',' , ID - 1, 1) = ','
AND CharIndex(',' , ',' + ROUTES + ',' , ID) - ID > 0
It may be necessary to use a cursor to loop through the CSV table and process each row (a loop within another loop...) but this is beyond my comprehesion of PL/SQL.
Many thanks in advance for your advice/help.
apkNot sure what you are trying to do with the last step, but this should work for the first part. I assume you would use sqlldr but I just did inserts instead. You might need more than 5 "routes" in the csv. You could put some reasonable max on that number of columns:
SQL>create table t_csv
2 (TPNUMBER varchar2(20),
3 ROUTE_1 VARCHAR2(5),
4 ROUTE_2 VARCHAR2(5),
5 ROUTE_3 VARCHAR2(5),
6 ROUTE_4 VARCHAR2(5),
7 ROUTE_5 VARCHAR2(5),
8 ROUTE_6 VARCHAR2(5) );
Table created.
SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2) values( '1001 1', '56W', '18' );
1 row created.
SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2,ROUTE_3) values( '1002 2', '16', '186', '28');
1 row created.
SQL>create table t_quotes(
2 tpnumber NUMBER,
3 routes VARCHAR2(5));
Table created.
SQL>DECLARE
2 L_tpnumber NUMBER;
3 L_route VARCHAR2(5);
4 begin
5 for rec in (select * from t_csv) loop
6 L_tpnumber := SUBSTR(rec.tpnumber,1,INSTR(rec.tpnumber,' ')-1);
7 L_route := SUBSTR(rec.tpnumber,INSTR(rec.tpnumber,' ')+1);
8 insert into t_quotes values( L_tpnumber, l_route );
9 if rec.route_1 is not null then
10 insert into t_quotes values( L_tpnumber, rec.route_1 );
11 end if;
12 if rec.route_2 is not null then
13 insert into t_quotes values( L_tpnumber, rec.route_2 );
14 end if;
15 if rec.route_3 is not null then
16 insert into t_quotes values( L_tpnumber, rec.route_3 );
17 end if;
18 if rec.route_4 is not null then
19 insert into t_quotes values( L_tpnumber, rec.route_4 );
20 end if;
21 if rec.route_5 is not null then
22 insert into t_quotes values( L_tpnumber, rec.route_5 );
23 end if;
24 end loop;
25 end;
26 /
PL/SQL procedure successfully completed.
SQL> select tpnumber, routes from t_quotes;
TPNUMBER ROUTE
1001 1
1001 56W
1001 18
1002 2
1002 16
1002 186
1002 28
7 rows selected. -
Oracle SP for comparing 80 column values across 8 table pairs in 2 diff DBs
Hi All,
I have an Oracle SP for comparing 80 column values across 8 table pairs in 2 diff DBs.
However, it is taking hell lot of time around 6hours to process 10,000 records.
Can anyone suggest how to fine-tune this?
Thanks guys.Tables prefixed with X are the temp tables to store data of DB-A.
The report will be originally based on DB-B, so DB Links will not be required for @PROD1.WORLD tables.
This is a test region, so I have pointed to @PROD1.WORLD to test with Prod Data.
SEC_COMPARE_CONFIG is the config table containing the table_name to be reported, corresponding temp tables to store the data and the columns on which it is to be reported.
There are in total 8 tables- 90 rows and 8 temp tables.
SPOKE_TO_HUB_SEC_MTCH_TBL records the securities on which it is to be reported.
HIST_DATA_COMPARE_TBL is the final results table.
Here is the entire code:
CREATE OR REPLACE PACKAGE SECURITY_COMPARE AS
PROCEDURE PROCESS_RECORDS (IN_EFFECTIVE_DATE IN DATE,
IN_PRIMARY_ASSET_ID IN VARCHAR2 DEFAULT NULL);
PROCEDURE IDENTIFY_SECURITIES ( P_EFFECTIVE_DATE IN DATE,
P_PRIMARY_ASSET_ID IN VARCHAR2 DEFAULT NULL);
PROCEDURE RETREIVE_RECORDS_FROM_SPOKE;
PROCEDURE COMPARE_RECORDS(p_err_msg OUT VARCHAR2);
PROCEDURE INSERT_DATA_TO_TABLE ( v_target_table VARCHAR2, v_sql_to_run VARCHAR2, v_commit_after NUMBER);
END SECURITY_COMPARE;
CREATE OR REPLACE PACKAGE BODY SECURITY_COMPARE AS
/*Declared String for recording Dynamic SQL's*/
LC_SQL VARCHAR2 (20000);
PROCEDURE PROCESS_RECORDS(IN_EFFECTIVE_DATE IN DATE,
IN_PRIMARY_ASSET_ID IN VARCHAR2 DEFAULT NULL)
AS
L_EFF_DATE DATE;
L_PRIMARY_ASSET_ID VARCHAR2(100);
k_err_msg VARCHAR2(100); --Error message displayed in case of NO discretionary records found.
BEGIN
L_EFF_DATE := IN_EFFECTIVE_DATE;
L_PRIMARY_ASSET_ID := IN_PRIMARY_ASSET_ID;
IDENTIFY_SECURITIES(L_EFF_DATE,L_PRIMARY_ASSET_ID); --Calling the Identify_Securities procedure to identify the securities older by 90 days from report effective date
RETREIVE_RECORDS_FROM_SPOKE(); --Retreiving the historic records from the security tables into temporary tables.
COMPARE_RECORDS(p_err_msg=>k_err_msg); --Compare the records and report the discrepencies into HIST_DATA_COMPARE_TBL table
END PROCESS_RECORDS;
PROCEDURE IDENTIFY_SECURITIES(P_EFFECTIVE_DATE IN DATE,
P_PRIMARY_ASSET_ID IN VARCHAR2 DEFAULT NULL)
AS
P_EFF_DATE DATE; --Effective Date of the report
P_PRIMARY_ID VARCHAR2(100); --Primary AssetID which is used to search based on specific security
v_target_table VARCHAR2(500); --Variable indicating the Target table for inserting the data
v_sql_to_run VARCHAR2(5000); --Variable to store the Dynamic SQL to be executed
v_commit_after NUMBER; --Variable to define after how many records is COMMIT to be done
BEGIN
LC_SQL :='';
P_EFF_DATE := P_EFFECTIVE_DATE;
P_PRIMARY_ID := P_PRIMARY_ASSET_ID;
/*Deleting Old Entries from SPOKE_TO_HUB_SEC_MTCH_TBL table*/
LC_SQL := 'TRUNCATE TABLE SPOKE_TO_HUB_SEC_MTCH_TBL';
EXECUTE IMMEDIATE LC_SQL;
IF(P_PRIMARY_ID is NULL) --In case records do not need to be identified on basis of specific security
THEN
/*Identify Securities older by 90days from report effective date*/
v_target_table := ' SPOKE_TO_HUB_SEC_MTCH_TBL';
v_sql_to_run := 'WITH T AS ('||
' SELECT R.PRIMARY_ASSET_ID PRIMARY_ASSET_ID_R,'||
' R.SECURITY_ALIAS SECURITY_ALIAS_R,'||
' R.LAST_HELD_DATE LAST_HELD_DATE_R,'||
' R.PREV_HELD_DATE PREV_HELD_DATE_R,'||
' Q.PRIMARY_ASSET_ID PRIMARY_ASSET_ID_Q,'||
' Q.SECURITY_ALIAS SECURITY_ALIAS_Q,'||
' COUNT(*) OVER(PARTITION BY Q.PRIMARY_ASSET_ID) CNT'||
' FROM [email protected] R,'||
' [email protected] Q'||
' WHERE SYS_OP_MAP_NONNULL(R.last_held_date) <> '||q'!'FF'!'||
' and ceil(R.last_held_date-to_date('||''''||P_EFF_DATE||''''||')) >= 0'||
' and ceil(R.last_held_date-to_date('||''''||P_EFF_DATE||''''||')) <= 60'||
' and R.PRIMARY_ASSET_ID=Q.PRIMARY_ASSET_ID'||
' )'||
' SELECT PRIMARY_ASSET_ID_R,'||
' SECURITY_ALIAS_R,'||
' LAST_HELD_DATE_R,'||
' PREV_HELD_DATE_R,'||
' PRIMARY_ASSET_ID_Q,'||
' SECURITY_ALIAS_Q'||
' FROM T'||
' WHERE CNT =1';
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
ELSE
v_target_table := ' SPOKE_TO_HUB_SEC_MTCH_TBL';
v_sql_to_run := 'WITH T AS ('||
' SELECT R.PRIMARY_ASSET_ID PRIMARY_ASSET_ID_R,'||
' R.SECURITY_ALIAS SECURITY_ALIAS_R,'||
' R.LAST_HELD_DATE LAST_HELD_DATE_R,'||
' R.PREV_HELD_DATE PREV_HELD_DATE_R,'||
' Q.PRIMARY_ASSET_ID PRIMARY_ASSET_ID_Q,'||
' Q.SECURITY_ALIAS SECURITY_ALIAS_Q,'||
' COUNT(*) OVER(PARTITION BY Q.PRIMARY_ASSET_ID) CNT'||
' FROM [email protected] R,'||
' [email protected] Q'||
' where R.PRIMARY_ASSET_ID='||''''||P_PRIMARY_ID||''''||
' and R.PRIMARY_ASSET_ID=Q.PRIMARY_ASSET_ID'||
' )'||
' SELECT PRIMARY_ASSET_ID_R,'||
' SECURITY_ALIAS_R,'||
' LAST_HELD_DATE_R,'||
' PREV_HELD_DATE_R,'||
' PRIMARY_ASSET_ID_Q,'||
' SECURITY_ALIAS_Q'||
' FROM T'||
' WHERE CNT =1';
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
END IF;
LC_SQL := 'TRUNCATE TABLE HIST_DATA_COMPARE_TBL';
EXECUTE IMMEDIATE LC_SQL;
END IDENTIFY_SECURITIES;
PROCEDURE RETREIVE_RECORDS_FROM_SPOKE
AS
v_target_table VARCHAR2(500);
v_sql_to_run VARCHAR2(5000);
v_commit_after NUMBER;
BEGIN
LC_SQL :='';
LC_SQL:= 'TRUNCATE TABLE X_SECMASTER_HISTORY_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_SEC_MASTER_DTL_HIST_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_SECMASTER_DTL_EXT_HST_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_EQUITY_HIST_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_EQUITY_DETAIL_HIST_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_FIXED_INCOME_HIST_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_FIXED_INCOME_DTL_EXT_TBL';
EXECUTE IMMEDIATE LC_SQL;
LC_SQL:= 'TRUNCATE TABLE X_DERIVATIVES_HIST_TBL';
EXECUTE IMMEDIATE LC_SQL;
/*SECMASTER_HISTORY*/
v_target_table := 'X_SECMASTER_HISTORY_TBL';
v_sql_to_run := ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*SECURITY_MASTER_DETAIL_HIST*/
v_target_table := 'X_SEC_MASTER_DTL_HIST_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*SECMASTER_DETAIL_EXT_HIST*/
v_target_table := 'X_SECMASTER_DTL_EXT_HST_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*EQUITY_HIST*/
v_target_table := 'X_EQUITY_HIST_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*EQUITY_DETAIL_HIST*/
v_target_table := 'X_EQUITY_DETAIL_HIST_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*FIXED_INCOME_HIST*/
v_target_table := 'X_FIXED_INCOME_HIST_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*FIXED_INCOME_DETAIL_EXT_HIST*/
v_target_table := 'X_FIXED_INCOME_DTL_EXT_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
/*DERIVATIVES_HIST*/
v_target_table := 'X_DERIVATIVES_HIST_TBL';
v_sql_to_run:= ' SELECT /*+DRIVING_SITE(K)*/ K.* FROM [email protected] K '||
' INNER JOIN SPOKE_TO_HUB_SEC_MTCH_TBL I'||
' ON K.SECURITY_ALIAS = I.SPOKE_SEC'||
' AND K.SRC_INTFC_INST = 140 '||
' and K.EFFECTIVE_DATE =(SELECT /*+DRIVING_SITE(H)*/ MAX (H.EFFECTIVE_DATE) FROM [email protected] H WHERE'||
' H.SECURITY_ALIAS = K.SECURITY_ALIAS AND H.SRC_INTFC_INST = K.SRC_INTFC_INST)' ;
v_commit_after := 0;
INSERT_DATA_TO_TABLE(v_target_table,v_sql_to_run,v_commit_after);
END RETREIVE_RECORDS_FROM_SPOKE;
PROCEDURE COMPARE_RECORDS(p_err_msg OUT VARCHAR2)
AS
l_count NUMBER;
l_err_msg VARCHAR2(100);
TYPE T_SECURITIES is TABLE of HIST_DATA_COMPARE_TBL%rowtype;
ttype T_SECURITIES;
CURSOR C1
IS
SELECT TABLE_NAME, TEMP_TABLE, COLUMN_NAME from SEC_COMPARE_CONFIG
where column_name='EFFECTIVE_DATE';
CURSOR C2
IS
SELECT * FROM SEC_COMPARE_CONFIG where id <=82;
C_REC SEC_COMPARE_CONFIG%rowtype;
BEGIN
LC_SQL :='';
p_err_msg :='';
FOR C_REC in C1
loop
LC_SQL:= ' SELECT /*+DRIVING_SITE(B)*/ /*+PARALLEL(A,100)*/ B.SECURITY_ALIAS, to_char(C.SPOKE_PAID), A.SECURITY_ALIAS,to_char(C.HUB_PAID),'||''''||C_REC.TABLE_NAME||''''||','||q'!'EFFECTIVE_DATE'!'||','||
' NVL((cast(B.'||C_REC.COLUMN_NAME||' as VARCHAR2(100))),'||q'!'No Records Found'!'||'),'||
' NVL((cast(A.'||C_REC.COLUMN_NAME||' as VARCHAR2(100))),'||q'!'No Records Found'!'||')'||
' FROM '||C_REC.TEMP_TABLE||' A, SECURITYDBO.'||C_REC.TABLE_NAME ||'@PROD1.WORLD B,'||
' SPOKE_TO_HUB_SEC_MTCH_TBL C'||
' WHERE A.SRC_INTFC_INST=140'||
' AND B.SRC_INTFC_INST=140'||
' AND A.SECURITY_ALIAS=C.spoke_sec'||
' and b.security_alias=C.HUB_SEC'||
' AND a.effective_date <> (select max(h.effective_date) from SECURITYDBO.'||C_REC.TABLE_NAME||'@PROD1.WORLD H'||
' where h.security_alias=c.hub_sec and h.src_intfc_inst=140 )';
EXECUTE IMMEDIATE LC_SQL BULK COLLECT into ttype;
FORALL x in ttype.First..ttype.Last
insert into HIST_DATA_COMPARE_TBL values ttype(x);
commit;
end loop;
For C_REC in C2
loop
LC_SQL:= ' SELECT /*+DRIVING_SITE(B)*/ /*+PARALLEL(A,100)*/ B.SECURITY_ALIAS, to_char(C.SPOKE_PAID), A.SECURITY_ALIAS,to_char(C.HUB_PAID),'||''''||C_REC.TABLE_NAME||''''||','||''''||C_REC.COLUMN_NAME||''''||','||
' NVL((cast(B.'||C_REC.COLUMN_NAME||' as VARCHAR2(100))),'||q'!'No Records Found'!'||'),'||
' NVL((cast(A.'||C_REC.COLUMN_NAME||' as VARCHAR2(100))),'||q'!'No Records Found'!'||')'||
' FROM '||C_REC.TEMP_TABLE||' A, SECURITYDBO.'||C_REC.TABLE_NAME ||'@PROD1.WORLD B,'||
' SPOKE_TO_HUB_SEC_MTCH_TBL C'||
' WHERE A.SRC_INTFC_INST=140'||
' AND B.SRC_INTFC_INST=140'||
' AND A.SECURITY_ALIAS=C.spoke_sec'||
' and b.security_alias=C.HUB_SEC'||
' and b.effective_date=a.effective_date'||
' AND NVL((cast(A.'||C_REC.column_name||' as VARCHAR2(100))),'||q'!'No Records Found'!'||') <>'||
' NVL((cast(B.'||C_REC.column_name||' as VARCHAR2(100))),'||q'!'No Records Found'!'||')';
EXECUTE IMMEDIATE LC_SQL BULK COLLECT into ttype;
FORALL x in ttype.First..ttype.Last
insert into HIST_DATA_COMPARE_TBL values ttype(x);
commit;
end loop;
BEGIN
select count(*) into l_count from HIST_DATA_COMPARE_TBL;
if(l_count=0) then
l_err_msg :='No records found';
end if;
END;
END COMPARE_RECORDS;
NAME: INSERT_DATA_TO_TABLE
DESCRIPTION: This procedure will insert the records into the target table based based on the data fetched using the sql to run variable.
It also records the commit_after variable which defines that after how many records the insert needs to be committed.
PROCEDURE INSERT_DATA_TO_TABLE ( v_target_table VARCHAR2,
v_sql_to_run VARCHAR2,
v_commit_after NUMBER) IS
v_limit_sql1 VARCHAR2(300) := ' ';
v_limit_sql2 VARCHAR2(900) := ' ';
v_plsql_to_run VARCHAR2(32767);
BEGIN
IF NVL(v_commit_after,0) <> 0 THEN
v_limit_sql1:= ' LIMIT ' || TO_CHAR(v_commit_after) ;
v_limit_sql2:= ' IF MOD(v_number_of_rows, ' || TO_CHAR(v_commit_after) || ' ) = 0 THEN ' ||
' COMMIT; ' ||
' END IF; ' ;
END IF;
v_plsql_to_run:= ' ' ||
'DECLARE ' ||
' v_number_of_rows number:=0; ' ||
' ' ||
' TYPE MyType IS REF CURSOR; ' ||
' CV MyType; ' ||
' TYPE RecTyp IS TABLE OF ' || v_target_table || '%ROWTYPE; ' ||
' rec RecTyp; ' ||
' ' ||
'BEGIN ' ||
' ' ||
'OPEN CV FOR ' ||
' ' || REPLACE( v_sql_to_run, ';', ' ' ) || ' ; ' ||
' LOOP ' ||
' FETCH CV BULK COLLECT INTO rec ' || v_limit_sql1 || '; ' ||
' FORALL i IN 1..rec.COUNT ' ||
' INSERT /*+ APPEND */ INTO ' || v_target_table || ' VALUES rec(i); ' ||
' v_number_of_rows := v_number_of_rows + SQL%ROWCOUNT; ' ||
' ' || v_limit_sql2 || ' ' ||
' EXIT WHEN CV%NOTFOUND; ' ||
' ' ||
' END LOOP; ' ||
' COMMIT; ' ||
' CLOSE CV; ' ||
'END; ';
EXECUTE IMMEDIATE v_plsql_to_run;
COMMIT;
END INSERT_DATA_TO_TABLE;
END SECURITY_COMPARE; -
Interactive report – column heading in multiple rows
I am using interactive report. My question to the expert/guru’s is: - How do I change column heading into multiple row with text wrap.
For example:- My column heading is
Is Employee Trained ? -------> (single row display)
I want to make it display like
Is Employee
Trained ? ------> (Multi row display)
SagarHi,
What you could do is, disable the download csv function from IR (Interactive Report Attributes--> Search Bar-- Uncheck Download) and in the region header create a link and redirect it to another page which will have the csv report output.
e.g. <a href="#" onclick="javascript:redirect('f?p=&APP_ID.:3:&SESSION.::&DEBUG.:3::');"" >Download Report </a>
Here I am redirecting the link to Page 3. On Page 3 create a sql report with the same query and make report template to csv. Thanks,
Manish -
Is it possible to Lock just one column value in a row?
Is it possible to Lock just one column value in a row
A Java Developer has just asked me if it is possible to Lock just one column value in a row in Oracle
select ename from emp where empno=7369 for update;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
will lock the entire row with empno=7369.
But is it possible to lock one column value from this row, like SAL=800 ?
Edited by: J.Kiechle on Jan 8, 2009 10:45 PMJ.Kiechle wrote:
Is it possible to Lock just one column value in a rowNo. Locking granularity is a row. -
Splitting comma seperated column data into multiple rows
Hi Gurus,
Please help me for solving below scenario. I have multiple value in single column with comma seperated values and my requirement is load that data into multiple rows.
Below is the example:
Source Data:
Product Size Stock
ABC X,XL,XXL,M,L,S 1,2,3,4,5,6
Target Data:
Product Size Stock
ABC X 1
ABC XL 2
ABC XXL 3
ABC M 4
ABC L 5
ABC S 6
Which transformation we need to use for getting this output?
Thanks in advance !Hello,
Do you need to do this tranformation through OWB mapping only? And can you please tell what type of source you are using? Is it a flat file or a table?
Thanks -
Drill Down between 2 stacked column chart with multiple rows.
Hi,
Can anyone please help me.
1) i have to create stacked column chart with Region and cout of calls for previous 3 quarters.
2) the 2nd stacked column should display the priority with the count of calls for the respective selection of region on the 1st chart..
to achieve this,
i'm using 2 stacked column charts and 1 lebel baseb menu.
from this i can able to get the drill down from label based menu to 2nd stacked column chart but i couldn't able to done the same from 1st stacked coumn chart.
Becoz my data is multiple row for each quarter.
please suggest me to achieve the drill down between 2 stacked column charts.
assume that my data like below.:
coulmns for 1st stacked column chart : Region, Q2,Q3 &Q4
Region Q2 Q3 Q4
Other 3658 3497 497
NA - North
America 3 3 1101
APJK 1 4 597
UK 324
EMEA North 1 1 288
CORPORATE 1 5 215
LA -
Latin America1 2 208
EMEA 1 199
EMEA South 1 1 169
Coulmns for 2nd coumn chart: Region, Priority, Q2,Q3,Q4 ()which is derived from 1st table.
Region Priority Q2 Q3 Q4
Other D: End of Next Day 1568 1613 239
Other C: End of Day 983 893 119
Other A: 2 Hour 631 610 70
Other B: 4 Hour 396 318 56
NA -
North AmericaD: End of Next Day 2 2 514
APJK D: End of Next Day 3 297
NA -
North AmericaC: End of Day 284
NA -
North AmericaA: 2 Hour 1 170
UK D: End of Next Day 157
APJK C: End of Day 1 1 152
Other E: 3 - 5 Business Days 68 58 13
EMEA North D: End of Next Day 1 136
CORPORATE D: End of Next Day 4 107
NA - North America B: 4 Hour 1 104
LA - Latin America D: End of Next Day 1 1 86
EMEA D: End of Next Day 86
UK C: End of Day 85
APJK A: 2 Hour 79
EMEA South D: End of Next Day 72
EMEA North A: 2 Hour 69
EMEA North C: End of Day 56
APJK B: 4 Hour 55
EMEA C: End of Day 1 53
LA - Latin America C: End of Day 54
UK A: 2 Hour 49
EMEA South C: End of Day 1 44
CORPORATE A: 2 Hour 1 43
CORPORATE C: End of Day 44
LA - Latin America A: 2 Hour 1 42
EMEA South A: 2 Hour 1 32
EMEA B: 4 Hour 30
UK B: 4 Hour 30
EMEA A: 2 Hour 27
EMEA North B: 4 Hour 1 26
NA -
North AmericaE: 3 - 5 Business Days 25
LA - Latin America B: 4 Hour 23
EMEA South B: 4 Hour 20
CORPORATE B: 4 Hour 17
APJK E: 3 - 5 Business Days 13
Other F: 6 - 10 Business Days 6 4
Other G: 11 - 20 Business Days 6 1Hi Srinivas,
I'm using label based menu "filterd rows" only but i couldn't bind the drill down with the 1st stacked column chart.
for mor details:
1) i'm having 2 stacked coumn charts & 1 lebel based menu but eventhough i couldn't able to achieve.
if i select the lebel based values then the 2nd stacked column charts is giving detailed valus but if i keep my mouse on the 1st stacked column chart the there is no changes on the 2nd chart..
somewhere i'm mising the binding data between 1st stacked coumn chart & lebel based menu on drill down part.
Becoz i'm having multiple rows. so can you please try your and send me the xlf file using your concept. -
Custom row-fetch and how to get column values from specific row of report
Hi -- I have a case where a table's primary key has more than 3 columns. My report on the
table has links that send the user to a single-row DML form, but of course the automatic
fetch won't work because 1) I can't set more than 3 item values in the link and 2) the
auto fetch only handles 2 PK columns.
1)
I have written a custom fetch (not sure it's the most elegant, see second question) that is working
for 3 or few PK columns (it references the 1-3 item values set in the link), but when there are
more than 3, I don't know how to get the remaining PK column values for the specific row that was
selected in the report. How can I access that row's report column values? I'll be doing it from the
form page, not the report page. (I think... unless you have another suggestion.)
2)
My custom fetch... I just worked something out on my own, having no idea how this is typically
done. For each dependent item (database column) in the form, I have a source of PL/SQL
function that queries the table for the column in question, using the primary key values. It works
beautifully, though is just a touch slow on my prototype table, which has 21 columns. Is there
a way to manually construct the fetch statement once for the whole form, and have APEX be smart
about what items get what
return values, so that I don't have to write PL/SQL for every item? Because my query data sources
are sometimes in remote databases, I have to write manual fetch and dml anyway. Just would like
to streamline the process.
Thanks,
CarolHI Andy -- Well, I'd love it if this worked, but I'm unsure how to implement it.
It seems I can't put this process in the results page (the page w/ the link, that has multiple report rows), because the link for the row will completely bypass any after-submit processes, won't it? I've tried this in other conditions; I thought the link went directly to the linked-to page.
And, from the test of your suggestion that I've tried, it's not working in the form that allows a single row edit. I tried putting this manually-created fetch into a before header process, and it seems to do nothing (even with a hard-coded PK value, just to test it out). In addition, I'm not sure how, from this page, the process could identify the correct PK values from the report page, unless it can know something about the row that was selected by clicking on the link. It could work if all the PK columns in my edit form could be set by the report link, but sometimes I have up to 5 pk columns.
Maybe part of the problem is something to do with the source type I have for each of the form items. With my first manual fetch process, they were all pl/sql functions. Not sure what would be appropriate if I can somehow do this with a single (page level?) process.
Maybe I'm making this too hard?
Thanks,
Carol -
Cell value spanning multiple rows in JTable
Hi,
I have a JTable where I want a single column value alone to span multiple rows.
Something like
Course No. | Location | Cost
| loc1 | 1000
1 ---------------------------------------------
| loc2 | 2000
How can I create a JTable like this?
Thanks for the help.I have a link for that,
http://www2.gol.com/users/tame/
go in swing examples, JTable #4.
Hope it helps :) -
Display CLOB value in multiple rows in ADF UIX
Hi,
I have an ADF UIX application that uses data that are stored in a CLOB column in an Oracle Database.
The table data is presented in a simple table in page1.uix, I use BC4J for accessing the Database and Oracle JDeveloper 9.0.5.2.
The problem is that the CLOB data appear properly (meaning the rows appear OK) only in a frame (messageTextInput element) of a predefined size and if I change the element into a styledText or a formattedText the frame will not appear, but all the CLOB characters appear in a single row.
Does anyone know how I can present the CLOB text data in a UIX page, without having a frame around the text, and at the same time keep the CLOB text in multiple rows?There's no completely trivial way. You'd have to do a bit of extra processing of your CLOB data. The most straightforward work to do is to convert "\n" into "<br>", and then pass that into a <formattedText>.
-
How to change the column value upto 68000 rows
Hi,
I want to change the column value.
I have table called RefDoc
Select distinct r.int_ref from refdoc r where r.int_ref like '\\dxb%'
Int_Re__f
\\dxb\Sample\BFE B777\2008\PO2025225.tif
\\dxb\Sample\RO\SFR\26-01-2009j\RO2022098.pdf
\\dxb\Sample\RO\SFR\26-01-2009j\RO2040831.pdf
\\dxb\Sample\BFE B777\2008\PO2025253.tif
\\dxb\Sample\RO\UM INV\26-01-2009\RO2018358.pdf
up to 68000 rows
I want to change to \\AUH instead of \\dxb.
I want the table like
Int_Re__f
\\AUH\Sample\BFE B777\2008\PO2025225.tif
\\AUH\Sample\RO\SFR\26-01-2009j\RO2022098.pdf
\\AUH\Sample\RO\SFR\26-01-2009j\RO2040831.pdf
\\AUH\Sample\BFE B777\2008\PO2025253.tif
\\AUH\Sample\RO\UM INV\26-01-2009\RO2018358.pdf
Thanks
Niharuser REPLACE function and change it
UPDATE refdoc
SET int_ref = REPLACE(int_ref, '\\dxb\', '\\AUH\')
WHERE int_ref like '\\dxb\%'
Maybe you are looking for
-
Error encountered while running Reprots 9i
Hi, I am getting following error on runninf reports 9i on Solaris machine . Please help. An unexpected exception has been detected in native code outside the VM. Unexpected Signal : 11 occurred at PC=0xfe991918 Function name=Java_oracle_reports_engin
-
Below is a URL to a web service that returns an elevation value given a latitude, longitude, and some other parameters: http://gisdata.usgs.gov/XMLWebServices2/Elevation_Service.asmx/getElevation?X_Value=-100&Y_Value=34&Elevation_Units=FEET&Source_La
-
How to use iPhoto Library in non Apple applications.
Hello, I am fairly new to Mac OS and love iPhoto. However, when I try to access my iPhoto library in Microsoft word, or on shutterfly or other applications I cannot access it. My migrated photos from my old PC are accessible, but iPhoto library is no
-
how i can add one t-code to a number of roles? please give some advice.
-
Could not download SAP Sneak Preview - Java
Anyone managed to download SAP Sneak Preview - Java Edition recently? I can't dwnload it. Pls help. Rgds, Hapizorr Rozi Alias