suppose in my table 10 rows are there , i want to update odd
rows salary as 90000 ? how u do it ? any one help me ? what
do we use here cursor-fetch or normal sql ?
Answers were Sorted based on User's Feedback
Answer / pandu
Hi Krishna, Actually your answer is ok but i have a small
doubt "he want to update odd rows salary as 9000" but in ur
answer i didn't find the odd rows.how will you divide that
table in odd rows and even rows? kindly tell me.
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / vaneeshkhurana
Basically we can create a structure where first fetch then
update the fetch 2 times and update once again fetch 2 times
and update once again fetch 2 times and update once... and
keep on fetching 2 times and updating it once till table
code 100 comes.
This will update only the odd rows.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / saurabh
It can be achieved using the scroll able cursor along with the Relative option while updating the queue.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / harsha
The first answer is correct. It has a logic to select only
ODD rows(look at the two fetch statements).
Another logic to select only ODD rows.
SELECT SAL FROM EMP WHERE MOD(SAL,2)=1
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / krishna
Declare:
EXEC SQL
DECLARE CURSOR C1 FOR SELECT SAL FROM EMP FOR
UPDATE SAL
END-EXEC.
OPEN:
OPEN C1
FETCH:
PERFORM UNTILL SQLCODE=100
FETCH C1 INTO :SAL
UPDATE EMP SET SAL=9000 WHERE CURRENT OF C1
FETCH C1 INTO :SAL
END-PERFORM
Is This Answer Correct ? | 10 Yes | 13 No |
what is the total syntax for fetch ? can any one please give me all the details of fetch ? thx
How do you eliminate duplicate values in db2?
what are the bind parameters?
What is correlation names?
When can an insert of a new primary key value threaten referential integrity?
How to solved 818 error
4 Answers Keane India Ltd, Wipro,
What is db2 instance?
What are the three DB2 date and time data types and their associated functions?
What is correlated subquery?
wht are the restrictions for union ?
In a Cobol-DB2 program, I am fetching rows from 4 tables using cursor and then based on the a field present in that table, It processes the information accordingly..for example stat-c is one digit field..if stat-c is 'D' then the a row is deleted from table and written those details in to a file. If the stat-c is 'U' then a row is updated (hardcoded what to update)in a table and written those details in to a file. If the stat-c is 'I' then a row is inserted in a table and written those details in to two files. The issue is i have to include the intermediate commits. When an abend occurs, due to commit statement db2 tables will be saved, But there will be lose of file contents. When we resubmitting the job associated with this program there will be insert ,update and delete anomolies to avoid that what measures could be taken?. The intermediate commit is nothing but issuing commit after massive inserts, updates and deletes(sum of 500actions)
I have a main program (A) where we delete some rows in table in a cursor, and we commit it in sub program(B). What will happen - will we get an error or not?