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!

Basic query using DECODE not working as expected.

Y.RamletJul 4 2013 — edited Jul 4 2013

Version:11.2.0.3

Platform: RHEL 5.8

I am trying to use DECODE function.

In the below example, If the search encounters the string "Enterprise" , then the decode should

return 'Enterprise' . But it doesn't seem to work.

I thought some hidden character was causing the issue, so, I used TRIM. But no luck.


SQL> create table t (banner varchar2(80));

Table created.

SQL> insert into t values ('Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from t;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SQL> select * from t where banner like '%Database%';

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

-- Trying to use decode. If the search encounters the string "Enterprise" , then return 'Enterprise'

-- Although the string "Enterprise" is present ,  decode doesn't seem to work.

-- I tried using trim , upper . But no luck.


SQL> select 'EDITION', decode(banner,'%Enterprise%','Enterprise','Standard') Edition from t where banner like '%Database%';

'EDITIO EDITION

------- ----------

EDITION Standard

SQL> select 'EDITION', decode(trim(banner), '%Enterprise%','Enterprise','Standard') Edition from t where trim(banner) like '%Database%';

'EDITIO EDITION

------- ----------

EDITION Standard

SQL> select 'EDITION', decode(upper(trim(banner)), '%ENTERPRISE%','Enterprise','Standard') Edition from t where upper(trim(banner)) like '%DATABASE%';

'EDITIO EDITION

------- ----------

EDITION Standard

SQL>

Just don't understand why decode can't see the string "Enterprise"

BTW . Where is the preview button ?

This post has been answered by Suri on Jul 4 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2013
Added on Jul 4 2013
7 comments
1,267 views