I need to return the result of a query on a stored procedure

I need to return the result of a query to a stored procedure, I mean when I run a stored procedure it returns a result set in a select statement.
Best regards...

Hello.

Do you really want a stored procedure for this?
Why not just a script that contains the query?

Assuming that you don't really want a stored procedure, you'll have to decide what to do with the results.
An option is a slider.

For example, you can write a procedure of this type to hold the query:

CREATE OR REPLACE PROCEDURE USP_TEST
(     out_cursor     OUT     SYS_REFCURSOR
)
IS
BEGIN
     OPEN  out_cursor
     FOR     SELECT     *
          FROM     scott.emp;
END  USP_TEST;
/
SHOW ERRORS

You can move the cursor to another procedure for handling.

You could test this in SQL * more by creating a variable blond:

VARIABLE     usp_test_cursor     REFCURSOR;

EXEC  usp_test (:usp_test_cursor);

PRINT     :usp_test_cursor

Tags: Database

Similar Questions

  • Need to print the results of a query in a CASE statement

    I want to print the results of a query in a CASE statement:

    SELECT RUN_STATUS

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where START_TS >

    (sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e

    The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.

    If I execute this statement, it throws an error stating:

    ORA-00937: not a single group group function

    00937 00000 - 'not a single-group function.

    * Cause:

    * Action:

    Error on line: 1 column: 96

    How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.

    Thanks in advance!

    Hey guys,.

    I found the solution:

    SELECT

    RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0

    THEN "NO JOB RAN.

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where

    START_TS > (select sysdate - XXAFL_MINUTES MINUTE))

    where

    RUN_STATUS is not null;

    The output:

    NO JOBS RAN AFTER 09:07:54

    Thanks to you all!

  • Export the results of a query to a CSV file

    Hello

    My requirement is that I need to export the results of a query to a CSV file. Can someone please suggest a way to also include the names of columns in the CSV file?

    Thanks in advance.

    Annie

    Following code comes from asktom. I changed to include the column header. This will get your CSV file desired for a given query.

    create or replace function  dump_csv( p_query     in varchar2,
                                          p_separator in varchar2
                                                        default ',',
                                          p_dir       in varchar2 ,
                                          p_filename  in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(2000);
        l_status        integer;
        l_colCnt        number default 0;
        l_separator     varchar2(10) default '';
        l_cnt           number default 0;
    
         l_colDesc          dbms_sql.DESC_TAB;
    begin
        l_output := utl_file.fopen( p_dir, p_filename, 'w' );
    
        dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
    
        for i in 1 .. 255 loop
            begin
                dbms_sql.define_column( l_theCursor, i,
                                        l_columnValue, 2000 );
                l_colCnt := i;
            exception
                when others then
                    if ( sqlcode = -1007 ) then exit;
                    else
                        raise;
                    end if;
            end;
        end loop;
    
        dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
    
        l_status := dbms_sql.execute(l_theCursor);
    
         dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
    
         l_separator := '';
    
         for lColCnt in 1..l_colCnt
         loop
                utl_file.put( l_output, l_separator ||  '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
                   l_separator := p_separator;
         end loop;
    
         utl_file.new_line( l_output );
    
        loop
            exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
            l_separator := '';
            for i in 1 .. l_colCnt loop
                dbms_sql.column_value( l_theCursor, i,
                                       l_columnValue );
                utl_file.put( l_output, l_separator ||  '"' ||
                                        l_columnValue || '"');
                l_separator := p_separator;
            end loop;
            utl_file.new_line( l_output );
            l_cnt := l_cnt+1;
        end loop;
        dbms_sql.close_cursor(l_theCursor);
    
        utl_file.fclose( l_output );
        return l_cnt;
    end dump_csv;
    

    The original link is below.

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:95212348059

    Thank you
    Knani.

  • PLSQL function to return the result of the query

    Dear all,

    Oracle Database SE1 11.2.0.1

    I need to create a plsql function which should accept SQL as a parameter, execute it and return the result set.

    Is this possible?

    Madhu.149 wrote:

    I need to create a plsql function which should accept SQL as a parameter, execute it and return the result set.

    Be careful - results games indicate a set of data stored in memory. This is not what are sliders. This isn't how Oracle should be used.

    Imagine that you implement such a result set function - which, on average, requires 1 MB of memory (private server) to store the results of the SQL query. A 100 users mean a 100 MB of memory required server. This is not suitable. Not at all. Never.

    The correct back 'thing' is a handle to SQL cursor (called a ref cursor in this case). A SQL cursor is a "program" - that the appellant runs via the fetch command and generates one or more lines accordingly. Appellant repeatedly runs this slider through calls to fetch until this slider found and returns all rows affected (using consistent readings).

    If you want an abstraction interface that the client can call via PL/SQL code in the database, so this crafting optimal SQL interface, creates the SQL cursor and returns the handle of the cursor (via the ref cursor data type) to the client.

  • Need to get the result of the required format

    Hi all

    I'll have the data in a table below:

    IDNUM1num2
    1555555
    2123345
    3456567
    4666666

    IDNUM1num2
    1555555
    2123345
    3456567
    4666666

    and they need to get the result as below:. Help, please...

    IDNUM
    1555
    2123
    2345
    3456
    3567
    4666

    Thanks in advance...

    Hello

    So, instead of having 2 columns on 1 row, you want to have 1 column on 2 rows.  It's just that UNPIVOT:

    SELECT DISTINCT

    ID, num

    D

    UNPIVOT (num

    FOR the label IN (num1, num2)

    )

    ORDER BY id, num

    ;

    It is more effective than the UNION, because it requires only 1 pass through the table.

  • Need to get the result of joing the views dba

    Hello

    need to get the result of the fileds below in a database

    TABLE_NAME NOM_PARTITION NOM_TABLESPACE PARTITION_TYPE (RANGE?) PARTITION_RANGE_CONDITION SPACE_OCCUPIED_AS_OF_DATE (IN GB)

    can I know what are the points of view that I can use and application

    apprecaited for assistance

    Thank you

    Published by: user12266475 on November 2, 2011 11:33

    LONG data type is NOT friendly SQL.
    Consider the following:

    SQL> @long
    SQL> drop table test;
    
    Table dropped.
    
    SQL> create table test (id LONG);
    
    Table created.
    
    SQL> insert into test values(q'[RANGE     TO_DATE(' 2009-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')]');
    
    1 row created.
    
    SQL> set serveroutput on
    SQL> DECLARE
      2  long_var LONG;
      3  var_var  VARCHAR2(2000);
      4  BEGIN
      5       dbms_output.enable(10000);
      6       SELECT id INTO long_var FROM test ;
      7       var_var := substr(long_var,19,19);
      8       dbms_output.put_line(var_var);
      9  END;
     10  /
    2009-01-01 00:00:00
    
    PL/SQL procedure successfully completed.
    
  • Reading number of XML nodes in a document &amp; amp; return the result in the text member

    Hi all

    I wonder if you can help me with the following:

    I want to read the number of nodes in an XML document and return the result in a text cast member. That's what I do so far, but he refuses to work

    Yes, my mistake. That should have been:
    --
    tList =
    nNodes = count(tList[1])
    sText = «»
    Repeat with i = 2 to nNodes
    tText = tList [1] .getPropAt (i)
    sText = sText & tText & RETURN
    end repeat
    -Remove rear BACK tank
    remove the last tank of sText
    -Place ALL the text in a text member
    Member ("test1"). Text = sText
    -- ...

  • Insert the result of a query select in another table

    Hello

    I have a strange problem when I try to insert all the results of a query select in another table, using the declaration of the order.

    With the declaration of COMMAND it works fine
    Work:
    ------------------------------
    INSERT INTO ADART01 (SELECT (codart)
    "STOCK". "" CODART_STO ".
    Of
    "DB". ' ' 'ACTIONS');
    ------------------------------

    But if I try to sort the result using the declaration of the ORDER, I have the following error:
    Error: ORA-00907 missing right parenthesis
    ------------------------------
    INSERT INTO ADART01 (SELECT (codart)
    "STOCK". "" CODART_STO ".
    Of
    "DB". "" "ACTIONS"
    ORDER BY
    "STOCK". ("' CODART_STO ASC ');
    ------------------------------

    Any idea?

    Thank you for your help,
    Angel.

    delete "()" to select

    create table test1 (a number, b varchar2(100));
    
    insert into test1
        (a, b)
        select level, 'level ' || level from dual connect by level < 101;
    
    insert into test1
        (a, b)
        select level, 'level ' || level from dual connect by level < 101 order by to_char(sysdate - level, 'D');
    
    select * from test1;
    
    drop table test1;
    
  • defining the results of a query to a variable

    Hi all

    I'm having a problem affecting the results of a query to a variable. What I'm trying to do, is to do an AJAX call to a .cfc file and pass back the results of the function. The main problem is, I'm again moving a block of HTML (resulting from a cfquery in a cfoutput) stored in a variable. My code is something like...

    < name cffunction = "getText" access = "remote" returntype = 'Cancel' >

    < datasource = "" #request.dsn # cfquery "name ="queryTable">"
    SELECT kort, infoB

    Of infoTable

    < / cfquery >


    < cfset result = ' <!-this is the part I'm stuck, I want the table go here. -> ">"

    < table >
    < cfoutput query = "tablequery" >
    < b >
    < td > #infoA # < table > < td > #infoB # < table >
    < /tr >
    < / cfoutput >
    < /table >


    < cfwddx action = "cfml2js" input = "" # result # ' toplevelvariable 'o' = > "

    < / cffunction >

    It is a simplified version of what I want to do, but you get the idea...

    Is it still the right way to go about this?  Thank you

    That's what I get for trying the E-mail response feature!  Are you not happy, that I double checked my post.

    You could do a lot of string concatenation here to do stuff like"& Kort &""& infoB &""> time and time again."  But in reality the tags is so much easier to use.



      

        
      

    #infoA #.#infoB #.

  • Error of insufficient privileges on the creation of model running in a stored procedure

    Hello

    I get the error of insufficient privileges on execution of the DBMS_DATA_MINING. Script CREATE_MODEL in a stored procedure.

    If I run the same DBMS_DATA_MINING. Script CREATE_MODEL in an anonymous block with just begin... end;

    I am able to create a model successfully, but if I do the same thing after having stored the script in the stored procedure, it is throwing error of insufficient privileges.

    Scripts:

    BEGIN

    DBMS_DATA_MINING. () CREATE_MODEL

    Model_name = > < template name >

    mining_function = > dbms_data_mining. CLASSIFICATION,

    DATA_TABLE_NAME = > < data table name >

    CASE_ID_COLUMN_NAME = > < case ID >

    target_column_name = > < target column >

    SETTINGS_TABLE_NAME = > < settings table >

    DATA_SCHEMA_NAME = > < schema >

    SETTINGS_SCHEMA_NAME = > < schema >

    );

    END;

    The foregoing, works very well and created a model with the model given with success.

    But if I keep the above, in a stored procedure as - MINING_TESTING

    create or replace procedure MINING_TESTING as

    BEGIN

    DBMS_DATA_MINING. () CREATE_MODEL

    Model_name = > < template name >

    mining_function = > dbms_data_mining. CLASSIFICATION,

    DATA_TABLE_NAME = > < data table name >

    CASE_ID_COLUMN_NAME = > < case ID >

    target_column_name = > < target column >

    SETTINGS_TABLE_NAME = > < settings table >

    DATA_SCHEMA_NAME = > < schema >

    SETTINGS_SCHEMA_NAME = > < schema >

    );

    END;

    Compiles correctly.

    Enforcement - EXEC MINING_TESTING;

    Error message throw sufficient privileges.

    The error message complete below:

    Error report:

    ORA-01031: insufficient privileges

    ORA-06512: at "SYS." DBMS_DATA_MINING', line 1798

    ORA-06512: at "MIS_ORABI_ODM.CA_MINING_TESTER", line 3

    ORA-06512: at line 1

    01031 00000 - "insufficient privileges".

    * Cause: An attempt was made to change the user name or password

    without the privilege appropriate. This error also occurs if

    trying to install a database without the need for employment

    access privileges.

    When Trusted Oracle is configure in DBMS MAC, this error may occur

    If the user has been granted the privilege necessary for a higher label

    that the connection is active.

    * Action: Ask the database to perform the operation or grant administrator

    the required privileges.

    For users Trusted Oracle get this error, well that granted the

    the privilege that is suitable for the top label, ask the database

    administrator to grant the privilege to the appropriate label.

    Hello

    DataMiner UI grants privileges to a role, so if you're depending on these privileges you must proceed as follows when you create a stored procedure.

    Your stored procedure was created with the default authid which is definers. It will not use the privileges for the role. Solution is to create the stored procedure with authid current_user. This will pick up the privileges for the role. Another option is to apply the following subsidies directly to the user account:

    grant CREATE MINING MODEL

    CREATE THE TABLE,

    IN ORDER TO CREATE

    Example of stored procedure:

    create or replace procedure MINING_TESTING AUTHID CURRENT_USER as

    BEGIN

    DBMS_DATA_MINING. () CREATE_MODEL

    MODEL_NAME =>

    mining_function-online dbms_data_mining. CLASSIFICATION,

    DATA_TABLE_NAME =>

    CASE_ID_COLUMN_NAME =>

    target_column_name =>

    SETTINGS_TABLE_NAME =>

    DATA_SCHEMA_NAME =>

    SETTINGS_SCHEMA_NAME =>

    );

    END;

    Thank you, Mark

  • ProBook 4530 s: why do I need to return the old part, if I buy a new game?

    Well, I had a problem with my motherboard and replaced by a technician on-site in that HP sent me.

    The laptop is out of warranty, and I paid for the new motherboard + labor.

    However, when technology is introduced, he said it does not replace the motherboard unless I give him the old motherboard. He went on to say that it wascompany policy"and it won't let me keep all old, even though I pay for the new component.

    I was too tired t o argue with him, and he has replaced the motherboard and took the old motherboard.

    Reflection, it is quite absurd.

    It's like HP telling me "If you buy a new HP laptop, you will need to return your old HP laptop to us.

    It would make sense that I was getting a free replacement and the laptop was under warranty. It makes no sense when the laptop is out of warranty and that I pay for the replacement part.

    Think about it, when I bought the laptop, I obviously paid for the motherboard that came with the notebook. Then why HP becomes to take away from me?

    If I buy a new battery from HP store instead of amazon, I need to regain my old HP battery?

    If I buy a new keyboard on the HP store, should I return my old keyboard?

    I can give you the file number if you wish.

    Honestly, if it's the "strategy of the company", I never bother with another HP product again.

    HP has new motherboards. They sell the bad on the Chinese market and they appear on eBay or similar places. You have a new motherboard. If you can tell us the number of part of what you purchased we can tell you the "full" price and the "Exchange" of the party. They should definitely explain the options for you, but I think probably, they assume you want the lowest trading price.

  • my text on the LCD display is turn on the side, I need to return the screen

    need to return my screen is sideways

    need to return my screen is sideways

    If the entire screen turned sideway, there are 2 ways to fix...

    1. press the keys Alt Ctrl + set > up/down, left/right arrow keys to "flip" your screen back to normal.
    2. right click on a free space of the office > graphics > Rotation > choose the appropriate degree.
    NOTE: I would like to use #1. I find the #2 method that is difficult to use because I can't control my cursor on the Rotation mode.

    t-4-2

  • In Windows 7, why cursor moves when you type, causing need to return the position of the cursor?

    After inserting the cursor to start typing, the cursor moves frequently on his own.  This translates into the need to reposition the cursor and enter again before continuing to type.  I can't believe such a lack of basis occurs in the new product, but I can't work out how to remedy.

    I also noticed that other measures be taken before I even clicked or pressed enter, taking me where I want to be far away.  I own a computer using XP Professional and have never experienced this problem.  Only since I use my friends laptop installed with Windows 7 I just through that.

    I'm not sure I want to upgrade to Windows 7 if it is so cumbersome to work with.

    Everyone has noticed this and how is it fixed?

    Thanks much, Jeanette

    Hello Jessen P

    Have you looked at drivers as you suggest.  As a result, it became obvious that my friend had not installed the mouse trackball with the software provided with the mouse.  It has been installed.  Cursor action now seems stable.  Thank you very much for pointing me in the right direction.

    Kind regards

    Jeanette

  • Creating text file use new file, by returning the result by completely removing the lines of code to extend script?

    Hi guys

    Creating new files .txt in extendscript thru new file returns results by removing all the code in extend script.

    Example of

    -------------------

    var fPerCode = 'hack ';

    var myFileP = new File($.fileName);

    var myFilePtS = myFileP.parent.fsName.toString ();

    myFileP.open ('w');

    myFileP.write (fPerCode);

    myFileP.copy(myFilePtS+"\\"+"Mytools_icons"+"\\"+"name.txt");

    myFileP.close ();

    Alert ("path to the fullper.bat file" + "\n"+myFilePtS+"\\"+"Mytools_icons"+"\\"+"name.txt");

    If you run the above code, you see the result by disabling all of the code above.

    can someone help with this problem?

    You have a problem that you are writing your own script file and then doing a copy...

    You also toString() of unnecesery and deformities (+).

    Here is a fix your code:

    var fPerCode = 'hack ';

    var myFileP = new File($.fileName);

    var myFilePtS = myFileP.parent.fsName;

    var myNewFile = new File (myFilePtS + "\\Mytools_icons\\name.txt");

    myNewFile.open ('w');

    myNewFile.write (fPerCode);

    myNewFile.close ();

    Alert ("path to fullper.bat file\n" + myNewFile.fsName);

  • Need to obtain the result in an orderly manner

    Hello!!

    I had used this querry

    select
    func_find_busfun_desc('MEL', apbuf_fun_id,1) AS form_desc
            FROM APPL_BUS_FUN WHERE APBUF_PAR_FUN_ID ='SUP_DET_TRANS' AND 
    APBUF_FUN_ID IN ('SUP1030','SUP1040','SUP1080','SUP1010','SUP1120','SUP1130','SUP1180','SUP1160')
    Which gives the following result
    Rate Contract Details 
    NCR
    Supplier Document Details 
    Stocks
    Purchase Order
    Purchase Reciept
    Supplier Aging Details
    Supplier Balance
    I need to organize the output as
    Supplier Balance
    Supplier Document Details 
    Supplier Aging Details
    Stocks
    Purchase Order
    Purchase Reciept
    NCR
    Rate Contract details
    Could someone help me pls!

    Wilhelm wundt wrote:
    There is no specific connection I coded directly hard value, but I'm getting output like

    Supplier Balance
    Supplier Aging Details
    Stocks
    Purchase Order
    Purchase Reciept
    NCR
    Rate Contract details
    Supplier Document Details   //It must be second one But it resides last
    

    I had used this query

    select form_desc
    from(
    select func_find_busfun_desc('MEL', apbuf_fun_id,1) AS form_desc
    FROM APPL_BUS_FUN
    WHERE APBUF_PAR_FUN_ID ='SUP_DET_TRANS'
    AND APBUF_FUN_ID IN ('SUP1030','SUP1040','SUP1080','SUP1010','SUP1120','SUP1130','SUP1180','SUP1160')
    )
    order by decode(form_desc,  'Supplier Balance',1,
    'Supplier Document Details',2,
    'Supplier Aging Details',3,
    'Stocks',4,
    'Purchase Order',5,
    'Purchase Reciept',6,
    'NCR',7,
    'Rate Contract details',8,100)
    

    Hope you got the code.
    Decoding is a number of "form_desc" "based on your requirement. If the description given in the decoding is NOT EXACTLY matching your description the order is not correct. It seems that the description 'The Document provider Details' in your output and the decoding is slightly different (Extra space or typo...)

Maybe you are looking for