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!

Using CASE in a dynamic sql query

KunwarJul 28 2011 — edited Jul 28 2011
Hi,
I want to create a dynamic query using the CASE statement to replace the below 2 SQL statements:

+++++
select 'create or replace synonym '|| SYNONYM_NAME || ' for '||TABLE_OWNER||'.'||TABLE_NAME||'@'||SUBSTR(db_link,1,30)||' ;' FROM USER_SYNONYMS where db_link is not null;
select 'create or replace synonym '|| SYNONYM_NAME || ' for '||TABLE_OWNER||'.'||TABLE_NAME||' ;' FROM USER_SYNONYMS where db_link is null;
+++++

So that i have a single select query which will give the create synonym statements for all with/without db links

Using the CASE statement example like given below :
SELECT
FirstName, LastName,
Salary, DOB,
CASE Gender
WHEN 'M' THEN 'Male'
WHEN 'F' THEN 'Female'
END
FROM Employees

I am not getting how to write this CASE statement. Can someone guide me here?

Thanks,
Kunwar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2011
Added on Jul 28 2011
6 comments
335 views