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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Conditional SQL query based on if column is NULL or '' or not

M.EmmanuelDec 20 2018 — edited Dec 20 2018

Hi,

I have the following query:

_SELECT (CANONICAL\_NAME || ', ' || ALIASES || ' (' || DESCRIPTION || ')' ) D, ID R FROM WP\_ENCODING_

This is used for a list of values in Oracle APEX. Examples of the output for value D are:

pastedImage_2.png

When column ALIASES is null or '', I would like to have the following SQL query instead:

_SELECT (CANONICAL\_NAME || ' (' || DESCRIPTION || ')' ) D, ID R FROM WP\_ENCODING_

So basicaly I would like to remove this:

', ' || ALIASES ||

when ALIASES is null or ''.

Which would be the way to achieve this in SQL? If doing directly in SQL is not possible, how could I write a PL/SQL function body returning a SQL query which is what Oracle APEX can use as List of Value?

I am using Oracle 18c XE in case it is relevant.

Thanks,

This post has been answered by mathguy on Dec 20 2018
Jump to Answer
Comments
Post Details
Added on Dec 20 2018
10 comments
2,710 views