UPDATE statement monitoring
Does anybody know how to monitor update statement? I am updating 3 Million rows and it taking long time to complete. I just want to make sure this statement not hanged.
With a minor bit of effort on your part, you can do a search on, for example, longops, and then copy/use one of the gazillion sample scripts used to monitor long operations.
Similar Messages
-
Sudden increase in buffer gets per executions in update statement
Hi,
Recently we have encountered one performance issue, which is most likely caused by a sudden increase in the buffer gets per execution.
The SQL is an update statement, updating a table using a primary key (we have checked to confirm the running execution plan is using the primary key), and one field being updated is a BLOB column.
As shown in the below statistics, there is no major change in the number of executions during the every 20 minutes monitoring interval. However, the buffer gets per executions has been more than double, and the CPU time is almost doubled, hence the exec_time (elapsed time) has been doubled.
The same SQL has been running for the past four years in multiple similar databases. The database is Oracle 9.2.0.4 running on Solaris 9. For the past 300 days, the average elapsed time per execution is about 0.0093s, while the average buffer gets per execution is about 670. The update statement has been executed about 9 times per second.
The question is why there is a sudden increase in the buffer gets? The sudden increase happened twice for the past two days.
<pre>
B_TIME E_TIME EXECUTIONS_DIFF EXEC_TIME CPU_TIME BUFFER_GETS EXEC_PER_DAY
2009-11-25-14:04 2009-11-25-14:23 8513 .0069 .0068 315.56 646329
2009-11-25-14:23 2009-11-25-14:43 10170 .007 .0068 312.28 726188
2009-11-25-14:43 2009-11-25-15:05 11873 .0072 .0069 320.17 787885
2009-11-25-15:05 2009-11-25-15:23 8633 .011 .0101 844.83 675014
2009-11-25-15:23 2009-11-25-15:44 9668 .0144 .0137 1448.51 680778
2009-11-25-15:44 2009-11-25-16:04 9671 .0163 .0156 1809.04 702163
2009-11-25-16:04 2009-11-25-16:25 10260 .0188 .0177 2107.67 711447
2009-11-25-16:25 2009-11-25-16:44 9827 .0157 .0151 1834.3 739593
2009-11-25-16:44 2009-11-25-17:05 10586 .0171 .0164 2008.25 714555
2009-11-26-08:04 2009-11-26-08:24 11028 .0182 .0172 1979.61 800688
2009-11-26-08:24 2009-11-26-08:44 10533 .0154 .0149 1734.62 750248
2009-11-26-08:44 2009-11-26-09:04 9367 .018 .0168 2043.95 685274
2009-11-26-09:04 2009-11-26-09:24 10307 .0214 .0201 2552.43 729938
2009-11-26-09:24 2009-11-26-09:45 10932 .0251 .0234 3111.48 762328
2009-11-26-09:45 2009-11-26-10:05 10992 .0278 .0254 3386.41 797404
2009-11-26-15:03 2009-11-26-15:16 7183 .0425 .0348 4615.42 746824
2009-11-26-15:16 2009-11-26-15:23 2921 .0417 .0373 4887.75 682092
2009-11-26-15:23 2009-11-26-15:43 9597 .0393 .0352 4603.62 679656
2009-11-26-15:43 2009-11-26-16:03 8797 .0411 .0362 4783.66 630755
2009-11-26-16:03 2009-11-26-16:23 9957 .0453 .0391 5168.28 718100
2009-11-26-16:23 2009-11-26-16:43 11209 .0436 .0369 4870.77 808395
2009-11-26-16:43 2009-11-26-17:03 10729 .0428 .0375 5119.56 766103
2009-11-26-17:03 2009-11-26-17:23 9116 .0409 .0363 4912.58 659098
</pre>
Yesterday I did a trace on one of the sessions running the update statement, and below is the tkprof output:
<pre>
call count cpu elapsed disk query current rows
Parse 76 0.03 0.00 0 0 0 0
Execute 76 4.58 5.14 0 567843 19034 76
Fetch 0 0.00 0.00 0 0 0 0
total 152 4.61 5.14 0 567843 19034 76
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 88
Rows Row Source Operation
1 UPDATE (cr=30 r=0 w=0 time=6232 us)
1 INDEX UNIQUE SCAN <PK Index Name> (cr=3 r=0 w=0 time=58 us)(object id 81122)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
Waited--------------------------------------------------------------------------------
SQL*Net message to client 152 0.00 0.00
SQL*Net message from client 152 0.00 0.22
SQL*Net more data from client 1894 0.00 0.03
SQL*Net break/reset to client 152 0.00 0.00
buffer busy waits 14 0.00 0.00
enqueue 1 0.61 0.61
</pre>
GaoYuanHi,
I've reformatted your output for better understanding (with {noformat}...{noformat}):
B_TIME E_TIME EXECUTIONS_DIFF EXEC_TIME CPU_TIME BUFFER_GETS EXEC_PER_DAY
2009-11-25-14:04 2009-11-25-14:23 8513 .0069 .0068 315.56 646329
2009-11-25-14:23 2009-11-25-14:43 10170 .007 .0068 312.28 726188
2009-11-25-14:43 2009-11-25-15:05 11873 .0072 .0069 320.17 787885
2009-11-25-15:05 2009-11-25-15:23 8633 .011 .0101 844.83 675014
2009-11-25-15:23 2009-11-25-15:44 9668 .0144 .0137 1448.51 680778
2009-11-25-15:44 2009-11-25-16:04 9671 .0163 .0156 1809.04 702163
2009-11-25-16:04 2009-11-25-16:25 10260 .0188 .0177 2107.67 711447
2009-11-25-16:25 2009-11-25-16:44 9827 .0157 .0151 1834.3 739593
2009-11-25-16:44 2009-11-25-17:05 10586 .0171 .0164 2008.25 714555
2009-11-26-08:04 2009-11-26-08:24 11028 .0182 .0172 1979.61 800688
2009-11-26-08:24 2009-11-26-08:44 10533 .0154 .0149 1734.62 750248
2009-11-26-08:44 2009-11-26-09:04 9367 .018 .0168 2043.95 685274
2009-11-26-09:04 2009-11-26-09:24 10307 .0214 .0201 2552.43 729938
2009-11-26-09:24 2009-11-26-09:45 10932 .0251 .0234 3111.48 762328
2009-11-26-09:45 2009-11-26-10:05 10992 .0278 .0254 3386.41 797404
2009-11-26-15:03 2009-11-26-15:16 7183 .0425 .0348 4615.42 746824
2009-11-26-15:16 2009-11-26-15:23 2921 .0417 .0373 4887.75 682092
2009-11-26-15:23 2009-11-26-15:43 9597 .0393 .0352 4603.62 679656
2009-11-26-15:43 2009-11-26-16:03 8797 .0411 .0362 4783.66 630755
2009-11-26-16:03 2009-11-26-16:23 9957 .0453 .0391 5168.28 718100
2009-11-26-16:23 2009-11-26-16:43 11209 .0436 .0369 4870.77 808395
2009-11-26-16:43 2009-11-26-17:03 10729 .0428 .0375 5119.56 766103
2009-11-26-17:03 2009-11-26-17:23 9116 .0409 .0363 4912.58 659098
call count cpu elapsed disk query current rows
Parse 76 0.03 0.00 0 0 0 0
Execute 76 4.58 5.14 0 567843 19034 76
Fetch 0 0.00 0.00 0 0 0 0
total 152 4.61 5.14 0 567843 19034 76
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 88
Rows Row Source Operation
1 UPDATE (cr=30 r=0 w=0 time=6232 us)
1 INDEX UNIQUE SCAN <PK Index Name(cr=3 r=0 w=0 time=58 us)(object id 81122)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
SQL*Net message to client 152 0.00 0.00
SQL*Net message from client 152 0.00 0.22
SQL*Net more data from client 1894 0.00 0.03
SQL*Net break/reset to client 152 0.00 0.00
buffer busy waits 14 0.00 0.00
enqueue 1 0.61 0.61
********************************************************************************Can you please provide a DDL for the table, indexes, type of the tablespace(s) they reside in (ASSM/MSSM, extents sizes), the UPDATE statement, how many sessions on average/peaks are doing the same thing concurrently, how many sessions are working this table concurrently and how do they use it? -
Long running update statement needs a performance improve.
Hi,
I have the following update statement which runs for over 3 hours and updates 215 million rows, is there anyway I can rewrite it so it performs better?
UPDATE TABLE1 v
SET closs = (SELECT MIN(slloss)
FROM TABLE2 l
WHERE polnum = slpoln
AND polren = slrenn
AND polseq = slseqn
AND vehnum = slvehn
AND linecvg = sllcvg);Here is the execution plan:
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | UPDATE STATEMENT | | 214M| 4291M| 2344K (2)|
| 1 | UPDATE | TABLE1 | | | |
| 2 | TABLE ACCESS FULL | TABLE1 | 214M| 4291M| 2344K (2)|
| 3 | SORT AGGREGATE | | 1 | 21 | |
| 4 | TABLE ACCESS BY INDEX ROWID| TABLE2 | 1 | 21 | 5 (0)|
| 5 | INDEX RANGE SCAN | TABLE2_N2 | 2 | | 3 (0)|
----------------------------------------------------------------------------------Here are create table statements for TABLE1(215million rows) and TABLE2(1million rows):
CREATE TABLE TABLE2 (SLCLMN VARCHAR2(11 byte),
SLFEAT NUMBER(2), SLPOLN NUMBER(9), SLRENN NUMBER(2),
SLSEQN NUMBER(2), SLVEHN NUMBER(2), SLDRVN NUMBER(2),
SLCVCD VARCHAR2(6 byte), SLLCVG NUMBER(4), SLSABB
VARCHAR2(2 byte), SLPRCD VARCHAR2(3 byte), SLRRDT
NUMBER(8), SLAYCD NUMBER(7), SLCITY VARCHAR2(28 byte),
SLZIP5 NUMBER(5), SLCEDING VARCHAR2(1 byte), SLCEDELOSS
VARCHAR2(1 byte), SLRISKTYPE VARCHAR2(1 byte), SLVEHDESIG
VARCHAR2(1 byte))
TABLESPACE S_DATA PCTFREE 10 PCTUSED 0 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 106496K NEXT 0K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0)
NOLOGGING
MONITORING;
CREATE TABLE TABLE1 (POLNUM NUMBER(9) NOT NULL,
POLREN NUMBER(2) NOT NULL, POLSEQ NUMBER(2) NOT NULL,
VEHNUM NUMBER(2) NOT NULL, CVGCODE VARCHAR2(8 byte) NOT
NULL, LINECVG NUMBER(4), MAINVEH CHAR(1 byte), MAINCVG
CHAR(1 byte), CVGLIMIT VARCHAR2(13 byte), CVGDED
VARCHAR2(10 byte), FULLCVG CHAR(1 byte), CVGGRP CHAR(4
byte), CYCVG CHAR(1 byte), POLTYPE CHAR(1 byte),
CHANNEL CHAR(2 byte), UWTIER VARCHAR2(6 byte), SUBTIER
VARCHAR2(6 byte), THITIER VARCHAR2(3 byte), COMPGRP
VARCHAR2(8 byte), PRODGRP VARCHAR2(6 byte), UWSYS
VARCHAR2(6 byte), BRAND VARCHAR2(8 byte), COMP NUMBER(2),
STATE CHAR(2 byte), PROD CHAR(3 byte), RRDATE DATE,
STATENUM NUMBER(2), EFT_BP CHAR(1 byte), AGYCODE
NUMBER(7), AGYSUB CHAR(3 byte), AGYCLASS CHAR(1 byte),
CLMAGYCODE NUMBER(7), AGYALTCODE VARCHAR2(25 byte),
AGYRELATION VARCHAR2(10 byte), RATECITY VARCHAR2(28 byte),
RATEZIP NUMBER(5), RATETERR NUMBER, CURTERR NUMBER,
CURRRPROD CHAR(6 byte), CURRRDATE DATE, RATESYMB NUMBER,
SYMBTYPE CHAR(1 byte), CVGTERR NUMBER(3), CVGSYMB
NUMBER(3), VEHTERR NUMBER, VEHYEAR NUMBER, VEHMAKE
VARCHAR2(6 byte), VEHMODEL VARCHAR2(10 byte), VEHSUBMOD
VARCHAR2(10 byte), VEHBODY VARCHAR2(6 byte), VEHVIN
VARCHAR2(10 byte), VEHAGE NUMBER(3), VEHSYMB NUMBER,
DRVNUM NUMBER, DUMMYDRV CHAR(1 byte), DRVAGE NUMBER(3),
DRVSEX VARCHAR2(1 byte), DRVMS VARCHAR2(1 byte), DRVPTS
NUMBER(3), DRVPTSDD NUMBER(3), DRVGRP CHAR(7 byte),
DRVSR22 VARCHAR2(1 byte), DRVVTIER CHAR(2 byte),
BUSUSESUR CHAR(1 byte), EXCLDRVSUR CHAR(1 byte),
CSCODED NUMBER(5), CSACTUAL NUMBER(5), CSOVERRD
NUMBER(5), ANNMILES NUMBER(6), DLORIGDATE DATE,
DLLASTDATE DATE, DLMONTHS NUMBER(6), MATUREDSC CHAR(1
byte), PERSISTDSC CHAR(1 byte), ANNUALMILES_RANGE
VARCHAR2(25 byte), CEDEDLOSS VARCHAR2(1 byte), CEDEDPOL
VARCHAR2(1 byte), CEDEDCVG VARCHAR2(1 byte),
CONSTRAINT TABLE1_PK PRIMARY KEY(POLNUM, POLREN,
POLSEQ, VEHNUM, CVGCODE)
USING INDEX
TABLESPACE V_INDEX
STORAGE ( INITIAL 3874816K NEXT 0K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0) PCTFREE 10 INITRANS 2 MAXTRANS 255)
TABLESPACE U_DATA PCTFREE 10 PCTUSED 0 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4194304K NEXT 0K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0)
NOLOGGING
MONITORING;Thank you very much!user6053424 wrote:
Hi,
I have the following update statement which runs for over 3 hours and updates 215 million rows, is there anyway I can rewrite it so it performs better?
UPDATE TABLE1 v
SET closs = (SELECT MIN(slloss)
FROM TABLE2 l
WHERE polnum = slpoln
AND polren = slrenn
AND polseq = slseqn
AND vehnum = slvehn
AND linecvg = sllcvg);
Are you trying to perform a correlated update? If so, you can perform something similar to;
Sample data;
create table t1 as (
select 1 id, 10 val from dual union all
select 1 id, 10 val from dual union all
select 2 id, 10 val from dual union all
select 2 id, 10 val from dual union all
select 2 id, 10 val from dual);
Table created
create table t2 as (
select 1 id, 100 val from dual union all
select 1 id, 200 val from dual union all
select 2 id, 500 val from dual union all
select 2 id, 600 val from dual);
Table createdThe MERGE will update each row based on the maximum for each ID;
merge into t1
using (select id, max(val) max_val
from t2
group by id) subq
on (t1.id = subq.id)
when matched then update
set t1.val = subq.max_val;
Done
select * from t1;
ID VAL
1 200
1 200
2 600
2 600
2 600If you want all rows updated to the same value then remove the ID grouping from the subquery and from the ON clause. -
SqlDependency causing delays to UPDATE statements
I have a win forms application which uses SqlDependency to monitor an orders table for changes (ie when goods are shipped etc). The SQL statement works fine but I am having trouble with other SQL statements wanting to update the orders table whilst
the SqlDependency is monitoring the table.
Initially I thought it was down to the transaction containing the update statements but if I take just one simple update statement and run it in SQL Management Studio, I get the same delay between 10 and 20 seconds. It appears to be the case for just
this one table which is monitored, other tables which are included in the SqlDependency SQL statement through inner joins are updated fine (<1 second).
Anyone any ideas on what could cause this or where to start troubleshooting?
Also, this is in a production system and the table in question has circa 19k rows. I don't see this problem in my dev system which has fewer rows.
ChrisHello,
I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
Thank you for your understanding and support.
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support -
Decode function in Update statement
Hello everyone,
I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
I am using Oracle SQL. This is what I have so far for my decode function:
SQL> SELECT
2 DECODE(SIGN((return_dte - due_dte)*2),
3 '-1', '0',
4 '1', '12', 'Null')
5 FROM book_trans;
DECO
Null
12
Null
0
So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
The logic should be:
UPDATE book_trans SET PastDue_fees = decode(expression)
I've given it a couple of different tries with the following results:
SQL> UPDATE book_trans
2 SET pastdue_fees = SELECT
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
SET pastdue_fees = SELECT
ERROR at line 2:
ORA-00936: missing expression
SQL> UPDATE book_trans
2 SET pastdue_fees =
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
FROM book_trans
ERROR at line 6:
ORA-00933: SQL command not properly ended
Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
Thanks!882300 wrote:
Hello everyone,
I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
I am using Oracle SQL. This is what I have so far for my decode function:
SQL> SELECT
2 DECODE(SIGN((return_dte - due_dte)*2),
3 '-1', '0',
4 '1', '12', 'Null')
5 FROM book_trans;
DECO
Null
12
Null
0
So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
The logic should be:
UPDATE book_trans SET PastDue_fees = decode(expression)
I've given it a couple of different tries with the following results:
SQL> UPDATE book_trans
2 SET pastdue_fees = SELECT
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
SET pastdue_fees = SELECT
ERROR at line 2:
ORA-00936: missing expression
SQL> UPDATE book_trans
2 SET pastdue_fees =
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
FROM book_trans
ERROR at line 6:
ORA-00933: SQL command not properly ended
Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
Thanks!If you really really really want to update the entire table, the syntax would be...
UPDATE book_trans
SET
pastdue_fees = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
http://wikis.sun.com/display/Forums/Forums+FAQ -
Unable to execute an update statement using CallableStatement
Hi there,
I'm trying to run an update statement from JUnit using java.sql.CallableStatement and oracle.jbo.server.DBTransaction.
String updateSql =
"update footable set barcol=TO_DATE('12-SEP-09','dd-MM-yy') where bazcol = 505";
try {
statement =
applnModule.getDBTransaction().createCallableStatement(updateSql,
2);
int executeUpdate = statement.executeUpdate();
AppsLogger.write(this,
"# records UPDATED ------------------>" + executeUpdate,
AppsLogger.SEVERE);
} catch (SQLException s) {
s.printStackTrace();
Assert.fail("Encountered SQL Exception: " + s);
} finally {
try {
if (statement != null)
statement.close();
} catch (SQLException s) {
}Below is the exception I get when I run the above code. There is no problem with the SQL - it works fine from SQLDeveloper.
java.lang.AssertionError: Encountered SQL Exception: java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
org.junit.Assert.fail(Assert.java:91)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.invokeTestMethod(AtfJUnit4JTestCaseClassRunner.java:362)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.runMethods(AtfJUnit4JTestCaseClassRunner.java:272)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner$1.run(AtfJUnit4JTestCaseClassRunner.java:265)
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.run(AtfJUnit4JTestCaseClassRunner.java:262)Edited by: 911023 on Oct 2, 2012 11:28 AM
Edited by: 911023 on Oct 2, 2012 11:30 AMUsing case statement.
UPDATE gor_gold_post
SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END,
b49n = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END
WHERE tariff_code IN (169, 135, 136);Note: Code not tested. -
Is their any limit on the number of column updates in a update statement!
Hello All,
Is their any limit on the number of columns to set in a single update statement.+
am using oracle 11g .
example :-
UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5 , perslt18 = v_perslt18 , persot64 = v_persot64 , fam_size = v_fam_size , numchild = total_children , C_AGE1 = v_c_age1, C_AGE2 = v_c_age2, C_AGE3 = v_c_age3, C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
and also is it good practice to issue single update or multiple updates ?
example for the above update i can have multiple statements like .. does the performance matters if so which is good
UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5
WHERE FAMID = fmly_famid(i) ;
UPDATE FMLY SET perslt18 = v_perslt18 , persot64 = v_persot64 , fam_size = v_fam_size
WHERE FAMID = fmly_famid(i) ;
UPDATE FMLY SET numchild = total_children WHERE FAMID = fmly_famid(i) ;
UPDATE FMLY SET C_AGE1 = v_c_age1, C_AGE2 = v_c_age2, C_AGE3 = v_c_age3, C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
thanks/kumar
Edited by: kumar73 on Sep 25, 2010 8:38 AMIf you can do it in a single SQL statement then you should do that.
Here's a mantra that I found to work out pretty good:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:73891904732164 -
Error while schedulingg update stat in db13
Dear Experts,
Please look into my issue we are facing an error while scheduling update statistics in db13 and I tried to open detailed log
It is given
SXPG_COMMAND_EXECUTE failed for BRTOOLS - Reason: program_start_error: For More Information, See SYS
Please help me how to solve this my error
RegardsHi,
Check the owner for BRBACKUP, BRARCHIVE, and BRCONNECT in kernel,
these files should be with SIDADM, if not change the owner to SIDADM and rerun the update stats.
and also Refer the note 446172
Regards,
Ram -
How do I pass multiple values from a text box to an update statement
I hope this does not sound to lame. I am trying to update multiple values Like this:
Code|| Computer Desc || Computer Price || Computer Name
SEL1 || Apple macbook || 1564 || Apple Macbook Basic
SEL2 || Dell 630 || 1470 || Dell Latitude
I want to change all six values at once in one update statement based on the Code, I can't find a good tutorial/example to help me.
Can anyone point me in the right direction?
Thanks so much,
LauraYou can do conditional updates with decode or case statements e.g.
SQL> create table t as
2 select 'SEL1' as code, 'Apple macbook' as comp_desc, 1564 as comp_price, 'Apple Maxbook Basic' as comp_name from dual union
3 select 'SEL2', 'Dell 630', 1470, 'Dell Latitude' from dual
4 /
Table created.
SQL>
SQL> update t
2 set comp_desc = CASE code WHEN 'SEL1' THEN 'Test1' Else 'Test2' END,
3 comp_price = CASE code WHEN 'SEL1' THEN 1234 Else 2345 END,
4 comp_name = CASE code WHEN 'SEL1' THEN 'Test1 Name' Else 'Test2 Name' END
5 /
2 rows updated.
SQL>
SQL> select * from t
2 /
CODE COMP_DESC COMP_PRICE COMP_NAME
SEL1 Test1 1234 Test1 Name
SEL2 Test2 2345 Test2 Name
SQL> -
Need help to write a query for Update statement with join
Hi there,
The following update statement gives me error as the given table in set statement is invalid. But its the right table .
Is the statement correct? Please help .
update (
select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)
from vpproadside.VEHICLE_CRED_OVERRIDE
join vpproadside.vpp_vehicle
on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
where VPP_CARRIER_SEQ_NUMBER = 90
and EXPIRY_DATE = '17-MAR-10'
set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
Edited by: Indhu Ram on Mar 15, 2010 8:28 AMAsk Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797 -
Running an update statement on two dependent attributes
Dear All,
I have a repair_job table that contains values for work_cost, parts_cost and total_cost which is the sum of the work and parts cost values. I want to run an update statement that doubles the work cost and, naturally, updates the value of total cost as well. I tried to run it as:
update repair_job
set work_cost = 2 * work_cost, total_cost = work_cost + parts_cost
where licence in (
select licence from car
where year = to_char(sysdate,'YYYY')
thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
I look forward to hearing from you soon.
Regards,
GeorgeWelcome to the forum!
>
thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
>
The update to all columns of the row happen at the same time - there is no order involved.
You don't need two statements but you do need to do the updates based on the current value of the columns.
set work_cost = 2 * work_cost, total_cost = 2 * work_cost + parts_cost----------
In addition to sb92075's comments in 11 g you could also just define a virtual column for total_cost and then just query it like you do now.
total_cost NUMBER GENERATED ALWAYS AS (work_cost + parts_cost) VIRTUAL,See this Oracle-base article for an example
http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
Edited to supplement sb92075's reply by mentioning virtual columns -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M -
How to use the updated value in the same update statement
Hello,
I just wonder how to use the updated new value of other column in the same udpate statement. I am using Oracle 11.2, and want to update the two columns with one update statement as following:
create table tb_test (id number(5), tot number(5), mon_tot number(5));
update tb_test set (tot = 15, mon_tot = tot *15) where id = 1;
...I would like to update both tot and mon_tot column, the value of mon_tot shall be determinted by the new value of tot.
Thanks,
Edited by: 939569 on 1-Feb-2013 7:00 AMEdit: example added
SQL> create table tb_test
2 ( id number(5)
3 , tot number(5)
4 , mon_tot number generated always as (tot*15) virtual
5 );
Table created.
SQL> insert into tb_test (id, tot) values (1, 5);
1 row created.
SQL> select * from tb_test;
ID TOT MON_TOT
1 5 75
1 row selected.
SQL> update tb_test
2 set tot = 15
3 where id = 1;
1 row updated.
SQL> select * from tb_test;
ID TOT MON_TOT
1 15 225
1 row selected. -
How to track a column is not updated in a update statement issued.
Hello All,
Is there a way to write a trigger when a particular column is not specified in update statement.
For example, consider i have a table with 20 columns(Say Column1...column20). Trigger has to get fired only when column15(say) is not specified.
I know
CREATE OR REPLACE TRIGGER test_trigger
BEFORE UPDATE
OF COLUMN1, COLUMN2......COLUMN20--Except COLUMN15
ON TESTTABLE
FOR EACH ROW
BEGIN
END of_clause; /
above trigger will solve my problem. But i don't want to mention all columns in this trigger. It will cause maintainance problem afterwards.
Is there any way to mention something like NOT OF COLUMN in the trigger ?
Regards,
Abhijit.That trigger would get fired for every column except column 15.
What do you mean by "when a particular column is not specified in update statement"? Do you mean that the column is not mentioned at all in the update statement, or that the value of that column is not being changed even if it is mentioned in the statement?
If you mean the former, then I don't think there is any way to do that. however, if you want to do something only if the value in column15 is unchanged, then something along the lines of:
CREATE TRIGGER test_trigger
BEFORE UPDATE OF testtable
FOR EACH ROW
BEGIN
BEGIN
IF (:new.column15 IS NULL and :old.column15 IS NULL) OR
(:new.column15 IS NOT NULL and :old.column15 IS NOT NULL and
:new.column15 = :old.column15) THEN
< do whatever for no changes >
ELSE
< do nothing or something else for changes >
END IF;
END;John -
Where clause in UPDATE statement is ignored
I have the following procedure that updates a field in a table. The only problem is that all rows in the table are updated like the update statement doesn't have a where clause. When I hard code the number (733) in the where clause it works as expected. Even if I don't alias the table name it still updates all rows in the table. Any ideas?
DECLARE
extlinkid CONSTANT NUMBER := 733;
newURL CONSTANT VARCHAR2(250) := 'mailto:[email protected]';
BEGIN
UPDATE SCHEMA.TABLE A
SET A.URL = newURL
WHERE (A.EXTLINKID = extlinkid);
commit;
END;Oracle is resolving your variable extlinkid as the column in the table, so your UPDATE statement is equivalent to:
UPDATE schema.table a
SET a.url = newurl
WHERE (a.extlinkid = a.extlinkid);Which, of course, matches every record in the table. You need to change the name of your variable to something that is not a column name.
TTFN
John
Maybe you are looking for
-
I have been using the match for about 5 months and it's very cool to have all the tunes with me at all times. But, my ATT 'unlimited' data plan slows down after a certain point and I can't effectively stream the big files I uploaded to the cloud unt
-
Launching Rescue & Recovery from a Command Line
Question - I would like to know how I can launch Rescue & Recovery from a command line. Issue that is prompting the question - My laptop was sitting in my computer bag overnight. The battery was fully charged. I BELIEVE that it was in suspend mode a
-
Why does the GPS not work with other programs?
It works ok with Blackberry maps. But there are about 5 or 6 programs that I use that will not lock GPS. The one that really florred me was the camera. I sit there and sit there waiting for the gps to lock on (turn from red to white) and nothing happ
-
Seems like my macbook has gone to reset mode except that files and applications are intact. I tried to rearrange the icons but it came back to reset mode again whenever it is restarted. Basically, the icons are messed up, the dock was like what it wa
-
Excel stays live as a process when terminating a program during debug
Hi In my C# windows application I open an excel file with Excel.Application xlApp = new Excel.ApplicationClass(); when in debug mode in VS I often stop the application mid process by clicking on "stop debugging" in the VS menu. I noticed that this se