View previous topic :: View next topic
|
Author |
Message |
chiru_sh
New User
Joined: 21 Feb 2008 Posts: 18 Location: Mumbai
|
|
|
|
Hi,
I am new to DB2. I want to update column by 8%. Can anybody let me know, how we can do this. Suppose my table is
TABLE: EMP
EMP_ID SALARY
30301 50000
50010 20000
40010 40000
I want to increase SALARY by 8%.
Can anybody help me in this.Thanks in advance. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
SET SALARY = SALARY + .08(SALARY)? |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
UPDATE EMP SET SALARY = SALARY * 1.08 |
|
Back to top |
|
|
chiru_sh
New User
Joined: 21 Feb 2008 Posts: 18 Location: Mumbai
|
|
|
|
Thanks you very much...in COBOL whether i need to declare cursor or directly i can give this query..... |
|
Back to top |
|
|
Richa Jain
New User
Joined: 18 Mar 2008 Posts: 35 Location: Gurgaon
|
|
|
|
Yes, you can use it directly in a cobol program. |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
usually CURSORS are not required for updation of the table. They are used while fetching the records from the table. |
|
Back to top |
|
|
mkk157
Active User
Joined: 17 May 2006 Posts: 310
|
|
|
|
Quote: |
usually CURSORS are not required for updation of the table |
Note that UPDATE operations can be performed in one of two ways:
1) By performing a searched update operation
Ex: UPDATE EMPLOYEES SET SALARY = NULL
UPDATE EMPLOYEES SET SALARY = SALARY * 1.08
WHERE EMP_ID = 30301
2) By performing a positioned update operation.
To perform a positioned update, a cursor must first be created, opened, and positioned on the row that is to be updated. Then, the UPDATE statement that is to be used to modify one or more data values must contain a WHERE CURRENT OF [CursorName] clause (CursorName identifies the cursor being used—we'll look at cursors shortly). Because of their added complexity, positioned update operations are typically performed by embedded SQL applications.
EXEC SQL
UPDATE EMP
SET SALARY = :WS-SALARY
WHERE CURRENT OF CURSOR_1
END-EXEC |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
chiru_sh wrote: |
Thanks you very much...in COBOL whether i need to declare cursor or directly i can give this query..... |
I'd go for the CURSOR option (+Commit) in case the number of rows afected is high...it could be other programs couldn't access that table. |
|
Back to top |
|
|
|