Re write Update statement
Hi All,
I need to re-write below update statement. existing one is taking long time to update. Please help me on that. thanks in advance
UPDATE xxx a
SET a.bb = 'NG',
a.cc = '12'
WHERE EXISTS (
SELECT 1
FROM dt , lm
WHERE dt.ln_dt = (SELECT MAX (insert_date)
FROM ccc
WHERE source_system_id = 36)
AND dt.id = 36
AND dt.ln = a.ln
AND lm.lnr = dt.ln
AND NVL (lm.ind, 'XX') <> 'NG')
AND (
NOT EXISTS(
SELECT 1
FROM mt, lp
WHERE mt.ln=a.ln
AND lp.ln=a.ln
AND a.dt IS NOT NULL
AND mt.m_id = 1
AND lp.p_date >= trunc(sysdate,'mon')
AND EXISTS(
SELECT 1
FROM my_view p
WHERE p.ln = a.ln
AND p.pay_dt > TRUNC(ADD_MONTHS(SYSDATE, -3),'mon')
AND p.past_due > 29)
);
You haven't posted anything we can use to help you.
Please read these:
When your query takes too long
When your query takes too long ...
How to Post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
Similar Messages
-
Hai All
update dail set timeout=out_time where attend_date=r1.bardate and
(select bar_code from empl_barcode where empl_barcode.barcode=r1.barcode);
I got an error in my update statement. How can i write update statement with this or where i change..
Regards
Srikkanth.MHi,
review the syntax for the UNDATE statement. The following is okay:
UPDATE dail
SET timeout = out_time
WHERE attend_date = x
AND y > z
;if all the columns (including x, y and z) are in dail.
If you need to get some of those values from another table, then you can do a scalar sub-query , that is, a query that returns 9at most) one row, enclosed in parentheses.
For example, if x is in another table (named r1), you might say:
UPDATE dail m
SET timeout = out_time
WHERE attend_date = ( -- Begin scalar sub-query
SELECT MAX (bardate)
FROM r1
WHERE dail_id = m.id
) -- End scalar sub-query
AND y > z
;It looks like you're trying to do something similar.
I'm not sure exactly what x is supposed to be, and you're missing y (or z) as well as the operator between them.
MERGE is often easier to use than UPDATE, when you need to reference other tables.
If you'd like help, post a little sample data (CREATE TABLE and INSERT statements for all tables as they exist before the UPDATE) and the results you want from taht data (the contents of dail after the UPDATE). -
Sender JDBC: help to construct Update statement
Hi,
I need help in writing a update statement to DB2 database in sender JDBC adapter.
The sender adapter picks up only few records say 10 at a time which match the Select query condition. So I would need to update only those selected "n" records and not all the records that match the Select query condition.
Select looks like :
Select * from <table> where <condition> fetch first <n> rows only.
But it is not allowing the following update
update <table> set <field> = <value> where <field> IN (Select * from <table> where <condition> fetch first <n> rows only)
The above statement errors because DB2 does not allows u201CFetchu201D statement within the update sub query.
Any pointers to a write update statement for n records is highly appreciatedu2026
~SaNvu2026Hi Santosh,
In JDBC Sender Adapter provide the following select & update statements
Select Statement:
select * from <table> where <condition> AND ROWNUM<N (N==No.of Rows)
Update Statement:
update <table> set <field> = <value> where <field> IN (Select * from <table> where <condition> AND ROWNUM<N)
(N==No.of Rows)
And for the error you are facing is because of the server communication link failure between the two systems.
Check the connections and try to stop & start communication channels once.
Regards
Venkat Rao .G -
Update statement for multiple records
i have table a and table b
common col in both the tables is emp_id
in table b i have district_id
which i want to update in table a.... column district_id for all the employees
how to write update statement for this
Edited by: user10873676 on Oct 17, 2011 8:00 AMBased on your current description, we have something like this...
SQL> create table a (emp_id number)
2 /
Table created.
SQL>
SQL> create table b (emp_id number, district_id number)
2 /
Table created.
SQL>
SQL> insert into a (emp_id)
2 select rownum from dual connect by rownum <= 10
3 /
10 rows created.
SQL>
SQL> insert into b (emp_id, district_id)
2 select rownum, 10-rownum from dual connect by rownum <= 10
3 /
10 rows created.
SQL>
SQL> update b
2 set district_id = 1
3 /
10 rows updated.
SQL>
SQL> select * from a;
EMP_ID
1
2
3
4
5
6
7
8
9
10
10 rows selected.
SQL> select * from b;
EMP_ID DISTRICT_ID
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
10 rows selected.Which I'm sure is NOT what you want as the update on table b has nothing to do with table a, and we have no idea what the district_id should be updated with. -
Write an UPdate statement using the logic used in PL/SQL block (oracle 10g)
Hi All,
I have written the following PL/SQL block. I want to write an UPDATE statement using the logic used in the following PL/SQL block. can any one please help me out in this regards.
DECLARE
v_hoov_fag gor_gold_post.hoov_flg%TYPE;
v_b49n gor_gold_post.b49n%TYPE;
CURSOR c
IS
SELECT bs_id, loyalty_date, loyalty_period, contract_date
FROM gor_gold_post
WHERE tariff_code IN (169, 135, 136);
BEGIN
FOR rec IN c
LOOP
IF (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
v_hoov_flg := 1;
ELSE
v_hoover_flag := 99;
END IF;
IF (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
v_b49n := 1;
ELSE
v_b49n := 99;
END IF;
UPDATE gor_gold_post
SET hoov_flg = v_hoov_flg,
b49n = v_b49n
WHERE bs_id = rec.bs_id AND tariff_code IN (169, 135, 136);
COMMIT;
END LOOP;
END;Thank you,Using 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. -
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 -
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. -
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 -
How to use Update Statement in ODI Procedure
Hi,
How can I use an update statement inside an ODI procedure.
ThanksHi,
You do not need the BEGIN and END. ODI procedures are free text, so you can simply write your update statement, as you would in toad/sql developer etc etc. Just make sure you set the Technology and the logical schema. It is how ever best practice to also use the API:
<%=odiRef.getSchemaName("YOUR_LOGICAL_SCHEMA_NAME", "D")%>. to prefix tables. This way, you select data from different schema's in the same instance (as long a your user has the correct privs).
Cheers
Bos
Edited by: Bos on Jun 22, 2011 3:09 PM -
Multiple UPDATE statement in a message
Hi Experts,
Here is a scenario where we need to send multiple UPDATE statements in single message
the structure is as below.
<Table_name> 0..unbounded occurrence
<action> UPDATE
<access>
<non key fields>
</access>
<key>
<key fields>
</key>
in the above case the node <Table_name> would occur multiple times, the issue is only the first occurrence of the update statement is executed, rest of the update statements are ignored.
did my approach is wrong, please help...
thanks.Bandana,
No your approach is not wrong. But you may need to tweak little bit to get your requirement correctly.
Please follow Raj or Jais reply in this threads:
JDBC Receiver - Multiple rows Update
JDBC receiver multiple records UPDATE
But with this approach it would be multiple calls. If I were you I would write SQL_DML statement to update all at once.
Regards,
---Satish -
Error in UPDATE statement with SET and JOIN
Hi
UPDATE lms_assessment_student QS JOIN lms_assessment_student_ans QA ON QS.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id SET QA.Mark = 1, QA.Comment_Field = 1 WHERE QS.pk_Assessment_Stud_Id = 1 AND QA.Question_Id = 1;
The above statement when executing is showing ORA-00971: missing SET keyword. so i changed it to
UPDATE lms_assessment_student QS SET QA.Mark = 1, QA.Comment_Field = 1 WHERE QS.pk_Assessment_Stud_Id = 1 AND QA.Question_Id = 1 JOIN lms_assessment_student_ans QA ON QS.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id ;
and it showing ORA-00933: SQL command not properly ended.So can anyone help me in solving this problem
Thanking you in advance
DinnyHi ,
So many errors
YOUR QUERY :
UPDATE lms_assessment_student QS SET QA.Mark = 1, QA.Comment_Field = 1 WHERE QS.pk_Assessment_Stud_Id = 1 AND QA.Question_Id = 1 JOIN lms_assessment_student_ans QA ON QS.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id ;
and it showing ORA-00933: SQL command not properly ended.So can anyone help me in solving this problem
first thing u want to update qa and u write update QS ??
Second y do u want to join??? just put the condition
SOLUTION
UPDATE lms_assessment_student_ans
SET lms_assessment_student_ans.Mark = 1,
lms_assessment_student_ans.Comment_Field = 1
WHERE lms_assessment_student.pk_Assessment_Stud_Id = 1
AND lms_assessment_student.pk_Assessment_Stud_Id = QA.fk_Assessment_Stud_Id
Hope it works for u..
Bhavesh -
Hi, i have the following data
document_seq_num, Country, LE, SOB
33100037 NL 000320 13
33100037 NL 000320 13
33100037 NL 000320 13
33100037 NL 000320 13
33100038 NL 000320 13
33100038 NL 000320 13
33100038 NL 000320 13
33100038 NL 000320 13
33100039 NL 000320 13
33100039 NL 000320 13
33100039 NL 000320 13
33100039 NL 000320 13
33100040 NL 000320 13
33100040 NL 000320 13
33100040 NL 000320 13
33100040 NL 000320 13
33100041 NL 000320 13
33100041 NL 000320 13
33100041 NL 000320 13
33100041 NL 000320 13
33100042 NL 000320 13
33100042 NL 000320 13
33100042 NL 000320 13
33100042 NL 000320 13
33100043 NL 000320 13
33100043 NL 000320 13
33100043 NL 000320 13
33100043 NL 000320 13
i want an update statement for every change in the document sequnce with the other combination..
the seqence number should change.
i tried to write a rank over partion and and sequence but when i am trying to update, this is always updating
90000000 in first run, as it is in loop for all records it is updating the same. i want an
increment to the sequence for every change in document_seq_num
Can any one help me to correct this procedure
create or replace PROCEDURE test is
cursor cur_voc_ref
IS SELECT a.document_seq_num,
a.country, a.LE, a.SOB, 2009, Rank() over (partition by
a.country, a.LE, a.SOB
order by a.document_seq_num, a.country, a.LE, a.SOB)
from (select distinct document_seq_num,
country, LE, SOB,period_name
from temp_tab
where country= 'NL'
and LE= '000320'
and SOB=13
order by SOB,LE,document_seq_num) a
where
a.country= 'NL'
and a.LE= '000320'
and a.SOB=13
and substr(a.period_name,5,6) =substr(2009,3,4);
v_base number;
BEGIN
FOR c_rec IN cur_voc_ref
LOOP
BEGIN
select nvl(max(ggtsi.reference), substr(2009,3,2)*1000000) into v_base
from temp_tab ggtsi;
update temp_tab
set reference= v_base
where document_seq_num= c_rec.document_seq_num
and country=c_rec.country
and le=c_rec.le
and sob=c_rec.sob;
commit;
END;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception in opening balance insert ' || SQLCODE || ' ' || SQLERRM );
END;user11289444 wrote:
Hi, i have the following data
document_seq_num, Country, LE, SOB
33100037 NL 000320 13
33100037 NL 000320 13
33100037 NL 000320 13
33100037 NL 000320 13
33100038 NL 000320 13
33100038 NL 000320 13
33100038 NL 000320 13
33100038 NL 000320 13
33100039 NL 000320 13
33100039 NL 000320 13
33100039 NL 000320 13
33100039 NL 000320 13
33100040 NL 000320 13
33100040 NL 000320 13
33100040 NL 000320 13
33100040 NL 000320 13
33100041 NL 000320 13
33100041 NL 000320 13
33100041 NL 000320 13
33100041 NL 000320 13
33100042 NL 000320 13
33100042 NL 000320 13
33100042 NL 000320 13
33100042 NL 000320 13
33100043 NL 000320 13
33100043 NL 000320 13
33100043 NL 000320 13
33100043 NL 000320 13
i want an update statement for every change in the document sequnce with the other combination..
the seqence number should change.
i tried to write a rank over partion and and sequence but when i am trying to update, this is always updating
90000000 in first run, as it is in loop for all records it is updating the same. i want an
increment to the sequence for every change in document_seq_num
Can any one help me to correct this procedure
create or replace PROCEDURE test is
cursor cur_voc_ref
IS SELECT a.document_seq_num,
a.country, a.LE, a.SOB, 2009, Rank() over (partition by
a.country, a.LE, a.SOB
order by a.document_seq_num, a.country, a.LE, a.SOB)
from (select distinct document_seq_num,
country, LE, SOB,period_name
from temp_tab
where country= 'NL'
and LE= '000320'
and SOB=13
order by SOB,LE,document_seq_num) a
where
a.country= 'NL'
and a.LE= '000320'
and a.SOB=13
and substr(a.period_name,5,6) =substr(2009,3,4);
v_base number;
BEGIN
FOR c_rec IN cur_voc_ref
LOOP
BEGIN
select nvl(max(ggtsi.reference), substr(2009,3,2)*1000000) into v_base
from temp_tab ggtsi;
update temp_tab
set reference= v_base
where document_seq_num= c_rec.document_seq_num
and country=c_rec.country
and le=c_rec.le
and sob=c_rec.sob;
commit;
END;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception in opening balance insert ' || SQLCODE || ' ' || SQLERRM );
END;Hi,
I suggest you to add a column to preserve current RANK value for all rows, <preserve_rank> for example, and
when you add the new rows you will update your <preserve_rank> but you must pay attention to have the same value for
document_seq_num, with other words you may insert yours rows in a batch like this:
-- first update preserve_rank with RANK function
declare
v_doc_seq_num numeric;
begin
v_doc_seq_num:=33100040;
-- note !!!
-- put all into a valid sql command
-- and apply execute immediate
insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
-- update preserve_rank
update temp_tab x set x.preserve_rank = (Select max(preserve_rank) from temp_tab y
where y.document_seq_num=v_doc_seq_num) old_rank + 1)
where (prserve_rank is null) and x.document_seq_num=v_doc_seq_num;
end; I know it's a lost a memory but the trigger is the last solution who can give us a nightmare.
Regards,
Ion
Edited by: user111444777 on Sep 25, 2009 11:12 AM
Edited by: user111444777 on Sep 25, 2009 11:35 AM -
I have a peculiar problem related to update statement.
In a table "table1" I have the following values for the column Name.
John
Doe
Adam
Teela
I need to do the following updates
John -> Adam
Doe -> Teela
Adam -> Doe
Teela -> John
One way of doing it would be to use the ROWID.
Update table1 set value=Adam where ROWID=1
Update table1 set value=Teela where ROWID=2
and so on and so forth.
But I don't want to use the ROWID.
Therefore the logical query that one would write is
Update table1 set value=Adam where value=John
Update table1 set value=Teela where value=Doe
Update table1 set value=Doe where value=Adam
Update table1 set value=John where value=Teela
But immediately the problem becomes apparent.
The converted table would now look like this
Doe
John
Doe
John
How do I make sure that the updation happens as I intend? Is there a way to work around it without ROWID?
Message was edited by:
user574608Much too late, but I don't want to have made it in vain ;) :
michaels> CREATE TABLE table1 (ID INTEGER,VALUE VARCHAR2(10))
Table created.
michaels> INSERT INTO table1
VALUES (1, 'John')
1 row created.
michaels> INSERT INTO table1
VALUES (2, 'Doe')
1 row created.
michaels> INSERT INTO table1
VALUES (3, 'Adam')
1 row created.
michaels> INSERT INTO table1
VALUES (4, 'Teela')
1 row created.
michaels> UPDATE table1
SET VALUE =
CASE VALUE
WHEN 'John'
THEN 'Adam'
WHEN 'Doe'
THEN 'Teela'
WHEN 'Adam'
THEN 'Doe'
WHEN 'Teela'
THEN 'John'
END
4 rows updated.
michaels> SELECT *
FROM table1
ID VALUE
1 Adam
2 Teela
3 Doe
4 John
4 rows selected. -
Problem in doing an update statement
Hello all
i should write an update statement,
these tables : country: name,code,population,nextyearr_population ...
nextyear_population is empty,at first i should get population_growth from population table then calculate the next year population according to corrent population and population_growth
population: country(actually is code not name of country) ,population_growth,....
i wrote so and i got this error
Error starting at line 1 in command:
update country c
set c.nextyear_population=(c.population+ ((c.population*(select pop.population_growth from population pop join country co on co.code=pop.code))/100)
where country.code=population.country
Error at Command Line:4 Column:20
Error report:
SQL Error: ORA-00904: "POPULATION"."COUNTRY": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
-- File created - Wednesday-May-15-2013
-- DDL for Table COUNTRY
CREATE TABLE "intern"."COUNTRY" ("NAME" VARCHAR2(40), "CODE" CHAR(2), "CAPITAL" VARCHAR2(40), "PROVINCE" VARCHAR2(40), "POPULATION" NUMBER, "AREA" NUMBER, "NEXTYEAR_POPULATION" NUMBER)
COMMENT ON COLUMN "intern"."COUNTRY"."NAME" IS 'the country name'
COMMENT ON COLUMN "intern"."COUNTRY"."CODE" IS 'the internet country code (two letters)'
COMMENT ON COLUMN "intern"."COUNTRY"."CAPITAL" IS 'the name of the capital'
COMMENT ON COLUMN "intern"."COUNTRY"."PROVINCE" IS 'the province where the capital belongs to'
COMMENT ON COLUMN "intern"."COUNTRY"."POPULATION" IS 'the population number'
COMMENT ON COLUMN "intern"."COUNTRY"."AREA" IS 'the total area'
COMMENT ON TABLE "intern"."COUNTRY" IS 'the countries of the world with some data'
REM INSERTING into intern.COUNTRY
SET DEFINE OFF;
Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Andorra','ad','Andorra la Vella','Andorra la Vella',69865,468,null);
Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('United Arab Emirates','ae','Abu Dhabi','Abu Dhabi',2523915,82880,null);
Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Afghanistan','af','Kabul','Kabul',28513677,647500,null);
-- File created - Wednesday-May-15-2013
-- DDL for Table POPULATION
CREATE TABLE "intern"."POPULATION" ("COUNTRY" CHAR(2), "POPULATION_GROWTH" NUMBER, "INFANT_MORTALITY" NUMBER)
COMMENT ON COLUMN "intern"."POPULATION"."COUNTRY" IS 'the country code'
COMMENT ON COLUMN "intern"."POPULATION"."POPULATION_GROWTH" IS 'population growth rate (percentage, per annum)'
COMMENT ON COLUMN "intern"."POPULATION"."INFANT_MORTALITY" IS 'infant mortality (per thousand)'
COMMENT ON TABLE "intern"."POPULATION" IS 'information about the population of the countries'
REM INSERTING into intern.POPULATION
SET DEFINE OFF;
Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ad',0.95,4.05);
Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ae',1.54,14.51);
Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('af',4.77,163.07);thank you in advance
im using oracle11g and ubuntu 12
best,davidHi, David,
Thanks for posting the CREATE TABLE and INSERT statements.
Don't forget to post the results you want from thatsample data (that is, the contents of country after everything is finished).
1003209 wrote:
... i wrote so and i got this error
Error starting at line 1 in command:
update country c
set c.nextyear_population=(c.population+ ((c.population*(select pop.population_growth from population pop join country co on co.code=pop.code))/100)
where country.code=population.country
Error at Command Line:4 Column:20
Error report:
SQL Error: ORA-00904: "POPULATION"."COUNTRY": invalid identifier
00904. 00000 - "%s: invalid identifier"
In the UPDATE statement itself (outside of sub-queries) you can only reference the table being UPDATEd, but in the WHERE clause:
where country.code=population.countryyou're trying to reference another table, population. That's what caused the error.
You either need another sub-query, or MERGE, which will probably be simpler and more efficient than UPDATE.
Maybe you are looking for
-
Crystal Report 9.0 and Websphere
hi can any body give me some steps regarding integration of crystal report and websphere i have already search this forum and i got lot many topics regarding this but all were using cyrstal report version 8 and 8.5 which requires mandatory using IIS
-
Address Book and Sync Issues with Verizon Curve
I got my first BB about a month ago and like it, for the most part. I have three major issues with it now: 1. SYNC I've downloaded and installed the latest software from pocket mac and my first sync went fine (I have a MacBook Pro running 10.4.11
-
Untrusted server cert chain for HTTPS on tomcat
I have written 2 servlets 1)One for sending username and password over HTTPS 2)One for receiving the username and password and decrypting this When I am executing the 1st servlet,i get the exception : Error is client : javax.net.ssl.exception.:untrus
-
Debit and credit note - integration between mm & sd with fi
Hi, How does the information flow from MM & SD to FI in the process of raising a DEBIT and CREDIT NOTES' respectively? (I'm aware of the fact that we need to define the document types "KG" and "DG" and raise the aforementioned by using F-41 & F-27).
-
Applets loading issue in Weblogic portal 10.3 - urgent
Hi, We are upgrading WLP 8.1 to WLP 10.3, I am facing an issue on loading an applet on the client browser getting class not found exception. The applet tag in WLP 8.1 ================= <applet name="ThisApplet" code="PrintFormApplet.class"