Need to return data from a query in different ways - Please help

We are using 10g R2
I have a proc as follows that has a query with over 100 values in the select clause:
proc one( input param1, input_param2,.... output_cursor )
as
begin
open cursor for
select ...about 100 values with most of them being calculated
from table1, view 1, table2, table 3, view 2 ...
where ....
and table1.col1 = input param1
and table1.col2 = input param 2
and view1.col5 = input param5...
end;
I need to return the data that comes from the above query in different formats, columns for a report would be different from columns for screen A and different for screen B. I need only certain columns for a report and different set of columns for another screen. I have wrapper procs that get different input params. From the wrapper procs I intend to call the above proc but would like only selected values.
How can I accomplish this? Since my main goal is to select different columns for each wrapper I was thinking of insert the data from the above proc into global temp table and selecting whatever columns and order I want from the wrappers.
What do you think? Any other solutions?
Thanks
Edited by: user565033 on Jan 21, 2013 7:50 PM

You need to clearly separate roles and responsibilities. The PL/SQL code that creates and supplies a cursor handle is server code tasked to supply data. The code that makes the call for server data, is responsible for formatting and rendering that data.
Thus moving data formatting into the server code needs to be question. Simple example. Cursor does not return invoice date as a date - but formats it into a string using TO_CHAR().
This works for client1 - as that is the date format expected. However, client2 has different International settings and specifies a different date format. Invoice date, formatted into a string by the server, now renders in the wrong format on client2.
Server code should not be concerned with rendering and formatting of data send to a client.
As for the idea to use a global temp table is ..., well to put it nicely, it smells. Badly.
The single most expensive operation on a database platform is I/O. And now you want to read server data and write it to temporary storage, and the read data from temporary storage to return to the client? What on earth for!? Why purposefully increase the size of the I/O workload? Why decrease performance and undermine scalability?
Provide a proper abstraction interface to the client. Enable it to specify (as simplistically as possible) what it wants ito data. There are a number of ways to design and implement this in PL/SQL. Simplistic example:
SQL> create or replace package Employees as
  2 
  3          EMP_FULL_DETAILS        constant integer := 1;
  4          EMP_BASIC_DETAILS       constant integer := 2;
  5 
  6          procedure GetEmpByID(
  7                  cur out sys_refcursor,
  8                  empID in emp.empno%type,
  9                  template in integer default EMP_BASIC_DETAILS
10          );
11 
12          procedure GetEmpByName(
13                  cur out sys_refcursor,
14                  empName in emp.ename%type,
15                  template in integer default EMP_BASIC_DETAILS
16          );
17  end;
18  /
Package created.
SQL>
SQL> create or replace package body Employees as
  2 
  3  type TArray is table of varchar2(32767);
  4 
  5  TemplateList       constant TArray :=
  6          new TArray(
  7                  'EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO ',
  8                  'EMPNO, ENAME, JOB '
  9          );
10 
11  procedure GetEmpByID(
12          cur out sys_refcursor,
13          empID in emp.empno%type,
14          template in integer default EMP_BASIC_DETAILS
15  ) is
16          sqlSelect       varchar2(32767);
17  begin
18          sqlSelect :=
19                  'select '||TemplateList(template)||
20                  'from emp where empno = :empID';
21 
22          open cur for sqlSelect using empID;
23  end;
24 
25  procedure GetEmpByName(
26          cur out sys_refcursor,
27          empName in emp.ename%type,
28          template in integer default EMP_BASIC_DETAILS
29  ) is
30          sqlSelect       varchar2(32767);
31  begin
32          sqlSelect :=
33                  'select '||TemplateList(template)||
34                  'from emp where ename like :empName';
35          open cur for sqlSelect using empName;
36  end;
37 
38 
39  end;
40  /
Package body created.
SQL>
SQL> var c refcursor
SQL>
SQL> exec Employees.GetEmpByID( :c, 7499 );
PL/SQL procedure successfully completed.
SQL> print c
     EMPNO ENAME      JOB
      7499 ALLEN      SALESMAN
SQL>
SQL> exec Employees.GetEmpByName( :c, 'A%', Employees.EMP_FULL_DETAILS );
PL/SQL procedure successfully completed.
SQL> print c
     EMPNO ENAME      JOB               MGR HIREDATE                   SAL       COMM     DEPTNO
      7499 ALLEN      SALESMAN         7698 1981/02/20 00:00:00       1600        300         30
      7876 ADAMS      CLERK            7788 1987/05/23 00:00:00       1100                    20
SQL>

Similar Messages

  • Open HUB ( SAP BW ) to SAP HANA through DB Connection data loading , Delete data from table option is not working Please help any one from this forum

    Issue:
    I have SAP BW system and SAP HANA System
    SAP BW to SAP HANA connecting through a DB Connection (named HANA)
    Whenever I created any Open Hub as Destination like DB Table with the help of DB Connection, table will be created at HANA Schema level ( L_F50800_D )
    Executed the Open Hub service without checking DELETING Data from table option
    Data loaded with 16 Records from BW to HANA same
    Second time again executed from BW to HANA now 32 records came ( it is going to append )
    Executed the Open Hub service with checking DELETING Data from table option
    Now am getting short Dump DBIF_RSQL_TABLE_KNOWN getting
    If checking in SAP BW system tio SAP BW system it is working fine ..
    will this option supports through DB Connection or not ?
    Please follow the attachemnet along with this discussion and help me to resolve how ?
    From
    Santhosh Kumar

    Hi Ramanjaneyulu ,
    First of all thanks for the reply ,
    Here the issue is At OH level ( Definition Level - DESTINATION TAB and FIELD DEFINITION )
    in that there is check box i have selected already that is what my issue even though selected also
    not performing the deletion from target level .
    SAP BW - to SAP HANA via DBC connection
    1. first time from BW suppose 16 records - Dtp Executed -loaded up to HANA - 16 same
    2. second time again executed from BW - now hana side appaended means 16+16 = 32
    3. so that i used to select the check box at OH level like Deleting data from table
    4. Now excuted the DTP it throws an Short Dump - DBIF_RSQL_TABLE_KNOWN
    Now please tell me how to resolve this ? will this option is applicable for HANA mean to say like , deleting data from table option ...
    Thanks
    Santhosh Kumar

  • I need a script for my following query... Please help

    I have files like
    customername_photonumber_version
    customername-photonumber-version
    reliance_123456_002
    reliance_123456_001
    reliance-123456-001
    reliance_123456_001.01
    reliance_111111_002
    reliance_111111_001
    reliance-111111-001
    reliance_111111_001.01
    reliance_555555_002
    reliance_555555_001
    reliance-555555-001
    reliance_555555_001.01
    maruthi_555555_002
    maruthi_555555_001
    maruthi-555555-001
    maruthi_555555_001.01
    maruthi_232323_002
    maruthi_232323_001
    maruthi-232323-001
    maruthi_232323_001.01
    I want a script that creates a folder 555555 and copy all the contents irrespective of _001 or -001 _002 reliance etc to the same folder
    that is
    555555-> 
                    maruthi_555555_002
                    maruthi_555555_001
                    maruthi-555555-001
                    maruthi_555555_001.01
                    reliance_555555_002
                    reliance_555555_001
                    reliance-555555-001
                    reliance_555555_001.01
    and so on for all photo numbers. kindly help.
    Thanks in advance!!!!

    Check these out.
    http://www.google.com/search?client=safari&rls=en&q=macbook+13+inch+case&ie=UTF- 8&oe=UTF-8
    http://www.google.com/search?client=safari&rls=en&q=macbook+13+inch+rubberized+c ase&ie=UTF-8&oe=UTF-8

  • Returning data from child jdialog...problem

    Hello
    I have a parent form which calls a jdialog. I need to return data from the jdialog.
    So i have this class which contains the varaibles i want to set.
    public class ProtocolRecordType {
    public int num;
    public String name;
    I from my main i call this class and method. Now i seem to be able to set object values to try and do a pass by reference in teh constructor, but if i use the same variable in a method it says unresolved symbol. Most of the code was generated with netbeans ide.
    Can anybody explain this to me ?
    Thanks
    public class ProtocolsDialog extends javax.swing.JDialog {
    / Creates new form ProtocolsDialog */
    public ProtocolsDialog(java.awt.Frame parent, boolean modal, ProtocolRecordType protocol ) {
    super(parent, modal);
    initComponents();
    System.out.println("done constructor");
    // public int y=0;
    protocol.name="protoname"; <==========setting it here works, i can print this out when it returns to parent frame.
    private void Protocol1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    //protocol.name="aaaa";
    // ProtocolRecordType.name="";
    System.out.println("proto1 selected");
    protocol.name=("xxxtest"); +<=================this says cannot find symbol protocol.name+
    }

    Check out tjacobs.ui.dialogs.ParamDialog and tjacobs.ui.ex.SetupPane in TUS for two easy ways to do this

  • Transfer Data from a Query to DSO

    Hello,
    I have an APD to transfer data from a query to a 'Direct update DSO'. The execution of this APD times out since the volume of query data is very high.
    Is there an alternate way of transfering data from a query to DSO?
    Please suggest.
    Thanks!

    One way would be to extract the data from the existing cube using a function module that would mimic the query level filters and restrictions. That data can be populated into the new cube.
    I wud suggest u take the data from a non-aggregated layer (say a DSO below the cube).
    Also, check for the possibility of running the APD in multiple runs by using some kind of selection that would sum up to give u the whole data required.
    Can u confirm if ur query itself is getting timed out?
    -PA1

  • The ways to return data from a stored procedure.

    Hi, I know there are three ways to pass out a value from a Microsoft SQL stored procedure, but I have no clear idea what Oracle SP can do, I know Oracle doesn't support multi-recordset(v8), can not return a recordset by a inner select query, but I do know there is a cursor object, which doesn't like its counterpart in Microsoft SQL server, is a choice under most situation. Here I wonder anyone who is good at Oracle can give a list of all ways to return data from a SP, including example is more better, thanks.

    Here is a way to get return a record from a function and a procedure. You need to be familiar with Oracle packages as well as stored procedures and functions:
    CREATE OR REPLACE PACKAGE EmpPkg AS
    cursor cEmp(pEmpno in number) is
    select empno, ename, job, hiredate, sal
    from emp
    where empno = pEmpno;
    FUNCTION GetEmployee(pnEmpNo in number) RETURN cEmp%rowtype;
    PROCEDURE GetEmployee(pnEmpNo in number, prEmp out cEmp%rowtype);
    END;
    CREATE OR REPLACE PACKAGE BODY EmpPkg AS
    FUNCTION GetEmployee(pnEmpNo in number) RETURN cEmp%rowtype IS
    rEmp cEmp%rowtype;
    BEGIN
    open cEmp(pnEmpNo);
    fetch cEmp into rEmp;
    close cEmp;
    return rEmp;
    END;
    PROCEDURE GetEmployee(pnEmpNo in number, prEmp out cEmp%rowtype) IS
    BEGIN
    open cEmp(pnEmpNo);
    fetch cEmp into prEmp;
    close cEmp;
    END;
    END;
    Here's how you use the package:
    DECLARE
    rEmp EmpPkg.cEmp%rowtype;
    BEGIN
    rEmp := EmpPkg.GetEmployee(7782);
    dbms_output.put_line(rEmp.ename);
    EmpPkg.GetEmployee(7902, rEmp);
    dbms_output.put_line(rEmp.ename);
    END;
    Note that you can return any Oracle data type from a function. Likewise, you can specify any Oracle data type as an out parameter in a procedure. Also, you can make a parameter both an in and an out datatype like this:
    PROCEDURE GetEmployee(pnEmpNo in out number);
    I hope this puts you in the right direction.
    null

  • How to Sort by the length of the returned value from a query.

    Hi,
    I was wondering if it is possible to sort by the length of the returned value from a query?
    For example if I want to get a list of people with the name 'Samuel', I would like to short by how short the length of the whole name is.
    Sort by length of the name in SQL
    Samuel Syda
    Samuel Indranaka
    Samuel Johnsons
    Samuel Longhenderson
    Thank you.

    Hi,
    Sorting is done by an ORDER BY clause at the end of the main query.
    In most cases, you can ORDER BY any expression, even f it is not in the SELECT clause.  In this case, it sounds like you just need:
    ORDER BY  LENGTH (name_column)
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Post your query, using an ORDER BY clause like the one above, and point out where that query is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Bapi to get data from BW query

    Hi,
    Does anyone familiar with bapi function to get data from BW query .???
    I'm trying to use  RS_VC_GET_QUERY_VIEW_DATA_FLAT  but i get only the SUM rows of the query
    and not the details rows (drill down).
    i want to export the data of BW query to table and i need all the query data.
    if someone have an example or documention its will be great.
    Thanks.

    Hi,
    Does anyone familiar with bapi function to get data from BW query .???
    I'm trying to use  RS_VC_GET_QUERY_VIEW_DATA_FLAT  but i get only the SUM rows of the query
    and not the details rows (drill down).
    i want to export the data of BW query to table and i need all the query data.
    if someone have an example or documention its will be great.
    Thanks.

  • Help needed to insert data from different database

    Hi ,
    I have a requirement where i need to fetch data from different database through database link .Depending on user request , the dblink needs to change and data from respective table from mentioned datbase has to be fetched and populated .Could i use execute immediate for this, would dblink work within execute immediate .If not , could pls let me know any other approach .

    What does "the dblink needs to change" mean?
    Are you trying to dynamically create database links at run-time? Or to point a query at one of a set of pre-established database links at run-time?
    Are you sure that you really need to get the data from the remote database in real time? Could you use materialized views/ Streams/ etc to move the data from the remote databases to the local database? That tends to be far more robust.
    Justin

  • How configure a primavera web service to return data from the second database?

    Hi everyone,
    We have P6 with first WS deployed on a single server weblogic domain. The first WS return data from the first database instance.
    Then deployed advanced second WS on a separate weblogic domain server with a different port. Configured second WS with <WS2_INSTALL_HOME>/bin/dbconfig.sh, creating a new branch of a configuration that specifies a different second instance of the database. However, this configuration is ignored and second web services return data from the first database.
    We have one domain, which including next servers:
    Name / Host / Port / Deployments
    P6 / localhost / 0001 / P6(v8.3), p6ws1(v8.3)
    p6ws2 / localhost / 0002 / p6ws2(v8.3)
    Now we have two different file BREBootstrap.xml.
    P6 BREBootstrap.xml:
    <Database>
    <URL>jdbc:oracle:thin:@db1:1521:db1</URL>
    <UserName>pubuser</UserName>
    <Password>anycriptopass1</Password>
    <Driver>oracle.jdbc.OracleDriver</Driver>
    <PublicGroupId>1</PublicGroupId>
    </Database>
    <CfgVersion>8.330</CfgVersion>
    <Configurations>
    <BRE name="P6 Config_DB1" instances="1" logDir="anydir/P6EPPM/p6/PrimaveraLogs"/>
    </Configurations>
    p6ws2 BREBootstrap.xml:
    <Database>
    <URL>jdbc:oracle:thin:@db2:1521:db2</URL>
    <UserName>pubuser</UserName>
    <Password>anycriptopass2</Password>
    <Driver>oracle.jdbc.OracleDriver</Driver>
    <PublicGroupId>1</PublicGroupId>
    </Database>
    <CfgVersion>8.330</CfgVersion>
    <Configurations>
    <BRE name="P6 Config_DB2" instances="1" logDir="anydir/P6EPPM/ws2/PrimaveraLogs"/>
    </Configurations>
    ‘P6 Config_DB1’ and ‘P6 Config_DB2’ including Database property for 1 and 2 database respectively.
    How to configure a second web service to return data from the second database?
    Thanks in advance!
    Regards,
    Dmitry

    OK, so I got this to work this morning with Username Token Profile (with little help from Oracle Support).
    I followed your steps 1-4 but in step 2 I didn't add the -Ddatabase.instance=2 because I want to check to see if my code could swap between different instances.
    It appears for Username Token Profile to use Database Instance, you need to set it in the soap header.
    So my soap request looks like this:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <s:Header>
            <DatabaseInstanceId xmlns="http://xmlns.oracle.com/Primavera/P6/WS/Authentication/V1">2</DatabaseInstanceId>
            <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                <u:Timestamp xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' u:Id='uuid-327b6ed1-b26d-4a61-81d5-e326174c1961-3'>
                    <u:Created>2014-10-23T04:28:01.152Z</u:Created>
                    <u:Expires>2014-10-23T04:29:01.152Z</u:Expires>
                </u:Timestamp>
                <o:UsernameToken u:Id='uuid-327b6ed1-b26d-4a61-81d5-e326174c1961-3' xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
                    <o:Username>admin</o:Username>
                    <o:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>password</o:Password>
                    <o:Nonce EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'>vJBQhCc28bAeszej7gOaiC2tVCQ=</o:Nonce>
                    <u:Created>2014-10-23T04:28:01.152Z</u:Created>
                </o:UsernameToken>
            </o:Security>
        </s:Header>
        <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <ReadProjects xmlns="http://xmlns.oracle.com/Primavera/P6/WS/Project/V2">
                <Field>ObjectId</Field>
                <Field>Id</Field>
                <Field>Name</Field>
                <Field>Status</Field>
                <Field>StartDate</Field>
                <Field>FinishDate</Field>
                <Field>DataDate</Field>
                <Filter>Id = 'EC00515'</Filter>
            </ReadProjects>
        </s:Body>
    </s:Envelope>
    This request pulled the project from the second instance.
    V/r,
    Gene

  • I need to download data from Oracle data base into a Excel spread sheet

    I need to download data from Oracle data base into a Excel spread sheet.
    Any input will be appreciated.

    Goes something like this:
    1) create an ODBC connection (on NT/WIN: ODBC DATA SOURCES in the control panel, create a USER DSN.
    2) in EXCEL-menu: DATA->GET EXTERNAL DATA->CREATE NEW QUERY. In the wizzard you will see the DSN created in the previous step. Select that source.
    3) follow the wizzard.
    Hope this does any good...
    Regards,

  • Need to convert  Date from calendar to String in the format dd-mom-yyyy

    Need to convert Date from calendar to String in the format dd-mom-yyyy+..
    This is absolutely necessary... any help plz..
    Rgds
    Arwinder

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • Return data from all columns apart from a certain data type.

    Bit stuck on something, hope somebody here can help:
    I want to do a 'select * from ' a table, to return all columns except ones of a certain datatype. ie. I want to return data from all columns, excluding columns of datatype 'SDO_GEOMETRY'.
    This gives me the list of columns:
    SELECT COLUMN_NAME
    FROM   USER_TAB_COLUMNS
    WHERE TABLE_NAME = 'ORDER_ITEM'
    AND   DATA_TYPE <> 'SDO_GEOMETRY'; But I can't seem to take it any further...
    Now if I knew the columns beforehand, then of course I could just list them, excluding the geometry column, but this is to be used for a plug-in for MS Word, where a user can pick database columns to dynamically fill a report from - but I don't want the geometry columns as these can't be handled in this way.

    Hi Reggie,
    > connects to the database and presents a list of tables
    My guess is that this macro is written so it selects from all_tab_cols.
    Change that plugin and let it select from a view like the one above. That way, the users won't be able to see/pick anything that you are not able/willing to present for them.
    Edit:
    You could even tease your users, and let them see the columns, but not being able to pick them.
    create or replace view available_tab_columns
    as
       select decode(pickable.data_type, null, 0, 1) pickable
             ,atc.* -- narrow down yourself
         from all_tab_cols atc  -- or maybe user_tab_cols
             ,(select 'CHAR' data_type from dual union all
               select 'DATE' from dual union all
            select 'NUMBER' from dual
               -- complete positive list, yourself
              ) pickable
        where atc.data_type = pickable.data_type(+);Regards
    Peter
    Message was edited by:
    Peter Gjelstrup

  • I need to copy data from a table in one database (db1) to another table in

    Hi
    I need to copy data from a table in one database (db1) to another table in another database (db2).
    I am not sure if the table exists in db2,,,if it doesnot it needs to be created as well data also needs to be inserted...
    How am I supposed to this using sql statements..?
    I shall be happy if it is explained SQL also...
    Thanking in advance

    How many rows does the table contains? There are manyway you can achieve this.
    1. export and import.
    2. create a dblink between two databases and use create table as select, if structure doesnot exists in other database, if structure exists, use, insert into table select command.
    example:
    create a dblink in db2 database for db1 database.
    create table table1 as select * from table1@db1 -- when there is no structure present
    -- you need to add constraints manually, if any exists.
    insert into table1 select * from table1@db1 -- when there is structure present.
    If the table contains large volume of data, I would suggest you to use export and import.
    Jaffar

  • I need to pass data from an Access database to Teststand by using the built in Data step types(open data

    base /open SQL Statement etc) the first time i defined the system everything was fine but when i changed the Database (using M.S.Access) the " open SQL Statement" it would show the tables but not thier columns ,I"m using win98 sec edition / Teststand 1.0.1i need to pass data from an Access database to Teststand by using the built in Data step types(open database /open SQL Statement etc) the first time i defined the system everything was fine but when i changed the Database (using M.S.Access) the " open SQL Statement" it would show the tables but not thier columns ,I"m using win98 sec edition / Teststand 1.0.1
    When I tried the same thing on another cmputer the same thing
    happend
    appreiciate u"r help

    base /open SQL Statement etc) the first time i defined the system everything was fine but when i changed the Database (using M.S.Access) the " open SQL Statement" it would show the tables but not thier columns ,I"m using win98 sec edition / Teststand 1.0.1Hello Kitty -
    Certainly it is unusual that you can still see the tables available in your MS Access database but cannot see the columns? I am assuming you are configuring an Open Statement step and are trying to use the ring-control to select columns from your table?
    Can you tell me more about the changes you made to your file when you 'changed' it with MS Access? What version of Access are you using? What happens if you try and manually type in an 'Open Statement Dialog's SQL string such as...
    "SELECT UUT_RESULT.TEST_SOCKET_INDEX, UUT_RESULT.UUT_STATUS, UUT_RESULT.START_DATE_TIME FROM UUT_RESULT"
    Is it able to find the columns even if it can't display them? I am worried that maybe you are using a version of MS Access that is too new for the version of TestSt
    and you are running. Has anything else changed aside from the file you are editing?
    Regards,
    -Elaine R.
    National Instruments
    http://www.ni.com/ask

Maybe you are looking for