When I use Merge duplicate Values
Hi
When I use MERGE for to INSERT It is duplicating values, I put condition in ON
MERGE /*+ append nologging */ INTO sysadm.ps_loc_item_sn_zz2 t3
USING (WITH tmp_ps_loc_item AS
(SELECT loc_cntr_id_sn, setid, companyid, effdt, setid_product, loc_product_sn,
ROW_NUMBER () OVER (PARTITION BY loc_cntr_id_sn, setid, companyid, effdt, setid_product, loc_product_sn ORDER BY linha)
seqno_item_sn,
loc_item_status, NULL ken_data_ativ_sn, NULL inactive_date_sn,
'LO' cntrct_origin_sn, SYSDATE row_added_dttm,
'CARGA PS 29052007' row_added_oprid, SYSDATE row_lastmant_dttm,
'CARGA PS 29052007' row_lastmant_oprid, 0 syncid, NULL syncdttm,
ken_component_sn
FROM (SELECT t1.*, ROWNUM linha
FROM sysadm.tmp_equip_crm t1,
(SELECT LEVEL l
FROM DUAL
CONNECT BY LEVEL <= 100)
WHERE l <= t1.qtd) )
SELECT t2.loc_cntr_id_sn, t2.setid, companyid, effdt, setid_product, loc_product_sn,
t2.seqno_item_sn, loc_item_status, t5.ken_data_ativ_sn, inactive_date_sn,
cntrct_origin_sn, row_added_dttm, row_added_oprid, row_lastmant_dttm, syncid,
syncdttm, t2.ken_component_sn
FROM tmp_ps_loc_item t2, sysadm.tmp_data_ativa t5
WHERE t2.loc_cntr_id_sn = t5.loc_cntr_id_sn(+)
AND t2.ken_component_sn = t5.ken_component_sn(+)
AND t2.loc_item_status = t5.loc_item_status_sn(+)
AND t2.seqno_item_sn = t5.seqno_item_sn(+)) t4
ON ( t3.loc_cntr_id_sn = t4.loc_cntr_id_sn
AND t3.setid = t4.setid
AND t3.companyid = t4.companyid
AND t3.effdt = t4.effdt
AND t3.setid_product = t4.setid_product
AND t3.loc_product_sn = t4.loc_product_sn
AND t3.seqno_item_sn = t4.seqno_item_sn)
WHEN MATCHED THEN
UPDATE
SET t3.syncid = 0
WHEN NOT MATCHED THEN
INSERT (loc_cntr_id_sn, setid, companyid, effdt, setid_product, loc_product_sn, seqno_item_sn,
loc_item_status_sn, ken_data_ativ_sn, inactive_date_sn, cntrct_origin_sn,
row_added_dttm, row_added_oprid, row_lastmant_dttm, row_lastmant_oprid, syncid,
syncdttm)
VALUES (t4.loc_cntr_id_sn, t4.setid, t4.companyid, t4.effdt, t4.setid_product,
t4.loc_product_sn, t4.seqno_item_sn, loc_item_status, t4.ken_data_ativ_sn,
t4.inactive_date_sn, t4.cntrct_origin_sn, t4.row_added_dttm, t4.row_added_oprid,
t4.row_lastmant_dttm, t4.ken_component_sn, t4.syncid, t4.syncdttm);
I don't understand what you mean exactly?
When an SQL statement encounters an error then all
its work is rolled back ...
So why do you expect that it worùs otherwise?simply
WHEN MATCHED THEN UPDATE SET t3.syncid = 0Only
Similar Messages
-
Concatenation error - when i use text column value in where condition.
Hi,
i am creating Materialized view using few columns from two tables and as per requirement i need to prepare select statement with where condition in another column.(new column)
i tried like below....
create materialized view MAIN
refresh force on demand
as
select
a.table_name,
a.column_name,
b.trial_name,
'select * from '||a.table_name||' where '||a.column_name|| ' = '|| b.trial_name||';' "QUERY"
from
exp_csv_tB a,
exp_csv_tr b;
a.table name value is : monitoring_table
a.column_name value is : study
b.trial_name = fty777
Materialized view created with extra column but it is not added '' (codes) to text value in where condition.
output which i got is :
select * from monitoring_table where study = fty777;
but
i need output like
select * from monitoring_table where study = 'fty777';
fty777 value should be in codes like 'fty777'. i read some articles but didnt get this example.
please help.Try this:
CREATE MATERIALIZED VIEW main
REFRESH FORCE ON DEMAND
AS
SELECT
a.table_name,
a.column_name,
b.trial_name,
'select * from '||a.table_name||' where '||a.column_name|| ' = '''|| b.trial_name||'';'' "QUERY"
FROM
exp_csv_tb a,
exp_csv_tr b;
You have to give double single codes for semi-colons ..
Regards.. -
Unique constraint is not thrown when used MERGE INSERT (alone) via dblink.
We found some interesting behaviour of unique constraint on Merge query when we use Merge When Not Matched Insert (no update query) via a dblink.
In one Schema S1, on Table A1(c1,c2,c3) there is a unique constraint on column (c1,c2).
Column c2 is nullable and has null for some records.
Now i have a table A2 with same defintion as A1 in Schema S2.In S2 , i have a dblink of S1 as S1 itself.
I have data in S2.A2. Here also i have some records with c2 as null and c1 matching with the data of S1.A1.
Now from schema S2,
I am using the following Merge Query,
MERGE INTO S1.A1 target
USING S2.A2 source
ON (target.c1 = source.c1 and target.c2 = source.c2)
WHEN NOT MATCHED
INSERT (c1,c2,c3) values (source.c1, source.c2,source.c3)
WHEN MATCHED
UPDATE c3 = source.c3;
Now when i execute this merge in schema S2,
if i have some data in S1.A1 and S2.A2 having c1 as same and c2 as null, as oracle does not treat two nulls same, it goes for an insert, i have got unique constraint violated error.
But if i execute MERGE INSERT alone, though that record is getting inserted , i am not getting unique constraint violated error.
Oracle version we are using is 10g (10.2...).
Is it a bug in oracle or what could have caused this behaviour.Dear,
ERROR at line 1:
ORA-00001: unique constraint (SYS_C00137508) violatedYou need to think about two things
(a) read consistency : what was the situation of table_1 when the maching clause has been initially evaluated ; there were 0 rows matching which means the merge operation will be all insert
(b) your matching clause has a problem : the join column must be unique in both tables otherwise the merge will be ambigous. You don't have a unique key on the source table
(c) think that the merge operation will never insert id =1 and then update id = 1 within the same operation. This will never happen
Hope this helps
Mohamed Houri -
Query runs slower when using variables & faster when using hard coded value
Hi,
My query runs slower when i use variables but it runs faster when i use hard coded values. Why it is behaving like this ?
My query is in cursor definition in a procedure. Procedure runs faster when using hard coded valus and slower when using variables.
Can anybody help me out there?
Thanks in advance.Hi,
Thanks for ur reply.
here is my code with Variables:
Procedure populateCountryTrafficDetails(pWeekStartDate IN Date , pCountry IN d_geography.country_code%TYPE) is
startdate date;
AR_OrgId number(10);
Cursor cTraffic is
Select
l.actual_date, nvl(o.city||o.zipcode,'Undefined') Site,
g.country_code,d.customer_name, d.customer_number,t.contrno bcn,
nvl(r.dest_level3,'Undefined'),
Decode(p.Product_code,'820','821','821','821','801') Product_Code ,
Decode(p.Product_code,'820','Colt Voice Connect','821','Colt Voice Connect','Colt Voice Line') DProduct,
sum(f.duration),
sum(f.debamount_eur)
from d_calendar_date l,
d_geography g,
d_customer d, d_contract t, d_subscriber s,
d_retail_dest r, d_product p,
CPS_ORDER_DETAILS o,
f_retail_revenue f
where
l.date_key = f.call_date_key and
g.geography_key = f.geography_key and
r.dest_key = f.dest_key and
p.product_key = f.product_key and
--c.customer_key = f.customer_key and
d.customer_key = f.customer_key and
t.contract_key = f.contract_key and
s.SUBSCRIBER_KEY = f.SUBSCRIBER_KEY and
o.org_id(+) = AR_OrgId and
g.country_code = pCountry and
l.actual_date >= startdate and
l.actual_date <= (startdate + 90) and
o.cli(+) = s.area_subno and
p.product_code in ('800','801','802','804','820','821')
group by
l.actual_date,
o.city||o.zipcode, g.country_code,d.customer_name, d.customer_number,t.contrno,r.dest_level3, p.product_code;
Type CountryTabType is Table of country_traffic_details.Country%Type index by BINARY_INTEGER;
Type CallDateTabType is Table of country_traffic_details.CALL_DATE%Type index by BINARY_INTEGER;
Type CustomerNameTabType is Table of Country_traffic_details.Customer_name%Type index by BINARY_INTEGER;
Type CustomerNumberTabType is Table of Country_traffic_details.Customer_number%Type index by BINARY_INTEGER;
Type BcnTabType is Table of Country_traffic_details.Bcn%Type index by BINARY_INTEGER;
Type DestinationTypeTabType is Table of Country_traffic_details.DESTINATION_TYPE%Type index by BINARY_INTEGER;
Type ProductCodeTabType is Table of Country_traffic_details.Product_Code%Type index by BINARY_INTEGER;
Type ProductTabType is Table of Country_traffic_details.Product%Type index by BINARY_INTEGER;
Type DurationTabType is Table of Country_traffic_details.Duration%Type index by BINARY_INTEGER;
Type DebamounteurTabType is Table of Country_traffic_details.DEBAMOUNTEUR%Type index by BINARY_INTEGER;
Type SiteTabType is Table of Country_traffic_details.Site%Type index by BINARY_INTEGER;
CountryArr CountryTabType;
CallDateArr CallDateTabType;
Customer_NameArr CustomerNameTabType;
CustomerNumberArr CustomerNumberTabType;
BCNArr BCNTabType;
DESTINATION_TYPEArr DESTINATIONTYPETabType;
PRODUCT_CODEArr PRODUCTCODETabType;
PRODUCTArr PRODUCTTabType;
DurationArr DurationTabType;
DebamounteurArr DebamounteurTabType;
SiteArr SiteTabType;
Begin
startdate := (trunc(pWeekStartDate) + 6) - 90;
Exe_Pos := 1;
Execute Immediate 'Truncate table country_traffic_details';
dropIndexes('country_traffic_details');
Exe_Pos := 2;
/* Set org ID's as per AR */
case (pCountry)
when 'FR' then AR_OrgId := 81;
when 'AT' then AR_OrgId := 125;
when 'CH' then AR_OrgId := 126;
when 'DE' then AR_OrgId := 127;
when 'ES' then AR_OrgId := 123;
when 'IT' then AR_OrgId := 122;
when 'PT' then AR_OrgId := 124;
when 'BE' then AR_OrgId := 132;
when 'IE' then AR_OrgId := 128;
when 'DK' then AR_OrgId := 133;
when 'NL' then AR_OrgId := 129;
when 'SE' then AR_OrgId := 130;
when 'UK' then AR_OrgId := 131;
else raise_application_error (-20003, 'No such Country Code Exists.');
end case;
Exe_Pos := 3;
dbms_output.put_line('3: '||to_char(sysdate, 'HH24:MI:SS'));
populateOrderDetails(AR_OrgId);
dbms_output.put_line('4: '||to_char(sysdate, 'HH24:MI:SS'));
Exe_Pos := 4;
Open cTraffic;
Loop
Exe_Pos := 5;
CallDateArr.delete;
FETCH cTraffic BULK COLLECT
INTO CallDateArr, SiteArr, CountryArr, Customer_NameArr,CustomerNumberArr,
BCNArr,DESTINATION_TYPEArr,PRODUCT_CODEArr, PRODUCTArr, DurationArr, DebamounteurArr LIMIT arraySize;
EXIT WHEN CallDateArr.first IS NULL;
Exe_pos := 6;
FORALL i IN 1..callDateArr.last
insert into country_traffic_details
values(CallDateArr(i), CountryArr(i), Customer_NameArr(i),CustomerNumberArr(i),
BCNArr(i),DESTINATION_TYPEArr(i),PRODUCT_CODEArr(i), PRODUCTArr(i), DurationArr(i),
DebamounteurArr(i), SiteArr(i));
Exe_pos := 7;
dbms_output.put_line('7: '||to_char(sysdate, 'HH24:MI:SS'));
EXIT WHEN ctraffic%NOTFOUND;
END LOOP;
commit;
Exe_Pos := 8;
commit;
dbms_output.put_line('8: '||to_char(sysdate, 'HH24:MI:SS'));
lSql := 'CREATE INDEX COUNTRY_TRAFFIC_DETAILS_CUSTNO ON country_traffic_details (CUSTOMER_NUMBER)';
execDDl(lSql);
lSql := 'CREATE INDEX COUNTRY_TRAFFIC_DETAILS_BCN ON country_traffic_details (BCN)';
execDDl(lSql);
lSql := 'CREATE INDEX COUNTRY_TRAFFIC_DETAILS_PRODCD ON country_traffic_details (PRODUCT_CODE)';
execDDl(lSql);
lSql := 'CREATE INDEX COUNTRY_TRAFFIC_DETAILS_SITE ON country_traffic_details (SITE)';
execDDl(lSql);
lSql := 'CREATE INDEX COUNTRY_TRAFFIC_DETAILS_DESTYP ON country_traffic_details (DESTINATION_TYPE)';
execDDl(lSql);
Exe_Pos:= 9;
dbms_output.put_line('9: '||to_char(sysdate, 'HH24:MI:SS'));
Exception
When Others then
raise_application_error(-20003, 'Error in populateCountryTrafficDetails at Position: '||Exe_Pos||' The Error is '||SQLERRM);
End populateCountryTrafficDetails;
In the above procedure if i substitute the values with hard coded values i.e. AR_orgid = 123 & pcountry = 'Austria' then it runs faster.
Please let me know why it is so ?
Thanks in advance. -
"Merge with values" not merging values
Hello,
I have quite a problem with LDAP provisionning and LDAP groups management:
- "user1" and "user2" already exist in the LDAP directory and are members of "group1"
- I create user1 in IDM and give him the LDAP ressource => he gets linked correctly to his account
- I create user2 in IDM
- I have a role in IDM with the LDAP ressource associated and a "set attribute value" configured with "group2" and "merge with values"
- when I give this role to user1, user1 gets group1 and group2 in the LDAP directory. Great.
- when I give this role to user2, user2 gets linked correctly to his account and only has group2! group1 has disappeared and no merge whatsoever was performed!
Of course, my real situation involves thousands of existing users, and I plan to manage user ressources only via Roles and not via Ressource. I then have thousands of user2 who are going to lose their groups!
I also tried with "Authoritative merge with values", same result.
Any idea what should be changed?
ThanksHi,
If the users already have access to 'group1' then create a role with "Merge with value, clear existing" for the attribute.
If required then create another role for 'group2' also with "Merge with value, clear existing" for the attribute. A user who is assign both roles will be granted access to 'group1' and'group2'
"Merge with value, clear existing" will ensure the user only has access to the groups as per the role assignments. If the user is independently assigned 'group3' then IDM will remove 'group3' next time the user is refreshed within IDM.
If you only use "Merge with value" then old groups will not be removed even if they are not required. -
Corelating messages using the Dynamic Values
Hi all,
I want to collect message using BPM.I have sucessfully executed the same using corelation from one of the fields.The ID field was used for corelation
I was able to sucessfully execute the senario the messages with same ID were going to same process ID and getting collected as well
Now i wanted to have some dynamicconfiguration parameters for eg i thought i can use the filename.That is collate the messages using the filename.
I changed the corleation and tried but for each messages even with the same file name its creating a different process ID and thus my messages are not collected at all.
To tel you more about the senario i created its a file to file with BPM collecting the messages. i send the first file and then the second file also with the same file name.
I have configured the AdapterSpecific Attributes and able to view the filenames in the XML Messages header
Can anyone put some light as too why there are different Process IDs being created.I heard in some of the forums that its an error in some of the SPs
I am on XI 7.0 SP11 and think it should not be a problem.
Thanks in Advance
Rgds
Adityathnks for ure replies
But all of the above steps are checked
It seems that i have given the right co-relation as well but still dnt knw y i'm not able to collect the messages
The loop is defined to complete after a fixed count and the container variable increments by 1 after each loop
The senario works perfectly if i use any field corelation to collect the messages but fails when i use a dynamic value like filename. And yes i have double checked the filename they are same
Rgds
Aditya -
Using multiple key values to find data
Hello, It's me again.
I had a question about bring data out from Database and show on an ADF page on Jdev 11.1.1.3.
And Mr. Daniel Atwood answered my question with this follow blog he wrote.
http://www.avioconsulting.com/blog/datwood/2012/06/19/using-bpm-process-variable-adf-form-retrieve-database-information-0.
But I have another question on the top of that.
The example Mr.Atwood provided is when you using "one" key value, what if I have two key values, how to set this up?
Here are some details:
I have a table like this
ID Type_code Name
0001 05 a-blabla
0002 25 b-blabla
0002 26 b-blabla
0003 08 c-blabla
0003 25 c-blabla
0003 79 c-blabla
What I want to do is after input the ID(0003) and type_code (25), it will show me the result on three input text components in ADF page with value 0003, 25 and c-blabla.
Currently, I can use only ID to query the data, but I would like to use two key values to find the specific data.
Thank you very much for taking time to think about this,
Sincerely,
ViolaDear Daniel, may I ask one more question please?
what if I have 4 tables?
table1
ID * ID_Type_code * Name
0001 * 11 * abc
0002 * 12 * abcd
0003 * 13 * abcde
table2
ID * OID_type_code * Name
0001 * 22 * abc
0002 * 23 * abcd
0002 * 25 * abcd
0003 * 23 * abcde
0003 * 22 * abcde
0003 * 28 * abcde
table3
ID * OID_type_code * OGAD_line_id * address
0001 * 22 * 1 * a street
0001 * 22 * 2 * b street
0002 * 23 * 1 * c street
0002 * 25 * 1 * d street
0003 * 28 * 1 * e street
0003 * 28 * 2 * f street
0003 * 28 * 3 * g street
table 4
ID OID_type_codeOGAD_line_id*COP_line_id*phone number
0001*22*1*1*2222222222
0001*22*1*2*3333333333
0002*23*1*1*4444444444
0003*28*2*1*5555555555
0003*28*2*2*6666666666
Primary key for each table
table1, primary key is ID
table2, primary key is ID , OID_type_code
table3, primary key is ID , OID_type_code, OGAD_line_id
table4, primary key is ID , OID_type_code, OGAD_line_id , COP_line_id
I would like to show each value in each table in the separate input text fields.
Therefore, this is an advanced question based on the previous one, not only get values from one table but also from several tables based on input for example 0003 and 28 as the ID and OID_type_code?.
Let me know if you need more details,
Thank you so much,
Viola -
Hi everyone,
I need help with inserting values using merge.
* I need to check all the units in a parent category. For example, NF_ARTICLECATEGORYID = 7462 is a parent category.
* Im going to compare all the units in the parent category(7642) to the units in a subcategory (8053).
* If the units in parent category(7642) is not present in the subcategory(8053) then the units will be inserted in the same table.
table structure:
Table name : ARTICLECATEGORYACCESS
Fields: IP_ARTICLECATEGORYACCESSID
NF_ARTICLECATEGORYID
NF_UNITID
NF_USERID
N_VIEW
N_EDIT
Sample data:
CREATE TABLE articlecategoryaccess (
IP_ARTICLECATEGORYACCESSID NUMBER(5),
NF_ARTICLECATEGORYID NUMBER (10),
NF_UNITID NUMBER (10),
NF_USERID NUMBER (10)
N_VIEW INT,
N_EDIT INT);
INSERT INTO articlecategoryaccess VALUES (255583, 7642, 29727, NULL, 1 ,1);
INSERT INTO articlecategoryaccess VALUES (243977,7642,29728, NULL, 1 ,1);
INSERT INTO articlecategoryaccess VALUES (240770,7642,29843, NULL, 1 ,1);
INSERT INTO articlecategoryaccess VALUES (243413,7642,29844, NULL, 1 ,1);
INSERT INTO articlecategoryaccess VALUES (274828,7642,44849, NULL, 1 ,1);
INSERT INTO articlecategoryaccess VALUES (274828,8053,44849, NULL, 1 ,1);
Units ID 29727, 29728, 29843, 29844, 44849 has access to parent category 7642.
The units id 29727, 29728, 29843, 29844 dont have access to subcategory 8053.
29727, 29728, 29843, 29844 should be inserted in the same table and will have an access to 8053.
After they are inserted, it should look like this
IP_ARTICLECATEGORYACCESSID NF_ARTICLECATEGORYID NF_UNITID NF_USERID N_VIEW N_EDIT
255583 7642 29727 null 1 1
243977 7642 29728 null 1 1
240770 7642 29843 null 1 1
243413 7642 29844 null 1 1
274828 7642 44849 null 1 1
new value 8053 44849 null 1 1
new value 8053 29843 null 1 1
new value 8053 29844 null 1 1
new value 8053 29728 null 1 1
new value 8053 29727 null 1 1
NOTE: IP_ARTICLECATEGORYACCESSID is a sequence and it should be unique
DECLARE
BEGIN
MERGE INTO articlecategoryaccess b
USING (SELECT *
FROM articlecategoryaccess c
WHERE nf_articlecategoryid = 7642
MINUS
SELECT *
FROM articlecategoryaccess c
WHERE nf_articlecategoryid = 8053) e
ON (1 = 2)
WHEN NOT MATCHED THEN
INSERT (b.ip_articlecategoryaccessid, b.nf_articlecategoryid, b.nf_unitid, b.NF_USERID, b.N_VIEW, b.N_EDIT)
VALUES (articlecategoryaccessid_seq.nextval, 8053, e.nf_unitid, null, 1, 1);
END;
i got an error after running the script:
*Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level.
*Action: Either remove the unique restriction or do not insert the key.
why would it be duplicated? its a sequence and its unique.. I dont know, maybe there is something wrong my script..
Any help is appreciated..
EdEd,
1. What is the current value of the Sequence? Does the current value of sequence exist in the table? If yes, then increment the sequence to a value that is not present in the Table.
2. Do you have any unique constraint on any of the columns that you are inserting?
I have to ask you again, Why are you insisting on Merge statement when a simple Insert can do the job for you? Don't you feel that the below specified Merge statement is making things look more Complicated than they actually are, do you?
Think on it and then proceed. I hope these pointers help you to resolve the issue.
Regards,
P. -
Avoiding null and duplicate values using model clause
Hi,
I am trying to use model clause to get comma seperated list of data : following is the scenario:
testuser>select * from test1;
ID VALUE
1 Value1
2 Value2
3 Value3
4 Value4
5 Value4
6
7 value5
8
8 rows selected.
the query I have is:
testuser>with src as (
2 select distinct id,value
3 from test1
4 ),
5 t as (
6 select distinct substr(value,2) value
7 from src
8 model
9 ignore nav
10 dimension by (id)
11 measures (cast(value as varchar2(100)) value)
12 rules
13 (
14 value[any] order by id =
15 value[cv()-1] || ',' || value[cv()]
16 )
17 )
18 select max(value) oneline
19 from t;
ONELINE
Value1,Value2,Value3,Value4,Value4,,value5,
what I find is that this query has duplicate value and null (',,') coming in as data has null and duplicate value. Is there a way i can avoid the null and the duplicate values in the query output?
thanks,
Edited by: orausern on Feb 19, 2010 5:05 AMHi,
Try this code.
with
t as ( select substr(value,2)value,ind
from test1
model
ignore nav
dimension by (id)
measures (cast(value as varchar2(100)) value, 0 ind)
rules
( ind[any]= instr(value[cv()-1],value[cv()]),
value[any] order by id = value[cv()-1] || CASE WHEN value[cv()] IS NOT NULL
and ind[cv()]=0 THEN ',' || value[cv()] END
select max(value) oneline
from t;
SQL> select * from test1;
ID VALUE
1 Value1
2 Value2
3 Value3
4 Value4
5 Value4
6
7 value5
8
8 ligne(s) sélectionnée(s).
SQL> with
2 t as ( select substr(value,2)value,ind
3 from test1
4 model
5 ignore nav
6 dimension by (id)
7 measures (cast(value as varchar2(100)) value, 0 ind)
8 rules
9 ( ind[any]= instr(value[cv()-1],value[cv()]),
10 value[any] order by id = value[cv()-1] || CASE WHEN value[cv()] IS NOT NULL
11 and ind[cv()]=0 THEN ',' || value[cv()] END
12 )
13 )
14 select max(value) oneline
15 from t;
ONELINE
Value1,Value2,Value3,Value4,value5
SQL> -
Error in merge statement when trying to impliment SCD type 2 using merge...
Hi ,
I'm trying to impliment SCD type 2 using Merge using below blog as reference but sime how it is erroring out with error
http://www.made2mentor.com/2013/08/how-to-load-slowly-changing-dimensions-using-t-sql-merge/
Msg 207, Level 16, State 1, Line 40
Invalid column name 'Current'.
Msg 207, Level 16, State 1, Line 38
Invalid column name 'Current'.
Msg 207, Level 16, State 1, Line 47
Invalid column name 'Current'.
Here is the code below...
--Create Temporaty table to hold dimension records
IF OBJECT_ID('tempdb..#DimVirtualQueue') IS NOT NULL
DROP TABLE #DimVirtualQueue;
CREATE TABLE #DimVirtualQueue
( [VQ_name] [varchar](50) NULL,
[contact_type] [varchar](50) NULL,
[center_node_id] [int] NULL,
[sed_id] [datetime] NULL,
[eed_id] [datetime] NULL,
[insert_date] [datetime] NULL,
[Current] [char](1) NOT NULL
INSERT INTO #DimVirtualQueue(VQ_name, contact_type, center_node_id, sed_id, eed_id, insert_date,[Current] )
SELECT VQ_name, contact_type, center_node_id, sed_id , eed_id,GETDATE(),'Y'
FROM
( --Declare Source and Target tables.
MERGE dbo.tblSwDM_dim_VQ_test AS TARGET
--Source
USING (SELECT
RTRIM(LTRIM(Stage.RESOURCE_NAME)) AS VQ_name,
'Unknown' AS contact_type,
0 AS center_node_id,
CONVERT(INT,CONVERT(VARCHAR(8),GMT_START_TIME,112)) AS sed_id,
CONVERT(INT,CONVERT(VARCHAR(8),ISNULL(GMT_END_TIME,'2070-01-01'),112)) AS eed_id,
GETDATE() AS insert_date
FROM dbo.tblGenesys_stg_RESOURCE_ Stage
WHERE resource_type = 'queue'
AND resource_subtype = 'VirtualQueue'
AND NOT EXISTS (SELECT 1 FROM dbo.tblSwDM_dim_VQ AS dim
WHERE RTRIM(LTRIM(stage.RESOURCE_NAME)) = RTRIM(LTRIM(dim.vq_name))) ) SOURCE
ON TARGET.VQ_name = SOURCE.VQ_name
WHEN NOT MATCHED BY TARGET
THEN
INSERT ( VQ_name, contact_type, center_node_id, sed_id, eed_id, insert_date,[Current] )
VALUES (SOURCE.VQ_name,SOURCE.contact_type,SOURCE.center_node_id,SOURCE.sed_id,SOURCE.eed_id,SOURCE.insert_date,'Y')
WHEN MATCHED AND TARGET.[Current] = 'Y'
AND EXISTS (
SELECT SOURCE.VQ_name
EXCEPT
SELECT TARGET.VQ_name
--Expire the records in target if exist in source.
THEN UPDATE SET TARGET.[Current] = 'N',
TARGET.[eed_id] = SOURCE.eed_id
OUTPUT $Action ActionOut, SOURCE.VQ_name,SOURCE.contact_type,SOURCE.center_node_id,SOURCE.sed_id,SOURCE.eed_id) AS MergeOut
WHERE MergeOut.ActionOut = 'UPDATE';
--Insert data into dimension
INSERT tblSwDM_dim_VQ_test
SELECT VQ_name,contact_type,center_node_id,sed_id,eed_id,insert_date,[Current] FROM #DimVirtualQueue
Any help to resolve issue is appreciated...
Thanks,
Vishal..You need to show the DDL of your target table: dbo.tblSwDM_dim_VQ_test.
Do you have a column named [Current] in this table? -
Missing keyword when try to use MERGE
I have COUNT_STATISTICS table that needs to be updated daily.
MODEL
NEW_COUNT
NEW_DATE
OLD_COUNT
OLD_DATE
PRNCT_CHANGE
XEDHRD
5206358
21-AUG-13
0
19-AUG-13
(null)
XLIMS
72669230
21-AUG-13
72669230
20-AUG-13
0
XEDHRD
5206358
22-AUG-13
5206358
21-AUG-13
0
XLIMS
72859644
22-AUG-13
72669230
21-AUG-13
0.262
so on and so forth...
Sometimes I have a new MODEL name coming in and I have to account for that and create a row in the table in that case.
Other times, all I have to do is INSERT new row in the table with new values.
Simple right?
Well, I was trying to use MERGE INTO but it is giving me problems...
This is what I did assuming I manually went in the table and added a new MODEL name and zeros for other columns before I did insertion...
#!/bin/bash
MODEL=$1
sqlplus -S username/password << EOF
whenever sqlerror exit 1;
set echo on
set verify off
INSERT INTO SEMANTIC.COUNT_STATISTICS(MODEL,NEW_COUNT,NEW_DATE,OLD_COUNT,OLD_DATE)
SELECT MODEL,
SELECT COUNT(*)
FROM TABLE(SEM_MATCH(
?s ?p ?o
}',SEM_Models('$MODEL'),NULL,
SEM_ALIASES(SEM_ALIAS('','http://VISION/DataSource/SEMANTIC#')),NULL))
SYSDATE,
NEW_COUNT,
NEW_DATE
FROM SEMANTIC.COUNT_STATISTICS
WHERE MODEL = '$MODEL'
AND NEW_DATE = (
select max(NEW_DATE)
from SEMANTIC.COUNT_STATISTICS
where MODEL = '$MODEL'
update SEMANTIC.COUNT_STATISTICS
set prnct_change =
(NEW_COUNT-OLD_COUNT)/NULLIF(OLD_COUNT,0)*100
where model = '$MODEL'
AND NEW_DATE = (
select max(NEW_DATE)
from SEMANTIC.COUNT_STATISTICS
where MODEL = '$MODEL'
COMMIT;
exit;
EOF
Now I added MERGE in front of INSERT so it checks if the MODEL name doesn't exist-it creates it:
MERGE INTO SEMANTIC.COUNT_STATISTICS s
USING (SELECT '${MODEL}' AS MODEL, 0 AS NEW_COUNT, SYSDATE AS NEW_DATE,
0 AS OLD_COUNT, SYSDATE AS OLD_DATE FROM dual) t
on (s.MODEL = t.MODEL)
when not matched then
INSERT (s.MODEL, s.NEW_COUNT, s.NEW_DATE, s.OLD_COUNT, s.OLD_DATE)
VALUES (t.MODEL, t.NEW_COUNT, t.NEW_DATE, t.OLD_COUNT, t.OLD_DATE);
My code combined...
#!/bin/bash
MODEL=$1
sqlplus -S username/password << EOF
whenever sqlerror exit 1;
set echo on
set verify off
MERGE INTO SEMANTIC.COUNT_STATISTICS s
USING (SELECT '${MODEL}' AS MODEL, 0 AS NEW_COUNT, SYSDATE AS NEW_DATE, 0 AS OLD_COUNT, SYSDATE AS OLD_DATE FROM dual) t
on (s.MODEL = t.MODEL)
when not matched then
INSERT (s.MODEL, s.NEW_COUNT, s.NEW_DATE, s.OLD_COUNT, s.OLD_DATE)
VALUES (t.MODEL, t.NEW_COUNT, t.NEW_DATE, t.OLD_COUNT, t.OLD_DATE);
exit;
EOF
model_exists () {
sqlplus -s username/password <<!
set heading off
set feedback off
set verify off
set pages 0
SELECT count(MODEL)
FROM SEMANTIC.COUNT_STATISTICS
where MODEL ='$MODEL' AND TO_DATE(NEW_DATE, 'DD-MON-YY') = TO_DATE(SYSDATE, 'DD-MON-YY');
exit;
modelcount=$(model_exists $1)
if [ "${modelcount:-0}" -ne 0 ]; then
sqlplus -S username/password << EOF
whenever sqlerror exit 1;
set echo on
set verify off
INSERT INTO SEMANTIC.COUNT_STATISTICS(MODEL,NEW_COUNT,NEW_DATE,OLD_COUNT,OLD_DATE)
SELECT MODEL,
SELECT COUNT(*)
FROM TABLE(SEM_MATCH(
'{?s ?p ?o }',SEM_Models('$MODEL'),NULL,
SEM_ALIASES(SEM_ALIAS('','http://VISION/DataSource/SEMANTIC#')),NULL))
SYSDATE,
NEW_COUNT,
NEW_DATE
FROM SEMANTIC.COUNT_STATISTICS
WHERE MODEL = '$MODEL'
AND NEW_DATE = (
select max(NEW_DATE)
from SEMANTIC.COUNT_STATISTICS
where MODEL = '$MODEL'
COMMIT;
exit;
EOF
else
sqlplus -S username/password << EOF
whenever sqlerror exit 1;
set echo on
set verify off
UPDATE COUNT_STATISTICS
SET MODEL = '$MODEL',
NEW_COUNT = (SELECT COUNT(*) FROM TABLE(SEM_MATCH('{?s ?p ?o}',SEM_Models('$MODEL'),NULL,
SEM_ALIASES(SEM_ALIAS('','http://VISION/DataSource/SEMANTIC#')),NULL))
NEW_DATE = SYSDATE,
OLD_COUNT = NEW_COUNT,
OLD_DATE = NEW_DATE
WHERE MODEL = '$MODEL'
AND NEW_DATE = (
select max(NEW_DATE)
from SEMANTIC.COUNT_STATISTICS
where MODEL = '$MODEL'
COMMIT;
exit;
EOF
fi
sqlplus -S username/password << EOF
whenever sqlerror exit 1;
set echo on
set verify off
update COUNT_STATISTICS
set prnct_change =
(NEW_COUNT-OLD_COUNT)/NULLIF(OLD_COUNT,0)*100
where model = '$MODEL'
AND NEW_DATE = (
select max(NEW_DATE)
from SEMANTIC.COUNT_STATISTICS
where MODEL = '$MODEL'
COMMIT;
exit;
EOF
But this is creating two rows if it is a new MODEL, ie:
./load_myScript.sh MODELNAME
MODEL
NEW_COUNT
NEW_DATE
OLD_COUNT
OLD_DATE
PRNCT_CHANGE
MODELNAME
72669230
22-AUG-13
0
22-AUG-13
(null)
MODELNAME
0
22-AUG-13
0
22-AUG-13
(null)
This is not what I want. I want to create a new row if it doesn't exist and then update that same one for that day. But tomorrow it should INSERT a new one for that same MODEL name.
Does anyone see what I am doing wrong?Hi,
MODEL is an Oracle keyword, so it causes confusion to have a column named MODEL. Errors like "Missing Keyword" can occur when Oracle thinks you're talking about the MODEL clause, rather than the column.
The best solution is not to use Oracle keywords (as found in v$reserverd words) for you own column names, or other identifiers. MODEL_NAME and MODEL_ID are good names for columns
If you really must use that column name, qualify it with the table name, and/or put the column name in double-quotes (case-sensitive), e.g.
count_statistics."MODEL" -
Alert On UDF's when Duplicate value exists
Hi Experts,
I want an Alerts message on a UDF's Gate Entry Pass (G.E. No), when any duplicate value is entered in this UDF's.
e.g.:- a value is entered in this udf is 30. when same value is entered it should give an alert that value already exists.
Thanks & Regards,
Pankaj Sharma.Hi Gordon,
I am using this UDF's on the GRPO Form and the UDF's name is U_GE_NO(Gate Entry No). my client uses this field when the material entered the company premises and entered the unique value. so to remove duplicacy in data the want the alert. -
Hi all,
I have created a form with one data block MATURED_FD_DTL which looks like below:
ACCT_FD_NO
CUST_CODE
FD_AMT
FD_INT_BAL
TDS
CHQ_NO
ADD_FD_AMT
P_SAP_CODE
P_TYPE
CREATE TABLE MATURED_FD_DTL
ACCT_FD_NO VARCHAR2(17 BYTE) NOT NULL,
CUST_CODE NUMBER(9),
FD_AMT NUMBER(15),
FD_INT_BAL NUMBER(15),
TDS NUMBER(15),
CHQ_NO NUMBER(10),
ADD_FD_AMT NUMBER(15),
P_SAP_CODE NUMBER(10),
P_TYPE VARCHAR2(1 BYTE)
For MATURED_FD_DT.ACCT_FD_NO, Trigger: KEY_NEXT_ITEM, I have written the following code:
DECLARE
V1 NUMBER;
V2 NUMBER;
BEGIN
V1:=:MATURED_FD_DTL.ACCT_FD_NO;
MESSAGE('V1:'||V1);
MESSAGE(' ');
END;
GO_ITEM('MATURED_FD_DTL.CUST_CODE');
This is just a dummy code.
When ever i enter the value in the field of ACCT_FD_NO, it pops up a message saying "V1:Value of ACCT_FD_NO",
So i want to store that value .
Compare them & if it is egual, it should pop up a message saying duplicate value is entered and must not allow to enter, at form_level.
So how can I compare the ACCT_FD_NO value between FIRST_RECORD and NEXT_RECORD ??
Help Me .
Thank You.
Oracle Forms 6i.
Oracle 9i.Thank You HamidHelal.
Actually before posting the code, I went through the first link you have mentioned. I tried also, it is quite tedious procedure, however i dint get the proper result, may be i have done some mistake. Anyways , can you tell me how do i check in database table, if a value exists OR IF VALUE FOUND & then message and raise form trigger failure; something like below.
IF :MATURED_FD_DTL.ACCT_FD_NO EXISTS
THEN MESSAGE('YOU HAVE ENTERED AN EXISTING OR DUPLICATE VALUE');
MESSAGE(' ');
RAISE FORM_TRIGGER_FAILURE;
END;
OR
IF :MATURED_FD_DTL.ACCT_FD_NO FOUND
THEN MESSAGE('YOU HAVE ENTERED AN EXISTING OR DUPLICATE VALUE');
MESSAGE(' ');
RAISE FORM_TRIGGER_FAILURE;
END;
Is there any equivalent in the form in oracle forms 6i?? Please let me know how do i do this?? -
#Error & #Syntax when we are using merged dimension in BO4.1 SP3
Dear All,
We are using BO4.1 SP3 and Bex query as datasource.
When we are trying to take merged dimensions in Report block its giving #Syntax Error.
When we are defining variable with merged dimension, its giving #Error message and the merged dimension is deleted from the definition.
Please guide how can I use merged dimension.
Kindly let us know if there are some update required in the current BO version.
Warm Regards,
SonalFirst things abt merge dimension is that merge is applicable only on dimension not on measures.
And other is dimension that are going to be merge should have same data type.
I think you should check these conditions then it will works.
Merge is nothing but full outer join between two data providers. It helps joining two result sets on webi level.
Kindly attach your screen shots so that it would be helpful. -
When do we use Non-Cumulative values?
Hi BW Experots?
When do we use Non-Cumulative values?How is it related with exception aggregation
Please tell me .
Thanks in anticipation.Hi,
Taken from std, doc....
A non-cumulative is a non-aggregating key figure on the level of one or more objects that is always displayed in relation to time. Examples of non-cumulatives include headcount, account balance and material inventory.
http://help.sap.com/saphelp_nw04/helpdata/en/8f/da1640dc88e769e10000000a155106/frameset.htm
Check this out...
http://help.sap.com/saphelp_nw04/helpdata/en/80/1a62dee07211d2acb80000e829fbfe/frameset.htm
Pls. assign points if this helps you.. ****
Thanks,
Raj
Maybe you are looking for
-
Is there a way to make rollovers activate one after another?
This is an assignment for class. We need to have rollovers and what not. My problem is the links are all active at the same time and really mess with the story. is there anyway i could get them to activate in the order all the rollovers are in. I als
-
Vncserver not working for me in latest solaris 10 on sparc
Hello, This is Solaris 10 running on <142909-17> sun4u sparc SUNW,Sun-Fire-V440 When I(non root user) run vncserver, I get below message, New 'servername:1 (nonrootuser)' desktop is servername:1 Starting applications specified in /home/nonrootuser/.v
-
On the Zen Touch 20GB player, is the battery removable?
-
Hi, For some graphical user interface, I was overriding PaintComponent() method with Graphics argument and then using drawLine() method of Graphics class of Java. It worked in the way I wanted. However, the lines drawLine() method draws are too thin.
-
WP 8.1 Emulator not working on Windows 8.1 x64
Windows Phone 8.1 Emulator not working on Windows 8.1 x64 Ram 2GB,Hyper-V is enabled Error:Windows Phone Emulator is unable to set some properties on the virtual machine : 1.Couldn't change memory of virtual machine'xyxyxyxyxyxyyxyx' failed to modif