I wanted to optimize an update query.
Hi,
I have an update statement which i am executing using batchUPdate command.
this is my update statement -
UPDATE SELMDBO.cm_selm_gblnet_dse_data1
SET facility_id = ?,
client_oid =?
WHERE parent_ucn = ?
AND run_no = ?
i am using the java to update this query in batch.
but it is taking very large time to update 20000 records ( almost 2461419 ms)
i have put seperate indexes on facility_id , client_oid , parent_ucn and run_no
but it is not working i guess.
Is there any way i can optimize this update...
Thanks,
Sumit
Hi Helio,
Thanks for your quick response.
there are 98000 row in this table..
i am updating 20000 records with 5000 records at a time. so 4 time i am executing update statement . one update causing me half n hour which is too much for me..
this is the explain plan currently.
Plan
UPDATE STATEMENT ALL_ROWSCost: 121
3 UPDATE SELMDBO.CM_SELM_GBLNET_DSE_DATA1
2 TABLE ACCESS BY INDEX ROWID TABLE SELMDBO.CM_SELM_GBLNET_DSE_DATA1 Cost: 121 Bytes: 2,091 Cardinality: 41
1 INDEX RANGE SCAN INDEX SELMDBO.CM_SELM_GBLNET_DSE_DATA_IDX2 Cost: 111 Cardinality: 17,178
Please let me know if you need more information on this..
Similar Messages
-
Optimization of Update Query???
Hello guys!
I just finished writing an update query, which works but takes forever (approximately 20-30 seconds). Do you have any ideas how it can be optimized in order to run faster? Would it be reccomendable to create a new view that includes only the required columns for the Inner-Select Statement? Right now there are about 20 columns in VT_TBL_PUNKTDATEN_JOIN. Could the statement be written differently to speed up the execution???
Here is the statement:
begin
UPDATE TBL_PUNKTDATEN v SET v.INT_ZAEHLFAKTOR_BESTAND = :P700_INT_ZAEHLFAKTOR_BESTAND
WHERE EXISTS (SELECT p.INV_PT_ID_SUB FROM VT_PUNKTDATEN_JOIN p WHERE
(p.STR_GEBIET_MAIN = :P700_STR_GEBIET) and (p.STR_LRT_MAIN = :P700_STR_LRT) and (v.INV_PT_ID_SUB = p.INV_PT_ID_SUB));
end;I'm really curious if you have any solution for this!
I Appreciate your effort!
Bye,
Sebastianskahlert wrote:
@ Sven W.
I receive an ORA-01779 error (cannot modify a column which maps to a non key-preserved table).I thought that this would happen (based on your table names), but it was worth a try.
The problem is which table is the parent and which one is the child table. When joining two tables via a foreign key relationship the child table will be the so-called key-preserved table. This means one row from the source table can be matched to exactly one row in the joined output (=view).
In your case you can't use the update construct I suggested. It would work if you want to update the other table p.
However you could measure how long the join select is running and compare that to the update part. This can give a first indication if the select is slow or the update.
A further try can be to change the correlated subquery into an uncorrelated subquery. I doubt that this will help since the oracle optimzier can do this transformation by itself. Other than that you need to give us more information about table sizes and execution plans. You can always trace the update and see where the time is spent.
uncorrelated
UPDATE TBL_PUNKTDATEN v
SET v.INT_ZAEHLFAKTOR_BESTAND = :P700_INT_ZAEHLFAKTOR_BESTAND
WHERE v.INV_PT_ID_SUB IN (SELECT p.INV_PT_ID_SUB FROM VT_PUNKTDATEN_JOIN p
WHERE p.STR_GEBIET_MAIN = :P700_STR_GEBIET
and p.STR_LRT_MAIN = :P700_STR_LRT);Edited by: Sven W. on Aug 19, 2009 1:17 PM -
Performance optimization on select query for all entries
Hi All,
I want to optimize the select query in my Program.
The select query is taking lot of time to search the records for the given condition in the where clause
and more interestingly there are no records fetched from the database as the where condition does not matches.
It is taking more than 30 min to search the record and the result is no record found.
Below is my select query. I have also created the secondary Index for the same.
In My opinion FOR ALL ENTRIES is taking lot of time. Because there are more than 1200 records in internal table t_ajot
select banfn bnfpo bsart txz01 matnr Werks lgort matkl reswk menge meins flief ekorg
INTO CORRESPONDING FIELDS OF TABLE t_req
FROM eban
FOR ALL ENTRIES IN t_ajot
WHERE matkl >= t_ajot-matkl_low
AND matkl <= t_ajot-matkl_high
AND werks = t_ajot-werks
AND loekz = ' '
AND badat IN s_badat
AND bsart = 'NB'.
Please suggest.Hi,
that,
FOR ALL ENTRIES IN t_ajot
WHERE matkl >= t_ajot-matkl_low
AND matkl <= t_ajot-matkl_high
AND werks = t_ajot-werks
AND loekz = ' '
AND badat IN s_badat
AND bsart = 'NB'.
looks strange.
However:
How does your index look like?
What executoin plan do you get?
How do the statistics look like?
Whats the content of the variables t_ajot-... and s_badata?
Kind regards,
Hermann -
I want single update query without use the function.
I want to update sells_table selling_code field with max date product_code from product table.
In product table there is multiple product_code date wise.
I have been done it with below quey with the use of function but can we do it in only one update query
without use the function.
UPDATE sells_table
SET selling_code = MAXDATEPRODUCT(ctd_vpk_product_code)
WHERE NVL(update_product_flag,0) = 0 ;
CREATE OR REPLACE FUNCTION HVL.maxdateproduct (p_product IN VARCHAR2) RETURN NUMBER
IS
max_date_product VARCHAR2 (100);
BEGIN
BEGIN
SELECT NVL (TRIM (product_code), 0)
INTO max_date_product
FROM (SELECT product_code, xref_end_dt
FROM product
WHERE TO_NUMBER (p_product) = pr.item_id
ORDER BY xref_end_dt DESC)
WHERE ROWNUM = 1; -- It will return only one row - max date product code
EXCEPTION
WHEN OTHERS
THEN
RETURN 0;
END;
RETURN max_date_product;
END maxdateproduct;
Thanks in Advance.Hi,
Something like this.
update setlls_table st
set selling_code =(select nvl(trim(product_code)) from
(select product_code
, rank() over (partition by item_id order by xref_end_dt DESC) rn
from product
) pr
where rn =1
and pr.item_id = st.ctd_vpk_product_code
) where NVL(update_product_flag,0) = 0 ;As such not tested due to lack of input sample.
Regards
Anurag Tibrewal. -
Hi,
I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work
(fault number -2147217900)
I want to search for a value in a ms access table , if it exist i want to update it, if not i want to insert a new row.
Working with LabView 7.1, database con. toolset.
Who can HELP?
Thanks a lot
MarcoHello,
I think that If exist is not a standar SQL command (I know it exists I think in Oracle and SQL server), MS access doesn't support it, so I think the best way to do it is first make a Select and then either an Update or an insert, sorry...
Paulo -
Update Query is Performing Full table Scan of 1 Millions Records
Hello Everyboby I have one update query ,
UPDATE tablea SET
task_status = 12
WHERE tablea.link_id >0
AND tablea.task_status <> 0
AND tablea.event_class='eventexception'
AND Exists(SELECT 1 from tablea ltask where ltask.task_id=tablea.link_id
AND ltask.task_status = 0)
When I do explain plan it shows following result...
Execution Plan
0 UPDATE STATEMENT Optimizer=CHOOSE
1 0 UPDATE OF 'tablea'
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'tablea'
4 2 TABLE ACCESS (BY INDEX ROWID) OF 'tablea'
5 4 INDEX (UNIQUE SCAN) OF 'PK_tablea' (UNIQUE)
NOW tablea may have more than 10 MILLION Records....This would take hell of time even if it has to
update 2 records....please suggest me some optimal solutions.....
Regards
MaheshI see your point but my question or logic say i have index on all columns used in where clauses so i find no reason for oracle to do full table scan,,,,
UPDATE tablea SET
task_status = 12
WHERE tablea.link_id >0
AND tablea.task_status <> 0
AND tablea.event_class='eventexception'
AND Exists(SELECT 1 from tablea ltask where ltask.task_id=tablea.link_id
AND ltask.task_status = 0)
I am clearly statis where task_status <> 0 and event_class= something and tablea.link_id >0
so ideal case FOR optimizer should be
Step 1)Select all the rowid having this condition...
Step 2)
For each row in rowid get all the row where task_status=0
and where taskid=linkid of rowid selected above...
Step 3)While looping for each rowid if it find any condition try for rowid obtained from ltask in task 2 update that record....
I want to have this kind of plan,,,,,does anyone know how to make oracle obtained this kind of plan......
It is try FULL TABLE SCAN is harmfull alteast not better than index scan..... -
SQLSERVER to ORACLE conversion - Update query
Hi,
I have a query in sqlserver :
UPDATE
netVIEWplus.dbo.DIM_OUC_Latest
SET
OUC = LatestFixed.OUC,
OUC_Desc = LatestFixed.OUC_Desc,
OUC_Level = LatestFixed.OUC_Level,
Parent_OUC = LatestFixed.Parent_OUC,
CC_Type = LatestFixed.CC_Type,
GFR = LatestFixed.GFR,
CORP = LatestFixed.CORP,
SOB = LatestFixed.SOB,
Div_Unit = LatestFixed.Div_Unit,
Div_Desc = LatestFixed.Div_Desc,
L1_OUC = LatestFixed.L1_OUC, L1_DEPT_DESC = LatestFixed.L1_DEPT_DESC,
L2_OUC = LatestFixed.L2_OUC, L2_DEPT_DESC = LatestFixed.L2_DEPT_DESC,
L3_OUC = LatestFixed.L3_OUC, L3_DEPT_DESC = LatestFixed.L3_DEPT_DESC,
L4_OUC = LatestFixed.L4_OUC, L4_DEPT_DESC = LatestFixed.L4_DEPT_DESC,
L5_OUC = LatestFixed.L5_OUC, L5_DEPT_DESC = LatestFixed.L5_DEPT_DESC,
L6_OUC = LatestFixed.L6_OUC, L6_DEPT_DESC = LatestFixed.L6_DEPT_DESC,
L7_OUC = LatestFixed.L7_OUC, L7_DEPT_DESC = LatestFixed.L7_DEPT_DESC,
L8_OUC = LatestFixed.L8_OUC, L8_DEPT_DESC = LatestFixed.L8_DEPT_DESC,
Current_Flag = LatestFixed.Current_Flag,
INF_Div_Unit_Only = LatestFixed.INF_Div_Unit_Only,
INF_DIM_OUC_Id_Used = LatestFixed.DIM_OUC_Id
FROM
netVIEWplus.dbo.DIM_OUC_Latest
INNER JOIN
netVIEWplus.dbo.DIM_OUC HistoryDIM
ON
HistoryDIM.DIM_OUC_Id = netVIEWplus.dbo.DIM_OUC_Latest.DIM_OUC_Id
INNER JOIN
netVIEWplus.dbo.DIM_OUC LatestDIM
ON
LatestDIM.DIM_OUC_ID = HistoryDIM.Latest_Id
INNER JOIN
netVIEWplus.dbo.DIM_OUC LatestFixed
ON
netVIEWplus.dbo.DIM_OUC_Latest.OUC = LatestFixed.OUC
WHERE
LatestDIM.INF_Updateable = 1
AND
LatestFixed.Valid_From =
SELECT MAX(Valid_From)
FROM netVIEWplus.dbo.DIM_OUC
WHERE OUC = LatestFixed.OUC
AND INF_Updateable = 0
Which I want to convert in oracle like below :
UPDATE
netVIEWplus.DIM_OUC_Latest T1
SET (OUC,OUC_Desc,OUC_Level,Parent_OUC,CC_Type,GFR,CORP,SOB,Div_Unit,Div_Desc,L1_OUC,L1_DEPT_DESC,L2_OUC,
L2_DEPT_DESC,L3_OUC,L3_DEPT_DESC,L4_OUC,L4_DEPT_DESC,L5_OUC,L5_DEPT_DESC,L6_OUC,L6_DEPT_DESC,L7_OUC,L7_DEPT_DESC,
L8_OUC,L8_DEPT_DESC,Current_Flag,INF_Div_Unit_Only,INF_DIM_OUC_Id_Used) =
(SELECT LatestFixed.OUC OUC,LatestFixed.OUC_Desc OUC_Desc,
LatestFixed.OUC_Level OUC_Level,LatestFixed.Parent_OUC Parent_OUC,LatestFixed.CC_Type CC_Type,LatestFixed.GFR GFR,
LatestFixed.CORP CORP,LatestFixed.SOB SOB,LatestFixed.Div_Unit Div_Unit,LatestFixed.Div_Desc Div_Desc,
LatestFixed.L1_OUC L1_OUC,LatestFixed.L1_DEPT_DESC L1_DEPT_DESC,LatestFixed.L2_OUC L2_OUC,LatestFixed.L2_DEPT_DESC L2_DEPT_DESC,
LatestFixed.L3_OUC L3_OUC,LatestFixed.L3_DEPT_DESC L3_DEPT_DESC,LatestFixed.L4_OUC L4_OUC,
LatestFixed.L4_DEPT_DESC L4_DEPT_DESC,LatestFixed.L5_OUC L5_OUC,LatestFixed.L5_DEPT_DESC L5_DEPT_DESC,
LatestFixed.L6_OUC L6_OUC,LatestFixed.L6_DEPT_DESC L6_DEPT_DESC,LatestFixed.L7_OUC L7_OUC,
LatestFixed.L7_DEPT_DESC L7_DEPT_DESC,LatestFixed.L8_OUC L8_OUC,LatestFixed.L8_DEPT_DESC L8_DEPT_DESC,
LatestFixed.Current_Flag Current_Flag,LatestFixed.INF_Div_Unit_Only INF_Div_Unit_Only,
LatestFixed.DIM_OUC_Id INF_DIM_OUC_Id_Used
FROM
netVIEWplus.DIM_OUC HistoryDIM,netVIEWplus.DIM_OUC LatestDIM,netVIEWplus.DIM_OUC LatestFixed
where
HistoryDIM.DIM_OUC_Id = T1.DIM_OUC_Id
AND
LatestDIM.DIM_OUC_ID = HistoryDIM.Latest_Id
and
T1.OUC = LatestFixed.OUC
and
LatestFixed.INF_Updateable = 1
AND
LatestFixed.Valid_From =
SELECT MAX(Valid_From)
FROM netVIEWplus.DIM_OUC
WHERE OUC = LatestFixed.OUC
AND INF_Updateable = 0
and rownum=1)
where exists
(SELECT 1
FROM
netVIEWplus.DIM_OUC HistoryDIM,netVIEWplus.DIM_OUC LatestDIM,netVIEWplus.DIM_OUC LatestFixed
where
HistoryDIM.DIM_OUC_Id = T1.DIM_OUC_Id
AND
LatestDIM.DIM_OUC_ID = HistoryDIM.Latest_Id
and
T1.OUC = LatestFixed.OUC
and
LatestFixed.INF_Updateable = 1
AND
LatestFixed.Valid_From =
SELECT MAX(Valid_From)
FROM netVIEWplus.DIM_OUC
WHERE OUC = LatestFixed.OUC
AND INF_Updateable = 0
Problem is, it is taking long time to execute in oracle. Find the explain plan of the oracle query :
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
UPDATE STATEMENT Optimizer Mode=ALL_ROWS 1 19 M
UPDATE NETVIEWPLUS.DIM_OUC_LATEST
HASH JOIN SEMI 1 216 19 M
TABLE ACCESS FULL NETVIEWPLUS.DIM_OUC_LATEST 299 K 55 M 1550
VIEW SYS.VW_SQ_3 4 G 90G 12 M
HASH JOIN 4 G 208G 12 M
TABLE ACCESS FULL NETVIEWPLUS.DIM_OUC 298 K 2 M 2009
MERGE JOIN CARTESIAN 4 G 167G 1664177
HASH JOIN 14 K 516 K 4873
TABLE ACCESS FULL NETVIEWPLUS.DIM_OUC 53 K 945 K 2030
VIEW SYS.VW_SQ_2 81 K 1 M 2841
SORT GROUP BY 81 K 1 M 2841
TABLE ACCESS FULL NETVIEWPLUS.DIM_OUC 245 K 4 M 2030
BUFFER SORT 298 K 1 M 1664177
INDEX FAST FULL SCAN NETVIEWPLUS.DIM_OUC_PK 298 K 1 M 113
COUNT STOPKEY
NESTED LOOPS 1 253 4062
NESTED LOOPS 1 235 2032
NESTED LOOPS 1 15 2
TABLE ACCESS BY INDEX ROWID NETVIEWPLUS.DIM_OUC 1 10 2
INDEX UNIQUE SCAN NETVIEWPLUS.DIM_OUC_PK 1 1
INDEX UNIQUE SCAN NETVIEWPLUS.DIM_OUC_PK 298 K 1 M 0
TABLE ACCESS FULL NETVIEWPLUS.DIM_OUC 1 220 2030
VIEW SYS.VW_SQ_1 1 18 2030
SORT GROUP BY 3 54 2030
TABLE ACCESS FULL NETVIEWPLUS.DIM_OUC 3 54 2030
Can any one suggest how to efficiently write the update query.
Regards,
KoushikHi,
Have you gathered stats as well ? Did the query use index(es) as well ?
Without any more info like explain plan, indexes, etc., further help will be unable.
Nicolas. -
Insert and update query to calculate the opening and closing balance
create table purchase(productid number(5) ,dateofpurchase date,
qty number(5));
create table inventory(invid number(5),productid number(5),
idate date,openingqty number(5),closingqty number(5));
Records in inventory:
1,1,'01-jan-2009', 10, 20
2,1,'03-jan-2009', 20, 30
3,1,'04-jan-2009', 40, 50
when I enter the purchase invoice for 15 qty on 02-jan-2009
after say '15-jan-09' , a new record should get inserted
with opening balance = (closing balance before 02-jan-2009)
and all the opening and closing balance for that product should
get affected.
If the invoice for 20 qty is entered for the existing date say
'03-jan-2009' in inventory , then the closing balance
for 03-jan-2009 should get updated and all the following records
should get affected.
I need the insert for the first one and update query for the
second one.
Vinodh<strike>You can do this in one statement by using the merge statement</strike>
Hmm, maybe I spoke too soon.
Edited by: Boneist on 25-Sep-2009 13:56
Thinking about it, why do you want to design your system like this?
Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
Edited by: Boneist on 25-Sep-2009 13:59 -
Hello,
I was hoping anyone could provide ideas on the best way to do an update query based on an if then else statement I am using Oracle 11 on a linux server. I am writing within a perl script. I've researched online and saw some examples using case. Below is the basic query logic I am trying to implement. I would really appreciate any suggestions.
Thanks,
JC
If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') and askme_temp.CKT_ID = heci.CKT_ID then SUBPRODUCT =’IPAG’
ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') AND REGION=’SE’ then SUBPRODUCT =’METRO_E’
ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') then SUBPRODUCT =’OPT_E_MAN’Hi,
Welcome to the forum!
CASE sounds like a good idea to me.
For example:
UPDATE table_x
SET subproduct = CASE
WHEN askme_temp.CKT_ID = heci.CKT_ID
THEN 'IPAG'
WHEN region = 'SE'
THEN 'METRO_E'
ELSE 'OPT_E_MAN'
END
WHERE maint_center IN ( 'ENOC1CENTER'
, 'PMCTGAAHSDC'
, 'ATTCSPCRT01'
, 'ATTCSPCWS01'
, 'NTNLWHS4NSA'
AND cac1 = 'S'
AND SUBST (ckt_id, 4, 2) IN ('KQ', 'KR', 'KS', 'KP', 'L1', 'L2', 'L3', 'VL')
AND ...
;CASE expressions are evaluated in the order in which you write them, so if askme_temp.ckt_id = heci.ckt_id (whatever those things are), subproduct will be set to 'IPAG'. It won't matter whether region is 'METRO_E' or not; if the 1st condition is TRUE, the first THEN value is returned, and the other WHEN expressions aren't even evaluated.
What do you want to do if none of those conditions are met?
Any conditions that are common to all the rows being UPDATEd can be put in the WHERE clause; they don't have to be repeated in the CASE expression.
Remember, MERGE is often more convenient to use than UPDATE.
Edited by: Frank Kulash on Jul 27, 2011 3:23 PM -
Can we improve further this update query
Can we optimize the following query further.
UPDATE OPTPRC_CHANGES_PK
SET UPDATEFLAG_ = 'X'
WHERE (UPDATEFLAG_ = 'U' OR UPDATEFLAG_ = 'A')
AND EXISTS
( SELECT 1 FROM OPTPRC
WHERE OPTPRC.DATE_ = OPTPRC_CHANGES_PK.DATE_
AND OPTPRC.EXCHCODE = OPTPRC_CHANGES_PK.EXCHCODE
AND OPTPRC.CONTRCODE = OPTPRC_CHANGES_PK.CONTRCODE )
The OPTPRC table contains about 10 million rows and OPTPRC_CHANGES_PK table contains about 1.5 million rows. The query takes about 20 minutes to complete. Ouch.
The index (Date_,Exchcode,contrcode) is in place on both tables.
Query Plan_
According to query plan, it is not using any indexes. Hash semi join is being used and table are fully scanned.
Oracle 10g is being used on Solaris 10.
Can we improve this query.Following is th query plan for the query poposed by SeánMacGC
Query Plan
PLAN_TABLE_OUTPUT
Plan hash value: 72452462
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (
| 0 | UPDATE STATEMENT | | 1558K| 53M| | 29378
| 1 | UPDATE | OPTPRC_CHANGES_PK | | | |
|* 2 | HASH JOIN | | 1558K| 53M| 44M| 29378
|* 3 | TABLE ACCESS FULL| OPTPRC_CHANGES_PK | 1521K| 27M| | 2137
| 4 | TABLE ACCESS FULL| OPTPRC | 9968K| 161M| | 11182
Predicate Information (identified by operation id):
2 - access("OPTPRC"."DATE_"="OPTPRC_CHANGES_PK"."DATE_" AND
"OPTPRC"."EXCHCODE"="OPTPRC_CHANGES_PK"."EXCHCODE" AND
"OPTPRC"."CONTRCODE"="OPTPRC_CHANGES_PK"."CONTRCODE")
3 - filter("OPTPRC_CHANGES_PK"."UPDATEFLAG_"='A' OR
"OPTPRC_CHANGES_PK"."UPDATEFLAG_"='U') -
We have an update query recently brought to my attention that is running extremely slow on Oracle 11.2.0.1 against a secure file binary XML table using
update /*+ NO_XML_DML_REWRITE */croutreach.action set object_value = :1 where actn_id = :2 .
I am told the majority/near majority of the ~ 16 fields are updated. Also this table has numerous predefined virtual columns with fn based indexes on them.
My first inclination was to recast this using the Oracle updatexml function. I was told, the /*+ NO_XML_DML_REWRITE */ hint would also be necessary here.
update /*+ NO_XML_DML_REWRITE */
<tble_name> a
set a.object_value = updatexml(a.object_value ...).
Last year our dba's were instructed by Oracle Support to use this hint, as the update wasn't updating any records w.o any error msgs.
+1. Hoping to find out if anyone has run across using this hint in some capacity and what was their experience?+
In trying to optimizie this update statement, I'll start from scratch not using the /*+ NO_XML_DML_REWRITE */ hint and will commence with using the updatexml function with setting up an xmlindex.
+2. Hoping to receive some suggestions on creating the proper xmlindex - figuring an unstructured index. If get some good performance with the xmlindex; hoping to retire some of the virtual column usage.+
+3. Any suggestions on living with virtual columns in conjunction with xmlindexes? See the action table definition and associated ivirtual columns and indexes. This table seems over indexed...+
REATE
TABLE "CROUTREACH"."ACTION" OF XMLTYPE
CONSTRAINT "ACTN_ID_PK" PRIMARY KEY ("ACTN_ID") USING INDEX PCTFREE 10
INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT
1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1
FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE
DEFAULT) TABLESPACE "ACME_DATA" ENABLE
XMLTYPE STORE AS SECUREFILE BINARY XML
TABLESPACE "ACME_DATA" ENABLE STORAGE IN ROW CHUNK 8192 CACHE READS LOGGING
NOCOMPRESS KEEP_DUPLICATES STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1
MAXEXTENTS 2147483645 PCTINCREASE 0 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT)
ALLOW NONSCHEMA ALLOW ANYSCHEMA VIRTUAL COLUMNS
*"ACTION_DEF_URN"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/srvContextPointer/outreachActionDefInfo/@actionDefUrn
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50))),
*"STAT_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/@status_dt'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
WITH
TIME ZONE))),
*"ACT_DEF_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/srvContextPointer/outreachActionDefInfo/@actionDefId'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(20))),
*"CORRL_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/correlationId'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50))),
*"STAT_RSN"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/statusReason'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(30))),
*"ACT_APPNT_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/actionAppointment/appointment_dt'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
WITH
TIME ZONE))),
*"UPDT_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/@update_dt'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
WITH
TIME ZONE))),
*"CRET_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/@create_dt'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
WITH
TIME ZONE))),
*"ACT_SEQ"* AS (CAST(TO_NUMBER(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/srvContextPointer/outreachActionDefInfo/@sequence'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2)) AS NUMBER(10))),
*"SERVICE_DEF_URN"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";
/action/srvContextPointer/serviceDefUrn'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(100))),
*"ASSIGN_TEAM_CD"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/assignment/@teamCategoryCode'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50))),
*"ASSIGN_STAFF_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
/action/assignment/staffProfileId'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50))),
*"ACTION_TYPE"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)
declare namespace xsi="http://www.w3.org/2001/XMLSchema-instance"; (::)
local-name-from-QName(QName("http://www.cigna.com/acme/domains/actions/2010/03",/action/@xsi:type))
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50))),
*"ACTN_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";/action/@id'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50))),
*"STATUS"*AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";/action/@status'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(20))),
*"ACME_MBR_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";/action/acmeMemberId'
PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
16777216,0),50,1,2) AS VARCHAR2(50)))
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE UNIQUE INDEX *"CROUTREACH"."SYS_C0014547"* ON "CROUTREACH"."ACTION"
"SYS_NC_OID$"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE UNIQUE INDEX *"CROUTREACH"."SYS_IL0000082156C00003$$"* ON "CROUTREACH".
"ACTION"
PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576
MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST
GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "ACME_DATA" PARALLEL (DEGREE 0 INSTANCES 0) ;
CREATE UNIQUE INDEX *"CROUTREACH"."ACTN_ID_PK"* ON "CROUTREACH"."ACTION" (
"ACTN_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT) TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACTION_STAT_RSN_IDX"* ON "CROUTREACH"."ACTION"
"STAT_RSN"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACTION_UPDT_DT_IDX"* ON "CROUTREACH"."ACTION"
"UPDT_DT"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACTION_CRET_DT_IDX"* ON "CROUTREACH"."ACTION"
"CRET_DT"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACTION_STAT_DT_IDX"* ON "CROUTREACH"."ACTION"
"STAT_DT"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACTION_MBRID_TYP_STAT_IDX"* ON "CROUTREACH"."ACTION"
"ACME_MBR_ID",
"ACTION_TYPE",
"STATUS"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACT_ACTDEF_URN_IDX"* ON "CROUTREACH"."ACTION"
"ACTION_DEF_URN"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;
CREATE
INDEX *"CROUTREACH"."ACTION_ACT_DEF_ID_STATUS_IDX"* ON "CROUTREACH"."ACTION"
"ACT_DEF_ID",
"STATUS"
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
TABLESPACE "ACME_DATA" ;Any suggestions much appreciated.
Regards,
Richard Blanchardodie 63
update /*+ NO_XML_DML_REWRITE */croutreach.action set object_value = :1 where actn_id = :2 .
This update pattern is used in the production environment and is slowing the environment down as more xml content is increased. In a new release build, this update pattern against the action table described earlier, is particularly problematic.
Have some more information on the /*+ NO_XML_DML_REWRITE */ hint. It turns out, last year, updates statements would intermittently fail to correctly update silently failing. An Oracle Service Request was created. Over the span of about 5 mnths, Oracle determined a very low level Oracle kernel bug was the culprit. Oracle As a result of this SR, Oracle SUpport created BUG 11939507 <ORA-08102: index key not found during update on xmltable with a virtual column>. This bug is viewable on metalink. Oracle claims this bug has only been oberved on In the interim to 11.2.0.3, Oracle Support mentioned to use /*+ NO_XML_DML_REWRITE */; thus disabling piecewise update.
Here's preface information on this bug:
Bug 11939507: ORA-08102: INDEX KEY NOT FOUND DURING UPDATE ON XMLTABLE WITH VIRTUAL COLUMN
Bug Attributes
Type B - Defect Fixed in Product Version 12.1
Severity 2 - Severe Loss of Service Product Version 11.2.0.1
Status 80 - Development to Q/A Platform 23 - Oracle Solaris on SPARC (64-bit)
Created 30-Mar-2011 Platform Version 10
Updated 13-Feb-2012 Base Bug -
Database Version 11.2.0.1
Affects Platforms Generic
Product Source Oracle
Hdr: 11939507 11.2.0.1 XDB 11.2.0.1 BINARY PRODID-5 PORTID-23
Abstract: ORA-8102: INDEX KEY NOT FOUND DURING UPDATE ON XMLTABLE WITH VIRTUAL COLUMN*** 03/30/11 12:22 pm ***
BUG TYPE CHOSEN =============== code
Component: XML Database =======================
DETAILED PROBLEM DESCRIPTION ============================
The issue happens intermittently when running a batch program with 50 concurrent sessions that involves high concurrent updates.
DIAGNOSTIC ANALYSIS =================== reproducible testcase on customer dummy data reproduced by Thomas.
WORKAROUND? =========== No
TECHNICAL IMPACT ================ Customer is experiencing this error which is critical to the application because it causes a home health care provider to possibly lose a couple hours worth of work and have to start from scratch. The condition has only accessed concurrently from about 40 threads
RELATED ISSUES (bugs, forums, RFAs) =================================== Bug 8514561 - ORA-8102 WHEN UPDATING TABLE
HOW OFTEN DOES THE ISSUE REPRODUCE AT CUSTOMER SITE? ==================================================== Intermittent
DOES THE ISSUE REPRODUCE INTERNALLY? ==================================== Intermittent
IS A TESTCASE AVAILABLE? ======================== Yes The good news is, this bug is corrupting a virtual index column.
I'll try test cases using the update pattern; 'update /*+ NO_XML_DML_REWRITE */croutreach.action set object_value = :1 where actn_id = :2 ' - substituting actual values for the bind variables and removing interfering virtual columns. Wil lcompare with and w/o the hint.
This wil address your; "Where does the new values come from? Individual variables?" - and provide sample data.
Presently, this update pattern is used 'blindly' in that when no xml relevent changes are identified, only a couple of the roughly 16 fields are updated - yet the whole document gets updated with this update pattern. When changes occur, the whole document is updated. Will work with updating 1 or 2 fields using updatexml and try the xmlexists function for the predicate.
04/25/12 Update:
odie 63,
Here's a sample xml record from the action securefile binary xml table:
<?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?><action xsi:type="AssessmentActionType" status_dt="2012-01-18T19:38:21.077Z" status="not applicable" create_dt="2012-01-17T23:10:16.173Z" id="dfdfdfdfdfddfdfdfdfdfdf" xmlns:ns5="http://www.xxxxx.ddd/exception/definition/schema/2010/01" xmlns="http://www.xxxxxx.ddd/mmm/domains/actions/2010/03" xmlns:ns6="http://www.xxxxx.ddd/mmm/domains/utility/outcome/2010/03" xmlns:ns7="http://www.xxxxxx.ddd/mmm/domains/common/2010/03" xmlns:ns2="http://www.xxxxx.ddd/mmm/messages/actions/2010/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.xxxxx.ddd/mmm/domains/workforce/2010/03" xmlns:ns4="http://www.xxxxxx.ddd/mmm/domains/entitlement/2011/11">
<acmeMemberId>abcdefghijklmnop</acmeMemberId>
<advocacyPlanId>qrstuvwxyz</advocacyPlanId>
<srvContextPointer>
<serviceDefUrn>urn:coderunner:Medical:Definition:ServiceService:11111:7</serviceDefUrn>
<outreachActionDefInfo sequence="1" actionDefUrn="urn:xxxxxxxxxx:Medical:Definition:Action:50813:2" actionDefId="xxxxxx">
<srvContextPath>Access Profile~Why did you access the profile?~Reason for access?</srvContextPath>
</outreachActionDefInfo>
</srvContextPointer>
</action>Started out using this update statement against the virtual column a.actn_id. This column is also indexed as a fbi.
UPDATE /*+ NO_XML_DML_REWRITE */ action A
SET A.object_value = updatexml(A.object_value,'/action/@status','triggered','xmlns="http://www.xxxx.vvv/yyy/domains/actions/2010/03"')
where a.actn_id='888a80be-d69f-464d-b3f7-85b6209f918e';
This statment updates fine with and w/o the hint. This hint takes away the piecewise update of the xml document and relies upon the a.actn_id virtual column.
Then removed the reliance on the virtual column using the xmlexists fn.
First did an alter index 'actn_id_pk invisible' to take the virtual column out of consideration by the optimizer.
UPDATE /*+ NO_XML_DML_REWRITE */ action A
SET A.object_value = updatexml(A.object_value,'/action/@status','triggered','xmlns="http://www.xxxx.vvv/yyy/domains/actions/2010/03"')
where xmlexists('$p/action[@id="'888a80be-d69f-464d-b3f7-85b6209f918e'"]' PASSING object_value as "p");
This update runs but doesn't update any columns - with or without the hint.
Also created a basic unstructured xmlindex to remove the full table scan - which worked fine execution plan-wise.
create index action_xmlindex_ix on action (object_value) indextype is xdb.xmlindex;Per the SR on this, the /*+ NO_XML_DML_REWRITE */ disables piecewise update and is a workaround for the bug surrounding virtual column index usage when having many concurrent sessions and updates against a table with millions of xml documents. Getting rid of the virtual column in the predicate removes the need for the workaround hint.
My problem is This update runs but doesn't update any columns. Maybe am missing something or doing a syntax/semantic error ?
Any assistance much appreciated...
Regards,
Rick Blanchard
Edited by: RickBlanchardSRSCigna on Apr 25, 2012 12:52 PM -
Sender jdbc adapter....update query?
Dear Team,
we are selecting date from master database and client dont want to add any other field for update query.
using select option, how to avoid selecting duplication records.
can i use current date and time for selecting the records for every select statement?
if yes then how to do it and what we need to update in update query??
Regards,
ChinnaHi Chinna,
Check like this below.
The following SQL statement selects the product name, and price for today from the "Products" table:
SELECT ProductName, Price, Now() AS PerDate
FROM Products;
Similarly,
UPDATE ProductName, Price, Now() AS PerDate
FROM Products;
Regards,
Loordh. -
Update query is not working (ora-01427)
RDBMS 10gr2
Long story short, I created a column from one table in another because the table it was moved from isn't really needed as all the other information is stored in other tables. With that the original column has values that need to be copied to the new column before the old table is dropped.
I'm using this update query:
update bi_req bir
set bir.job_name =
(select distinct bij.job_name
from bi_jobs bij,
bi_freq bif,
bi_apps bia,
bi_req bir
where bij.fk_bi_req_id = bir.pk_bi_req_id
and bia.pk_bi_apps_id = bij.fk_bi_apps_id
and bif.pk_bi_freq_id = bij.fk_bi_freq_id)
where bir.job_name is null;If I run the select statement separately, I get the exact results I need however whenever I run the entire statement, I get:
Error: ORA-01427: single-row subquery returns more than one rowI removed the extra bi_req from the subquery and that didn't help any.
If I replace the '=' with IN (also ALL) I get the error message:
ORA-00927: missing equal signHere is the create table for the table that will soon be dropped:
CREATE TABLE BI_JOBS
PK_BI_JOBS_ID NUMBER NOT NULL,
FK_BI_APPS_ID NUMBER NOT NULL,
FK_BI_FREQ_ID NUMBER NOT NULL,
JOB_NAME VARCHAR2(50 CHAR) NOT NULL,
FK_BI_REQ_ID NUMBER NOT NULL
)and the relevant columns for the table that has the column that needs the values from bi_jobs.job_name
CREATE TABLE BI_REQ
PK_BI_REQ_ID NUMBER NOT NULL,
FK_FREQ_ID NUMBER NOT NULL,
FK_BI_APPS_ID NUMBER,
JOB_NAME VARCHAR2(50 CHAR)
)Whatever value that is in bi_jobs.job_name I want in bi_req.job_name assuming that bi_jobs.fk_bi_req_id equals bi_req.pk_bi_req_id -
Can we rollback the update query using Transaction?
Can we rollback the Update query by writing the update query with in the transaction, as i am implementing different update queries, sometimes I am mistakenly updating the table without where criteria, which is messing up the table. Is there anyway where
we can write the update query within a transaction and rollback that particular update query which I am writing. I do have a backup table, but that wont be useful because we are doing lot of updates in a span of minutes. I researches about Apex Sql logs too,
but we do not have access to download such tools. So, can anyone give me a good solution for this?Sure, if you use transaction like this
begin transaction
update 1
update 2
rollback transaction
both updates will be rollbacked.
If you want to always be sure about rows you're about to change, always first try with SELECT statement and put each individual UPDATE into separate transaction with rollback at the end, e.g.
begin transaction
select ... where some condition
update . where same condition
select ... where same condition to verify update
rollback transaction
If your last select showed correct info, change ROLLBACK into COMMIT and re-run that script again to perform the actual update.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Hi, I want to update status_code of table_2. T_ID is the primary key in both table (Table_1 and table_2). The condition is any person's age >70 then status_code should be 'R' and if person's age<70 then status_code should be 'N'. Please help on this
Update query.
/*Table_1*/
T_ID LASTNAME FIRSTNAME DOB
1001 KAISER SUJIR 01/01/1942
1002 SMITH HUJR 01/01/1948
1003 JOHN JANE 02/01/1958
/*Table_2*/
T_ID LASTNAME FIRSTNAME STATUS_CODE
1001 KAISER SUJIR R
1002 SMITH HUJR R
1003 JOHN JANE R
/*Need the Following Result after the Update*/
T_ID LASTNAME FIRSTNAME STATUS_CODE
1001 KAISER SUJIR R --The Age is >70 that's why status_code is 'R'
1002 SMITH HUJR N --The Age is <70
1003 JOHN JANE N --The Age is <70DECLARE @table1 TABLE (T_ID INT, lastName VARCHAR(30), firstName VARCHAR(30), dob DATE)
INSERT INTO @table1 (T_ID, lastName, firstName, dob) VALUES (1001, 'KAISER', 'SUJIR' ,'01/01/1942'),(1002, 'SMITH', 'HUJR', '01/01/1948'),(1003, 'JOHN', 'JANE', '02/01/1958'),(1004, 'Jack', 'Jackson', '12/03/1944')
DECLARE @table2 TABLE (T_ID INT, lastName VARCHAR(30), firstName VARCHAR(30), statusCode CHAR(1))
INSERT INTO @table2 (T_ID, lastName, firstName, statusCode) VALUES (1001, 'KAISER', 'SUJIR', 'R'),(1002, 'SMITH', 'HUJR', 'R'),(1003, 'JOHN', 'JANE', 'R'),(1004, 'Jack', 'Jackson', 'R')
-- tables set up
UPDATE @table2
SET statusCode = CASE WHEN DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP) - CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP),t1.dob) > CURRENT_TIMESTAMP THEN 1 ELSE 0 END >= 70 THEN 'R' ELSE 'N' END
FROM @table2 t2
INNER JOIN @table1 t1
ON t2.T_ID = t1.T_ID
SELECT *, DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP) - CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP),t1.dob) > CURRENT_TIMESTAMP THEN 1 ELSE 0 END
FROM @table2 t2
INNER JOIN @table1 t1
ON t2.T_ID = t1.T_ID
Maybe you are looking for
-
Streaming Music, Apple TV stopps playing it
While I'm streaming music, Apple TV often stopps to play it after a few minutes. iTunes is still going on with streaming it. The connection to the wireless network is excelent and apple tv is showing all the time in iTunes library. All updates have b
-
MicroMV in Mac OS X Leopard - imovie'09
Hello someone could help me import videos from my old camera Sony DCR-IP220 MICROMV in Mac OS X Leopard? Now use another camera, but I have MICROMV recorded in the birth of my son and I would be it for my mac. Aluminum Macbook / 2.0 / 2GB / 160GB []
-
How can we move our existing documents into iCloud?
So far I've been presented with the option to save files into iCloud (textedit and the like). How can we take our existing documents (Word, Excel, TXT, PDF, etc) and store them in iCloud as well? Short of individually opening each one and saving in i
-
DW unexpectedly quits; can't change sites [added:a fix for Macintosh OS X]
Hello. If your Dreamweaver application was working wonderfully, you were doing a lot, making many sites etc. and suddenly DW stopped uploading to your remote site or just would not allow you to change sites, then read on... Manage sites, change site
-
Hi all, i) I have an F4 Help Popup working for vendor. It's shown in a table view for line items of a service ticket, so my code is in the iterator *set input field and F4 help to the Partner field in table strA = 'ShowF4KeyAndValueHelp2(' . CONCATE