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;
Similar Messages
-
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 -
Using md5 in a manul tabular form to compare if column value changed
Version: Application Express 3.2.0.00.27
Hello,
I am creating a manul tabular form using apx_item in my select statment that is the source for the query in a report region. I am using a collection. The collection creation statement is:
apex_collection.create_collection_from_query(
p_collection_name => 'DELEG_COLL',
p_query => 'SELECT authid
,empid empid
,to_char(deldate,''DD-MON-YYYY'') deldate
,delscope delscope
,dellimits dellimits
,subdelrights subdelrights
,to_char(delexpiry,''DD-MON-YYYY'') delexpiry
,to_char(datedelremoved,''DD-MON-YYYY'') datedelremoved
,delremovalcomments delremovalcomments
,delegator delegator
,''O'' original_record
,wwv_flow_item.md5(delscope, dellimits, subdelrights,
to_char(delexpiry,''DD-MON-YYYY'') delexpiry,
to_char(datedelremoved,''DD-MON-YYYY'') datedelremoved,
delremovalcomments, delegator)
FROM tbl_delegations
where empid = v(''P12_EMPID'')',
p_generate_md5 => 'YES');The above code is giving me an error in the function
wwv_flow_item.md5(delscope, dellimits, subdelrights,
to_char(delexpiry,''DD-MON-YYYY'') delexpiry,
to_char(datedelremoved,''DD-MON-YYYY'') datedelremoved,
delremovalcomments, delegator)It doesn't seem to like where I attempt to convert date column delexpiry and datedelremoved to a varchar. I am doing this as in the db they are dates and inorder to using the md5 function to compare if the values have changed and only update rows where the values changed.
There error that I get is:
ORA-20104: create_collection_from_query Error:ORA-20104: create_collection_from_query ParseErr:ORA-00907: missing right parenthesis
In the collection I am trying to store the md5 hash result. I haved all the update and insert logic working expect for date type columns. THose give the above error.
I thank you ahead of time for your assistance!
A. ShalonHelen,
Not sure I fully understand your goal. We don't use "tasks" at all but if you are looking to have your workflow check certain valus and be able to send email messages to people based on whatever, then you can certainly do that (as long as your Sharepoint
has the email setup. We do this for alot of workflow tasks.
So, in the workflow you can have a blanket statement like what I previously listed:
if Current Item:hiddenStatus not equals Current Item:Status
.... do something
or you can do something like:
if Current Item:hiddenStatus equals "In-Progress"
.... do something
Else if Current Item:hiddenStatus equals "Completed"
.... do something
or combine the two and do nested "if" statements. Then you add an email statement wherever you need it like:
if Current Item:hiddenStatus equals "Completed"
then email "these users"
To add the email part, just type in "email" on the line where you want to add a statment. There is only one option to choose from. That will display the line "then email these users". The "these users" will be a link. When you
click it you will get a popup to add the email info. We typically will send the email to a user (or users) that are already listed in one of the PeoplePicker fields. On the email form, you can type in your own text, designate that a value is based
on a column value (like our PeoplePicker), designate that a value is based on a workflow variable, add a link to the current item, etc. To get to these options you will click the button to the right of the fields or use the "Add or Change Lookup" button
in the bottom-left for the text area. There is alot you can set in the mail.
Does this help answer your question?
- Peter -
Oracle Text Help with XML column values
Hello. In addition to being new to Oracle Text, I am inheriting an Oracle Text application and have a couple of questions.
First, A context-based index has been set-up on a CLOB column which contains an XML formatted document. The Auto Section Group parameter has been set to created zones for each tag of the XML document. I have found that when using a browser to display the content of the CLOB, some of the column values have trouble displaying in the browser, where I receive an XML processing error. I believe this is due to the fact that some of the XML document rows contain URLs that are not embedded in the CDATA tag. In any case, if the browser has trouble displaying the XML, will oracle text have trouble indexing the XML and creating the section group zones?
Second, I understand that the NOT operator takes a right operand term and left operand term. Can either of the terms be the results of the WITHIN operator, i.e. "dogs not (cats within animals)".
Thank you.I bet you just whipped that out, and I thank you with all my
heart, its amazing to me how many ways I tried to do what you did.
Thanks
I have a second question relating to the same problem and
that is in referencing the over state. Currently, I can write
'text' into the text field and see what I have coming in from xml
in its place during the 'up' state.
However, when the timeline hits the 'over' state, the
textfield will display nothing, or 'text' if I have that written
in. I suspect that I am not referencing the'over' state correctly.
Should I add one line of code sort of referencing the text
field and not just the button while in the over state? -
Comparing two column values with multiple Parameter in VC (Indicator)
Hello VC experts,
GM
I would like to know about how to indicate multiple parameter with different colour in same column and also comparing value with adjucent column.
Eg.
Parameters ,, Column1 ,, Column 2 ,, Indicator (Image)
Parameter 1 ,, a1 ,, b1 ,, RED
Parameter 2 ,, a2 ,, b2 ,, GREEN
Parameter 3 ,, a3 ,, b3 ,,
Parameter 4 ,, a4 ,, b4 ,,
In case I : Parameter -1 Column 1 ( value) = more is better compared to Column 2
In case II : Parameter -2 Column 1 ( value) = Less is better compared to Column 2
How to acheive this INDICATOR based value comparison.
Edited by: Sunil B. Mundhe on Mar 7, 2009 6:30 AM
Edited by: Sunil B. Mundhe on Mar 7, 2009 6:38 AMHi
This is possible in VC. You have to insert 'Image' UI in the required table. Add images of alert through 'Image manager' (Tools tab). Select relevant images of alert in 'Image' UI. In display there is option for 'visibility condition' there you enter condition (like if greater than ,true,false).
Like wise you can add multiple 'Image' UIs in that table & based on visibility conditions you will get these alert images in table.
Regards
Sandeep -
Error -3016 when trying to compare a column value via "decode" function
The following statement:
select * from turbine_user
where login_name = decode(1, 2, 'name1', 'name2')
yields a "-3016 Invalid numeric constants" error.
OTOH, the following variations work as expected:
(a)
select * from turbine_user
where login_name = 'name1'
(b)
select * from turbine_user
where login_name = 'name2'
(c)
select * from turbine_user
where 'name1' = decode(1, 2, 'name1', 'name2')
(d)
select decode(1, 2, 'name1', 'name2') from turbine_user
Does MaxDB have problems with using the decode function to compare something to column values?
My MaxDB-Version: 7.6.03.07
Thanks in advance,
Alex
Edited by: Alexander Zimmer on Feb 6, 2008 3:53 PMHi,
unfortunately I assume that I should explain the doing of decode a little bit:
As we see in the reference manual:
DECODE(<check_expression>,<search_and_result_spec>,...[,<default_expression>])
<check_expression> ::=
<expression>
<search_and_result_spec> ::=
<search_expression>,<result_expression>
<default_expression> ::=
<expression>
<search_expression> ::=
<expression>
<result_expression> ::=
<expression>
Ok, that will mean, that the first parameter of decode will be compared to parameter number 2, 4, 6, 8, 10,... up to number n-1.
If the result of the comparison is true with parameter number x, the result of decode will be the value of parameter x+1.
If no comparison results in 'equal', then NULL will be returned if there is an odd number of parameters respectively the value of the last parameter if there is an even number of parameters of the decode function.
In your context, this means, that 1 is compared to 2 (always false), thus returning 'name2' always. Therefore I do not understand what you want to do with that decode.
Ok, if we assume that the select sent is only a short form of what you really want to do, then I have to apologize, but there is a bug in the kernel coding. It will be fixed ASAP.
To be able to work until then, put the function DIGITS around your 1 and around the 2 (or the corresponding real parameter values) and it should do.
BTW: with column on the left hand side, the error occurs and with a string literal it does not? This is different to my check where both values on the left side cause this error to occur.
Elke -
Compare previous column value in BPS Layout
How to compare the two column values in BPS layout.
My layout format
PO NO
GL
Actual
Amount
1001
701
1200
User Entry
Actual Value is 1200, User will enter the Amount but it should be equal to 1200 or less then that.
If user entered more than 1200 in Amount column, I should get error message.
Thanks in advance.
Regards,
KiruthikaHi Uryukin Andrey,
Where do we need to use this fox formula? Could you please explain steps to use this FF?
Thanks,
Harry -
Compare and test values in two tables
hi everbody, I use oracle 10g
I have a table for large itemsets called L shown below with values
ITEMS CODE
b 1
c 2
d 3
e 4
d:e 5
b:c 6
I generate all candidate combinations firstly 2-sequences for in code field values for that I use below code
select ltrim(replace(sys_connect_by_path(code,','),',',':'),':') comb,level
from L
where level > 1
connect by level =2 ;
some candidate examles generated above code shown belown ( i interest only comb results values )
comb
1:1
1:2
1:3
1:4
1:5
1:6
2:1
2:2
6:1
6:6
I have another table called T2 shown below with some values
TID ITEM CID T_DATE
1 b 1 05.05.1999
1 c 1 05.05.1999
2 e 1 17.05.1999
3 d 2 13.05.1999
4 b 2 19.05.1999
4 c 2 19.05.1999
5 d 2 21.05.1999
6 a 3 07.05.1999
6 b 3 07.05.1999
7 d 3 15.05.1999
7 e 3 15.05.1999
8 b 4 11.05.1999
8 c 4 11.05.1999
9 c 4 16.05.1999
now I want to test every items belong to candidate code generated above with item values of T2 table
in test table T2 is grouped by CID and T_DATE. I want to compare items belong to current code with item of T2 table. if first item(s) in candidate combination is found in T2 table , second item(s) must be found too if there is. but this first and second item(s) together must be found same CID but at different T_DATE belong to that CID. if found, this candidate okey for me.for example we take candidate 3:1. items are d ( code 3 ) and b ( code 1 ) respectively. first item d is searched for CID = 1, it is not found. now we search item d for CID = 2 again , yes it is found in TID=3 row then we look another item b for CID=2 but item b must be found after d row for same CID and at different T_DATE. yes item d is found too for CID=2 after b item at different T_DATE in TID=4 row. that is we wants, is customer ( for example CID 2) buy item b after buying item d same customer at another time as sequence. second example may be candidate 5:6. is customer buy items b and c together ( for code 6) after at another time buying items d and e ( code 5 ) together by same customer
NOTE : I use code field sequence values for pointer of items. items may be used directly on generating candidate process and used comparing process with T2 table
thanks for smart idea....In addition I would suggest you read this:
http://forums.oracle.com/forums/help.jspa
and learn to use the tags to format the parts of the post that belong in fixed format. -
How to update column values in a table where that column is referring to different tables
i have a table Order it has columns
OrderID, Name, Total
1 trade value populated from i.e. tradeorder table
2 fixed value is populated from fixedorder table
3 annual value populated from another table
I m thinking of creating function for every order id to call those tables..
and there are many insertions taking place in order table ,,at the moment its 20 rows ..
kindly provide your suggestionsYou can group rows in order table and update the set of row from the specific table. For instance
UPDATE [ORDER] SET [TOTAL]=B.[TOTAL] FROM [ORDER] A INNER JOIN [TRADEORDER] B ON A.ORDERID=B.ORDERID WHERE A.NAME='TRADE'
UPDATE [ORDER] SET [TOTAL]=B.[TOTAL] FROM [ORDER] A INNER JOIN [FIXEDORDER] B ON A.ORDERID=B.ORDERID WHERE A.NAME='FIXED'
UPDATE [ORDER] SET [TOTAL]=B.[TOTAL] FROM [ORDER] A INNER JOIN [ANOTHERTABLE] B ON A.ORDERID=B.ORDERID WHERE A.NAME='ANNUAL'
Regards, RSingh -
Oracle report problem-Passing a column value from a query block to another
Hi I am facing a problem in oracle reports.
I have 3 query blocks say Q1,Q2 and Q3.
From Q1 I get a tblkey coulmn and for each value of tblkey I need to pass it on to Q2 which gives me a status and now finally Q3 will take tblkey and status to give me final output.
Can somebody please tell me how I can do it?
Thanks,
AvinDepending on your report requirement, you may do a join of Q1, Q2, and Q3; or keep all Qs and for Q3 use subqueries ...
Select ... from ... where tblkey, status in (
select tblkey, status from ... where tblkey in (
select tblkey from .... where .... ) )
Good luck.
DC -
Need ideas for alternative to JavaScript for comparing two inputText values
Hello
I am currently using the JavaScript method to check if the values of two inputText components are equal.
If the values are not equal an alert box is displayed. In either case the action on the bean is performed and in the action method the two bean property values are compared again, if they don't match the action returns null and the for is redisplayed.
I don't like this method because:
A) it seems long winded and wasteful
B) the JavaScript dialog box is out of character with the rest of the form, where validation errors are returned as messages next to the offending component.
On one of the inputText components I already do a custom validation to check that the input value is a valid javax.mail.internet.InternetAddress.
Does anyone know of any other method ideas, perhaps using Value Change Events that will allow a message to be written against the second inputText component if the two values did not match, and which could be done before the Invoke Application event. I have tried something along these lines but have failed.
Many thanks in advance...If you can use a custom tag for the validator instead of the standard f:validator tag,
there is a better way:
The custom tag has an attribute , eg. "forId", to specify the ID of another component.
Then, your validator can use the attribute for the parameter of findComponent().
Something like:
YourValidatorTagHandler.java
protected Validator createValidator() throws JspException {
YourValidator val = (YourValidator)super.createValidator();
val.setForId(forId);
return val;
YourValidator.java
public void setForId(String f) {
forId = f;
public void validate(
FacesContext context,
UIComponent component,
Object value)
throws ValidatorException {
int i1;
int i2;
try {
i1 = ((Integer) value).intValue();
UIComponent comp = component.findComponent(forId);
String val = (String)((UIInput)comp).getSubmittedValue();
i2 = Integer.parseInt(val);
} catch (RuntimeException e) {
FacesMessage msg = new FacesMessage(e.getMessage());
throw new ValidatorException(msg);
if (i1 != i2) {
FacesMessage msg = new FacesMessage("Error");
throw new ValidatorException(msg);
} -
Query for comparing two columns in two tables
Hai, all,
I have following two tables and columns, I need to get the rows (all columns) from scott.cp_ip which are not ( the same value present in t1 and also in t2).
Table scott.cp_ip column cp_ip.vrno = Table scott.cb1 column cb1.cb_vnno
I used the following query and did not get the correct result:
select * from scott.cp_ip where cp_ip.vrno in (select cb1.cb_vnno from scott.cb1);
Can you please tell how it can be solved?
Thanks in advance.
Rcs
SQL> desc scott.cb1;
Name Null? Type
ID NUMBER
SUPCODE NUMBER
SUPLNAME VARCHAR2(100)
NAME VARCHAR2(100)
ITEMCODE VARCHAR2(10)
RECDOC NUMBER
RECDATE VARCHAR2(10)
TOTVALUE NUMBER
QTY NUMBER
CB_IPNO NUMBER
CB_VNNO NUMBER
CB_VDT VARCHAR2(10)
CB_AMT NUMBER
SQL> desc scott.cp_ip;
Name Null? Type
ID NUMBER
VRNO NUMBER
CODE VARCHAR2(50)
HEAD VARCHAR2(255)
PARTI VARCHAR2(255)
CR NUMBER
SQL> select * from scott.cp_ip
2 intersect
3 select * from scott.cb1;
select * from scott.cp_ip
ERROR at line 1:
ORA-01789: query block has incorrect number of result columns
SQL> (select * from scott.cp_ip
2 minus
3 select * from scott.cb1)
4 union all
5 (select * from scott.cb1
6 minus
7 select * from scott.cp_ip);
(select * from scott.cb1
ERROR at line 5:
ORA-01789: query block has incorrect number of result columns
SQL> select * from scott.cp_ip where cp_ip.vrno in (select cb1.cb_vnno from scott.cb1);
result=instead of 1408 rows, 1481 rows (excess 73 rows) getting!
----------Instead of SELECT * write only the column that you want to compare. I guess that would be cb1.cb_vnno and cp_ip.vrno.
-
Hi All,
I have 2 tables
table1: col1 sequenceid, col2 code
table2:col1 studentID , col2 code, col3 joindate
in table 1 i have values as
1 Q
2 W
3 E
4 R
5 T
6 Y
Table2:
A1 Q
1-04-2015
A1 W
2-04-2015
A3 Q
1-04-2015
A2 Q
1-04-2015
A3 W
2-04-2015
A2 W
2-04-2015
A2 E
2-04-2015
A3 E
2-04-2015
A1 E
2-04-2015
A2 R
2-04-2015
Now i want ouput as
A3 E
A2 R
A1 E
I want to group the values in table2 based on studentid order by the sequence in the table1 and get the latest which is having higher sequence (Note: the date field cannot be used to order the values)from @table2 a inner join @table1 b on a.col2=b.col2 collate database_default)
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 -
MDX Script for adding to column values
Hi Experts,
I am new in ASO MDX, need some help.
I have one ASO out line in which I want to fetch addition of "Sales Tax" and "Income Tax" where as there are some other taxes also in "Total Tax". I want to fetch only the sum of "Sales Tax" AND "Income Tax".
ThanksIF you have a look at - http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_tech_ref/frameset.htm?mdx_sum.html
It gives you an example of how to create a calculated member..
or just use something like
WITH MEMBER [Accounts].[Sales Tax + Income Tax] AS ' [Accounts].[Sales Tax] + [Accounts].[Income Tax]'
Cheers
John
http://john-goodwin.blogspot.com/ -
Compare 45 columns and update one table col
I am using Oracle 9i database.I need to compare each record between two tables
and update the one of table column (what records are updated)
CURSOR cur1 is select t1., t2. from t1, t2 where t1.primarykey = t2.primarykey
FOR rec1 IN cur1
LOOP
IF rec1.t1_col_1<>rec1.t2_col_1
then
update t1
set col_t1.rem="MOdified",t.col_1=rec1.t2_col_1
where t1.primerykey=rec1.primarykey
END IF;
IF rec1.t1_col_2<>rec1.t2_col_2
then
update t1
set col_t1.rem="MOdified",t.col_2=rec1.t2_col_2
where t1.primerykey=rec1.primarykey
END IF;
..........45 if else conditions
END LOOP;
I have 1 million records to compare and 45 columns to compare, how do I increase performance.
Currently it takes about 5hrs for the cursor to go through this if -else comparison.
Thanks and Regards
Swayamprakash.ChiluveruHi Swayamprakash,
Few basics first.
1. DML SQL's perform better than PL/SQL. Sounds great but Oracle then need to hop between SQL and PL/SQL engine for every record in the cursor causing THRASHING. This is an old concept, reference of which can be found in Operating Systems.
With Bulk Collect option, this could be minimized to a large extent, but causes a large amount of Undo being generated. This is another pitfall of using Bulk Collect. Morever, when you expect more percentage of records to be updated, it is advisable that the indices (if any) must be disabled. They can be rebuild afterwards causing very minimal amount of Undo. Performance gain is expected here.
Now a query that you need to clarify:
1. One million records to be updated on a diurnal basis - An OLTP database might need this functionality which is better handled by a screen driven interface rather than a SQL/Procedure running in background.
An OLAP database must simply ignore such requirements for they are meant to be history archives.
Suggestion:
Merge - Seems to be the only optimal solution at the moment for the exact requirements are unclear. Already, somone has suggested this.
Oracle Developers, DBA's must setp out from technicalities and turn towards functionality.
Kind regards,
Abhijit
Maybe you are looking for
-
Videochat not possible this computer does not support video chats
Hi there, since yesterday its not possible to to start an video chat. It's grey. In the preference of "mesage" under the tap "video" shows the message "this computer does not support video chats. There is no problem with the camera, i can use facetim
-
Is there STILL no way to have only icons on the Favorites bar for bookmarks?
-
SWWL - being used to clear Inbox for Workflow Item in error
Hello, We are currently using SWWL for clearing Workflow Iitems from the Inbox if they have errored out directly in production. I have tried to review this in the forum and generally have come to the conculsion that SWWL should not be directly use
-
Hi Team, Please consider this scenario. 1. System DE1 has SLD, DEV and NWDI and runs CMS. 2. DE* Landscape is moving to CTS+, but cannot utilize DE1 due to SLD,DEV, NWDI being on the same system (recomended No No) 3. So the responsibility of NWDI and
-
My messages app isn't opening up, what should i do?
I updated my phone and now every time I open to check my texts, it won't open.