Solved

Need procedure assistance

Posted on 2012-04-09
2
212 Views
Last Modified: 2012-06-27
Good evening,

I have two tables one is BASE_TABLES with table_id, table_name, and a few other cols.
The other is BASE_TABLE_COLS  with table_id, col_name, col_Alias

I would like to build a query based on the requisite table columns of the base tables.

that would be something like  'select '||col_name1||' , '||col_alias1||' ,...'||col_n||' from '||base_table ;
How could I build that query string in the procedure then execute into a ref_cursor?

Any assistance would be greatly appreciated.
0
Comment
Question by:Focker513
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 500 total points
ID: 37826459
check in this site, you can see how to use a refcursor

http://www.oracle-base.com/articles/misc/using-ref-cursors-to-return-recordsets.php

and for your code, you just have to use dynamic sql for using refcursor..

just posting a sample reference code. you can make the prepare the whole code basis on this approach

ie., store the sql in a variable

declare
cur_contr_details refcursor;
v_var varchar2(1000);
begin
v_var:= 'select '||col_name1||' , '||col_alias1||' ,...'||col_n||' from '||base_table ;
  OPEN cur_contr_details FOR v_var;

....
OPEN cur_contr_details FOR sql_stmt1 USING i.sncode;
0
 
LVL 2

Expert Comment

by:datakeyword
ID: 37826654
why not try esProc to solve it?
esProc is a tool for mass data computation, especially fit for the complex data computation like yours.
Check below for more details :http://www.esproc.com/library/product/bid-farewell-to-stored-procedure.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question