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 Instead of combination of SUBSTR 'n' INSTR?

AceNoviceJun 17 2009 — edited Jun 17 2009
Hi All,

I need your help for below 2 issues...

1. In my procedure, i am passing ID as parameter. For some of the code there will be 2 ids. Both IDs will be same except the 2nd ID will contain ~01 as last 3 characters.
ex: 20090617123456
20090617123456~01

Now i need to get the CODE from one table. This table maintains only one entry for type1 and type2 IDs. Let's say, table has entry ID=20090617123456 and CODE=007.

i have written following WHERE condition

WHERE file_id = in_file_id -- in_file_id is input paremeter.

But for type2, if i want to fetch CODE, i have modified the above WHERE condition.

WHERE file_id = SUBSTR(in_file_id, 1, (INSTR(in_file_id, '~')-1))

The code is working fine, but user says, do it using DECODE function. I am not able to achive the result using DECODE function. Can someone tell how to use DECODE function for the same or any other way to do so?
This post has been answered by Avinash Tripathi on Jun 17 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2009
Added on Jun 17 2009
6 comments
609 views