• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

How do i generate a MDX query in Oracle 9i?

I have 2 tables APPLICATIONS and APPLICATION_COLUMNS

1. APPLICATIONS has 25 Flex fields namely C01, C02, C03 ,etc.
2. The table APPLICATION_COLUMNS tells which Flex Fields needs to be displayed.
This data in this table will be stored as this.
Column Name | Field Name | Description|
1.C01|Columns Name|Some Description|
2.C02|Columns Name|Some Description|
3.C03|Columns Name|Some Description|

Now depending on the existence of this Column Name i.e. C01\C02\C03 in the above table APPLICATION_COLUMNS,I need to display those flex fields from APPLICATIONS table.

Let me know if more information is needed

Thanks

0
P_Ramprathap
Asked:
P_Ramprathap
  • 3
1 Solution
 
DrSQLCommented:
P_Ramprathap,
     It would have to be dynamic.  You can't translate a value into a column reference in the same query.  But, you can build your query using the "application_columns" table.  If you're using SQL*Plus you can generate the query into a file using the spool command and then execute it.  If you're using pl/sql or a programming language you'd build a string and then execute it according to the dynamic SQL approach you prefer (note that execute immediate would need to have a set number of columns returned).  Here's an untested SQL*Plus approach:

set head off
set timing off
set time off
set sqlprompt off
set lines 100
set pages 0
set show off
set verify off
col segment noprint

select 1 segment,decode(column_name,'C01','select <id columns>,', ', ') || column_name || ' as ' ||
          field_name
from application_columns
union all
select 2, '  from applications;' from dual

spool myquery.sql
/
spool off

set pages 40
set head on
set timing <whatever you normally use>
set time <whatever you normally use>
set sqlprompt on
set lines <whatever you normally use>
set show on
set verify o
start myquery
0
 
DrSQLCommented:
P_Ramprathap,
    It's been over a month.  Could you please update this question?  Thank you for using Experts Exchange.

Good luck!
0
 
DrSQLCommented:
P_Ramprathap,
    Sorry, but a "no" answer and a proposal of another approach does not mean that you didn't receive fair value for your question.  I explained the limitation (that you were not aware of) and showed you a method to use.  That's a legitimate answer.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now