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.

Tags: Database

Similar Questions

  • How to get the query of the region "PL/SQL function body returns the query string"?

    Hello

    is it possible to get the query string from the region of type "PL/SQL function body returns the query string"?

    I can get the definition of the region as a PL/SQL procedure, but I am interested in the returned query. I tried to write something like

    < pre > v_return_query: = «...» » ;
    : P49_QUERY: = v_return_query;
    Return v_return_query; < / pre >

    to save the return on hidden item P49_QUERY string, but it does not work. I get the error message: ERR-1002 cannot find the item for the "P49_QUERY" element ID in the application '4000 '.

    Kind regards
    Przemek

    If you need to make reference to a page element in the block then you can use this type of control to avoid having to use generic column names:

    if apex_application.get_current_flow_sgid(:APP_ID) = apex_application.get_sgid then-- runtime  :P9_SQL := vSQL;else-- design time  null;end if;
    

    But if all you want to do is capture the SQL debugging you can take all the references element in the block and use the insert statement (in a debug table) as I showed earlier.

    Scott

  • Function returning the query takes longer to run in Apex4.0

    Hi all

    I've created a report using the function returns the query. The function returns the query based on parameters that returns the dynamic columns. When I run the query in sql developer the query generates and returns the result in 3mins. But in the apex, it takes 35 minutes maximum to return.

    The query returns about 10000 lines.

    What a performance problem in the query or Apex? can someone help plz

    Concerning
    REDA

    No it's just the first tranche of 500. You can run it in good old SQL * more and the total time of the time (be patient however)

  • Function that return the name of the current report

    Hello

    Anyone know if there is a function that returns the name of the current report?, similar to GET_APPLICATION_PROPERTY (CURRENT_FORM) in the forms.


    Tnks,


    LEFM

    Hello

    You can use the builtin: SRW. GET_REPORT_NAME
    This function returns the file name of the running report

    http://www.Oracle.com/webapps/online-help/reports/10.1.2/topics/htmlhelp_rwbuild_hs/rwrefex/PLSQL/builtins/SRW/srw_get_report_name.htm

    NOTE: it is not the name of the RDF file. Is the name defined in the reporting name property.

    Concerning

  • Looking for an example of "function that returns the error text.

    Environment: APEX 3.1.1.00.09 on AIX 5.3

    I'm looking for an example implementation of the posting of the "function that returns the error text.

    I would like to write a database function that does the validation logic and return the text of the error.

    Is it possible to create multiple lines of text of error based on error conditions?

    I'm trying to use it at the end of the input data to go on the set of the 'document' to the entry and highlight all error conditions encountered before the 'document' is subject to additional processing.

    I wrote the function and reference it in a posting as ' validate_stuff (: P3_DOC_SEQ); »

    I have an error message "validate_stuff is not a procedure or is not defined.

    The object is a function, not a procedure. It is defined to return a parameter VARCHAR2 hoped posting if it is not NULL.

    When I run the SQL function * more and spend in a number of documents are returned the correct error messages.

    Any direction is greatly appreciated.

    -gary

    Hi Gary,.

    You must RETURN the result of the function:

    BEGIN
     RETURN validate_stuff(:P3_DOC_SEQ);
    END;
    

    Andy

  • Mathmatical function to return the value in injectors

    Hello
    I have obliged. If value for ex Lake 4400000, he should return as 4.4millions even for billions.
    is there an oracle function to return the value in this format. ???

    Hello

    When I want to have a "readable" released in large numbers, I use to do the following:

    Scott@my11g SQL>with t as (
      2  select 3456123456 n from dual
      3  union all select 4567123 from dual
      4  union all select 123465 from dual
      5  )
      6  select n, case when n>1000000000 then trunc(n/1000000000,1)||' Billions'
      7  when n>1000000 then trunc(n/1000000,1)||' Millions'
      8  else to_char(n) end fmtn
      9  from t ;
    
             N FMTN
    ---------- -------------------------------------------------
    3456123456 3.4 Billions
       4567123 4.5 Millions
        123465 123465
    

    ------
    * + [change] + *.
    Moreover, lakh [url http://en.wikipedia.org/wiki/Lakh] has no meaning outside of South Asia.
    Especially for a French man like me, grown with [url http://en.wikipedia.org/wiki/International_System_of_Units] International system of units that is fighting against what I call "funky" measures empirical such miles, yards, feet, inches, just not multiple of 10³
    Same billion mean differ depending on the country (see [url http://en.wikipedia.org/wiki/Long_and_short_scales] long and short scales)

    Just for "fun": [url http://articles.cnn.com/1999-09-30/tech/9909_30_mars.metric.02_1_climate-orbiter-spacecraft-team-metric-system?_s=PM:TECH] this is what can happen when we do not use the same system of units.

  • function to_numer returns the error in pl/sql

    Hello
    I don't have a prob when executing select double to_number('1234.56'), the numer contains decimal numbers
    But this stm return number not valid error in the procedure, except if I use to_number('1234.56','9999999.99')
    Please help me.
    I need to set parameter in DB?
    BTW: my NLS_NUMERIC_CHARACTER has the value '.,'
    Thank you.

    function to_numer returns the error in pl/sql

    hlthanh wrote:
    Hello
    I don't have a prob when executing select double to_number('1234.56'), the numer contains decimal numbers
    But this stm return number not valid error in the procedure, except if I use to_number('1234.56','9999999.99')
    Please help me.
    I need to set parameter in DB?
    BTW: my NLS_NUMERIC_CHARACTER has the value '.,'
    Thank you.

    Handle: hlthanh
    Status level: Beginner
    Join date: March 7, 1999
    Messages total: 94
    Total Questions: 60 (38 pending)
    many questions and so few answers.
    How SAD!

  • Function that returns the results of a select statement

    Hello

    I would like to create a feature on the famous HR Departments oracle table to select * from him. I don't know how to do it.

    Is someone can help me?.

    Thank you

    Oracle stored functions cannot return result sets directly but can return the REF CURSOR. Please read [optimize result set retrieval using ODP.NET and Ref Cursor | http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_refcursors.html] which gives complete examples in PL/SQL for the side Server and VB. NET client side.

  • How to perform a function and return the result in a variable of liaison

    Hello

    I'm trying to calculate the sum of the salaries of all persons with a particular using a function JOB_ID TOTAL_INCOME (v_job_id).

    create or replace function total_income
    + (v_job_id in VARCHAR2) +.
    Number IS BACK
    v_total number (6);

    cursor get_sal is
    Select the pay of employees
    where job_id = v_job_id;
    BEGIN
    v_total: = 0;
    for emp in get_sal
    loop
    v_total: = v_total emp.salary; +.
    end loop;

    dbms_output.put_line (' Total salary ' | v_job_id |' is: ' | v_total);
    Return v_total;
    END;

    Now I woud like to perform this function and assign the value returned in a variable binding test_sal

    test_sal variable number (6)
    SELECT total_income ('AD_VP') in: test_sal FROM DUAL;
    dbms_output.put_line (' Sal Total :'||: test_sal);

    This returns the errors below:

    SELECT total_income ('AD_VP') in: test_sal FROM DUAL
    *+
    Error on line 0
    ORA-01036: illegal variable name/number

    dbms_output.put_line (' Sal Total :'||: test_sal);
    Error on line 3
    ORA-00900: invalid SQL statement

    Could someone help me what could be the problem? Thanks for your time...

    Hi Kiran and welcome to the forum,

    You mix SQL and PL/SQL

    It's the way in which SQL:

    SQL> SELECT total_income('AD_VP') FROM DUAL;
    
    TOTAL_INCOME('AD_VP')
    ---------------------
                      123
    1 row selected.
    

    It comes to PL/SQL in SQL * more

    SQL> variable test_sal number
    SQL> execute :test_sal := total_income('AD_VP')
    PL/SQL procedure successfully completed.
    SQL> exec dbms_output.put_line('Total Sal:'||:test_sal)
    Total Sal:123
    PL/SQL procedure successfully completed
    

    Concerning
    Peter

  • a function that returns the type with a table joint!

    Good day to all,
    I have a function that returns a type.

    so I select it as:
    Select * from table (function (param1, param2))

    now I want to combine this with a table so that the settings for the service we get from the join table. Is this possible? And how?
    I tried different options without success.

    something like:
    Select *.
    table table (function (b.column1, b.columnb) x), tablea b
    where x.a = b.col

    Is this possible?

    Thanks in advance?

    user564819 wrote:

    something like:
    Select *.
    table table (function (b.column1, b.columnb) x), tablea b
    where x.a = b.col

    Is this possible?

    Somehow...

    SQL> create or replace type TIntegers is table of integer;
      2  /
    
    Type created.
    
    SQL>
    SQL> --// our sample pipeline simply spews 2 numbers for eevry number input - simple
    SQL> --// to use for the testcase below
    SQL> create or replace function FooPipe( n number ) return TIntegers pipelined is
      2  begin
      3          pipe row( trunc(n) );
      4          pipe row( trunc(n)*-1 );
      5          return;
      6  end;
      7  /
    
    Function created.
    
    SQL>
    SQL> with dataset( n ) as(
      2          --// ignore this part as it only builts a base table
      3          --// for us to use to select values for input to
      4          --// to the pipeline - in "real world" use this table
      5          --// will already exist
      6          select
      7                  level
      8          from    dual
      9          connect by level <= 10
     10  ),
     11  pipe_line( n, array ) as(
     12          --// we run the pipeline as a nested table column
     13          --// in the SQL projection - the CAST is important
     14          --// in order to establish the nested table type
     15          select
     16                  d.n,
     17                  cast(
     18                          FooPipe(d.n) as TIntegers
     19                  )
     20          from    dataset d
     21  )
     22  --// we now use a standard query to unnest the nested table column
     23  select
     24          p.n,
     25          pipe_val.*
     26  from       pipe_line p, TABLE(p.array)  pipe_val
     27  /
    
             N COLUMN_VALUE
    ---------- ------------
             1            1
             1           -1
             2            2
             2           -2
             3            3
             3           -3
             4            4
             4           -4
             5            5
             5           -5
             6            6
             6           -6
             7            7
             7           -7
             8            8
             8           -8
             9            9
             9           -9
            10           10
            10          -10
    
    20 rows selected.
    
    SQL>
    

    Not sure I like it. What is the real problem that this method (driving a pipeline with input of a base table rows) is supposed to address? There may be a simpler and more elegant approach...

  • Confidence for app.newDoc function always returns the undefined value

    Hello

    I'm doing a script activated by button.  Its purpose is to save a copy of the first page (form data erasure) in its own file in the same path as the open document.  As part of that I had to create a trust to cover the privileges of the app.newDoc function.  I have the following:

    trustedNewDoc = app.trustedFunction (function (nWidth, nHeight)

    {

    app.beginPriv ();

    app.newDoc (nWidth, nHeight);

    app.endPriv ();

    });

    This was recorded in a file called "newdoc.js" in the "app" of javascript.  I closed my Acrobat Pro XI and restarted.  As soon as I try to activate a button with just: "myDoc = trustedNewDoc var (500,500);", it opens the document as specified, but I get "undefined" returned to myDoc - that avoids manipulation of the Fryer.

    If I run the same line of the console, it also returns the value undefined.  Running "myDoc = var app.newDoc ();" also returns undefined, but just "app.newDoc ()"; only returns '[Doc]' - even if ' trustedNewDoc (500,500); "alone is still undefined.

    In any case, I feel like I'm missing something fundamental, even if I found some guides suggesting to do exactly what I have it implemented.  I am pretty sure I have everything entered correctly and followed all the steps, so at this point I'm stumped.  Any help would be greatly appreciated!

    Thank you

    Mike

    Thanks Gilad, that was exactly what he needed!  And thanks for getting back to me so quickly.  Now, I really wish I would have asked this question more early yesterday after spending hours trying to find a solution.

    Unfortunately there aren't really examples I found where a value was returned.  Maybe it's the good sense and I should have better, but I thought that the value has been returned by other means.  In any case, it's great to work with your help!  Now, I have a separate question, with what I need to see if I can get help. Hey, great work and thank you again!

  • function should return the number of rows in a table

    Hello world

    I wrote an entry function is the name of the table and the function should return how many line in the table.
    the table name can change.

    It is possible

    Published by: Balajiraam on March 18, 2011 05:33

    Hello

    Try this

    CREATE OR REPLACE FUNCTION GETCOUNT(TABLE_NAME IN VARCHAR2) RETURN NUMBER
    IS
        TMPCOUNT NUMBER;
        TMPSQL VARCHAR2(1000);
    BEGIN
        TMPSQL := 'SELECT COUNT(*) FROM ' || TABLE_NAME;
        EXECUTE IMMEDIATE TMPSQL INTO TMPCOUNT;
        RETURN TMPCOUNT;
    END;
    

    see you soon

    VT

  • Request report - use the function that returns the cursor

    My requirement is to create a report, which the source will be a function that returns a cursor (the type of cursor is ref cursor).
    How this can be done?

    for example. function my_func (pol_no in number) return cur_type < ref cursor >

    Edited by: viveks on October 27, 2009 10:09

    Better to look at a function that returns a query, or use a hose to treat your cursor returned, because the APEX at the moment can NOT handle the sliders in reports...

    Thank you

    Tony Miller
    Webster, TX

  • Need help with the function MAX Returns the values

    I am creating a report to return slow movement inventory data. One of the requests is that it return only the last date that an item is traded on. A map shows the last date of receipt for a part, the other will show the last time, a part has been issued or shipped on a sales order.

    The hiccup is that it returns every single of the last time that an item has been received, so every last show of the material (on the second sheet) of items on-site.

    Could someone help me set the max value? As shown below, and many variations, the sheet comes up with no corrupt data or dates.

    MAX (Date of the MAX operation) (PARTITION OF matter Transactions.Item matter Transactions.Item ORDER)

    Always returns the next two when in reality, I want just the one with the date the most recent (April 2010).

    100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVALENT A400M AB01D...     Problem of component WIP $0.00 11-Sep-2009-3
    100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVALENT A400M AD01D...     Problem of component WIP $0.00 April 13, 2010-16

    Thank you for your help.

    Becka

    Hi Becka
    If you have a new calculated column showng, as in your example, 13 April 10, and you have another column that contains also this date, you should be able to create a new condition. Condition that must be the date calculated max is equal to the actual date, thus returning only the line that includes 13 April 10.

    I hope I'm makng sense

    Best wishes
    Michael

  • Simple? How do you want 'INSERT' function to return the empty space after a field?

    All,

    I just have a PET of brain? I have a situation where I have a field that must return a single space, with a value that has a space before and after it.

    Example:

    In the text == > I'm < field > go to the office. <-notice no space between the two am, < field > and will

    I mean if set to FALSE, then "I am * not * going to the office."
    If true, then "I go to the office."

    If it is true, I am just RETURN(""); <-this returns a blank space


    If FALSE, I tried:

    RET = 'no '.
    RETURN ("" & ret & "");

    This property returns "I am notgoing to UNRWA. <-don't notice any empty space after the 'no '?

    I tried

    RET = 'no ';
    RET2 = ("" & ret);
    RETURN (Insert (ret2, 3, ""));

    Always the same result. What is strange, that is, if I do a RETURN (Insert (ret2, * 2 *, "")); then he comes back "I'm not tgoing to office" <-note the space between the "o" and the "t"?

    Ideas?

    I forgot about it. Depending on which version you use, DAL actually supported a function that will make the hard space for you, like this:

    Val = FLOAT (160) & 'not' & CHAR (160)
    Return (Val)

Maybe you are looking for