Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Decode function in Update statement

885303Aug 29 2011 — edited Aug 30 2011
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!
This post has been answered by Tubby on Aug 29 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2011
Added on Aug 29 2011
7 comments
13,915 views