Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Conditional / Dynamic SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-14-08, 16:47
tgrebe tgrebe is offline
Registered User
 
Join Date: Oct 2008
Posts: 1
Conditional / Dynamic SQL

Hello

I am trying to figure out if it's possible to use conditional sql in Oracle 9i to write an SQL statement such as the following;

select a.itema, b.itemb, c.itemc
from tablea a, tableb b, tablec c
where a.index=b.index and a.index=c.index

This needs to be one global, dynamic or conditional SQL query that runs across multiple users in the instance. The users may have some different attributes for these items and tables. For instance, for some of the users, itemb in tableb is called itemb1, other users do not have tablec at all. I've tried fooling around with the CASE statment a little, but no success so far. Any help would be appreciated.
Reply With Quote
  #2 (permalink)  
Old 10-15-08, 08:01
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
Wow, what a mess your database must be in!

You can interrogate ALL_TABLES and ALL_TAB_COLUMNS to find out the names of tables owned by any user, and then construct dynamic SQL like this:

Code:
declare l_sql long; c sys_refcursor; ... begin l_sql := 'select ' || l_col1 || ' from ' || l_table_name1 || ' where '...; open c for l_sql; loop fetch c into ...; exit when c%notfound; ... end loop; end;
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On