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 |
How do you insert a record with a nullable column?
I need to view the number of tables existing under one particular Owner. Is it possible? If so, pl give the SQL query for this?
what are bind concepts in db2 cobol?
How does DB2 store NULL physically?
This was related to -811 sqlcode, In a COBOL DB2 program which accesses employee table and selects rows for employee 'A', it should perform a paragraph s001-x if employee 'A' is present. In this case it gets -811 sqlcode, but still it process the paragraph s001-x. What could be wrong in my code.
What is an alias and how does it differ from a synonym?
What is the specific need of Plan and..where are the tables in DB2 are physically saved
What is cursor?
What is a db2 cursor?
What is the maximum size of varchar data type in db2?
Q1. How will you use two different DB2 qualifiers in a single COBOL program? Suppose we have 2 tables EMP1 and EMP2 with same structure defined in two different DB2 qualifiers QUAL1.EMP1 and QUAL2.EMP2 now during first 15 days we want to use QUAL1.EMP1 and rest of the days QUAL2.EMP2 how will we do this. We can create a single program and a single load for this program.
before altering a table is it necessary to lock ? if lock what is it ? how to do ? ifi want to lock a table what is that command ?