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.

Tags: Database

Similar Questions

  • 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...

  • 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

  • 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

  • How to loop through the results of a select statement in a process flow?

    Hello

    I use Warehouse Builder 10 g R2.

    I'm trying to implement a loop in a process stream that runs through the results of a select statement.

    In pl/sql, it would be implemented as a for loop by using a slider, but I simply doesn't work how to do this using the loops in the process flow.

    Someone at - it ideas?

    Thank you
    Liffey

    Liffey,
    Look at this thread
    For or while loop a loop in the process flow

    Kind regards
    Oleg

  • 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.

  • 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

  • function that limits the result?

    Hello, I am trying to write a calculation that CAP the deduction lead after reaching a certain number, in this case $50. For example:

    -Rate of pay is $25 / hour and annualization is 2080

    .0125 * ((Pay_Rate * Annual_Hours) / 26) = $25 deduction

    -Rate of pay is $50 / hour and annualization is 2080

    .0125 * ((Pay_Rate * Annual_Hours) / 26) = $50 deduction

    -Rate of pay is $75 / hour and annualization is 2080

    .0125 * ((Pay_Rate * Annual_Hours) / 26) = deduction of50 $

    Is there a 'Limit' function that will work in this formula?

    Thanks for your help,

    Chris

    Hello Chris,

    If I understand correctly you want the function LESS.

    LESS (n1, n2 [,...] *) = smaller of numbers n1, n2,...
    Thus, for example:

    SELECT LESS (Pay_Rate * Annual_Hours / 2080)

    50

    )

    ...

    give your calculation if less than 50 and 50 otherwise
    (I rewrote your calculation is equivalent but deleting the unnecessary parentheses and grouping "* 0.0125" and "/ 26" ")

    (Note: the "opposed" LESS is MORE)

    HTH,

    Bruno Vroman.

  • 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

  • Function that returns the text of the error - type of Validation

    Small question regarding creating a function that successfully compiles a validation without a text of the error control: what value the function returns to validation successful?

    I tried a null value, but it doesn't seem to work.

    Thank you.

    Hello

    How does it work?

    What return NULL validation function is passed. If it returns a character string, then the validation failed and string is displayed as the error message for validation

    BR, Jari

  • Selection of a function that returns a sys refcursor or alternative

    I have a query that returns a result set of three columns, namely the SSN, the PAID_YEAR and the PAID_TOTAL. This query, I can:

    1. Create a view and then question him.
    2. Create a function result set and return

    If I go the first way, that a simple request like this takes more than 20 seconds:

    SELECT PAID_YEAR,PAID_TOTAL FROM VIEW_1 WHERE SSN=12345678912882;

    I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.

    If I go the second way I can send only a parameter and make the engine look for only the rows that match the condition and the Recordset. But I don't know how then SELECT this result set returned. I took a look at the tables in pipeline, but do not understand how to their advantage. So my final question is if it is somehow possible to select from the result set returned by a function like this:

    SELECT * FROM FUNCTION_1(12132323232).

    If Yes, then how, if not, what would be another way?

    I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.

    No - you don't "know that" because it is not true. Just check out the plan of the command explain to yourself. Oracle can always use appropriate indexes so that only the needed rows are returned.

    So my final question is if it is somehow possible to select from the result set returned by a function like this:

    SELECT * FROM FUNCTION_1(12132323232).
    

    No - you can't do it like that. You must use the TABLE function to process the result of the function defined in a table:

    'SELECT * FROM TABLE(FUNCTION_1(12132323232)).

    -type to match record emp
    create or replace type emp_scalar_type as an object
    (EMPNO NUMBER 4,
    ENAME VARCHAR2 (10),
    USE VARCHAR2 (9).
    MGR NUMBER 4,
    HIREDATE DATE,
    NUMBER OF SAL (7, 2)
    NUMBER OF COMM (7, 2)
    DEPTNO NUMBER (2)
    )
    /

    -records of the emp table
    create or replace type emp_table_type to table of emp_scalar_type
    /

    -function of pipelined

    create or replace function get_emp (p_deptno number)
    return emp_table_type
    PIPELINED
    as
    TYPE EmpCurTyp IS REF CURSOR RETURN emp % ROWTYPE;
    emp_cv EmpCurTyp;
    l_rec emp % rowtype;
    Start
    Open emp_cv SELECT * from emp where deptno = p_deptno;
    loop
    extract the emp_cv in l_rec;
    When the output (emp_cv % notfound);
    line of conduct (emp_scalar_type (l_rec.empno, LOWER (l_rec.ename),
    l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno));
    end loop;
    return;
    end;
    /
     
    Select * from table (get_emp (20))

  • Message box in function that returns a list deletes the created list... (Dialog box)

    Hello

    I work with a complex dialogue, its purpose is to manage a section in the PDF file.

    I use a "mclv" object in the dialog box to represent data entries in the PDF file in order to manage the result in another section.

    I created a function that creates the list based on a previous section in the PDF object, the function works perfectly well.

    But I have a small question, the function used to create the list of the dialog box object performs a check with the former front list created, as appropriate,

    and if in any case it is different from the old list, I need to warn the user that the list has changed and if there were any changes applied to the result it will be returned to zero and must be recreated.

    But when the poping that message box, all lists are deleted and nothing is displayed in the objects 'mclv.

    If I remove the message box, the lists are all very well...

    Is there anyone who have come across something like this before? If so, any solution to this problem?

    I asked my question a bit too quickly, I already found a work around

    But I still don't understand why he behaves like that tho...

    I just thought how to work around this problem.

    If anyone has encountered this problem can use this solution:

    Instead of having the message inside the function to return box, I declared a global Boolean variable to the Script object

    If the message box must be displayed, the Boolean value is set to True

    Once in the initialize event of the dialog box, if the value Boolean true I call the message box and reset the value Boolean false

  • Create the view and by using the function that returns a type oracle

    Following is possible?

    A function returns an ORACLE object Type, and I want to use this feature, in my opinion, it is possible to access each field of the type once the function is executed and make a column in the view?
    create or replace TYPE SOME_INFO AS OBJECT
    ( 
      CHARGE FLOAT,
      SOME_DATE DATE,
      SOME_VAL VARCHAR(50)
    );
    
    CREATE OR REPLACE
      FUNCTION CALCULATE_INFO
        (
          p_chargeId NUMBER)
        RETURN SOME_INFO 
      AS 
      v_some_info SOME_INFO := new SOME_INFO(0, null, null);
    BEGIN
     
    -- function body populates the v_some_info
    return v_some_info;
     
    END calculate_info;
    Now, I want to use the function according to me - if the underlying query of the view follows-
     select c.*, calculate_info(c.charge_id) as someInfo from some_charge;
    How to recover someInfo.CHARGE, someInfo.some_date, someInfo.some_val? I can put them as columns in the view?

    If you use only functions that return a single value in a view?

    Thank you
    Mustapha

    Published by: Tina Giri on April 16, 2009 05:47

    How to recover someInfo.CHARGE, someInfo.some_date, someInfo.some_val?

    SQL>  create or replace type some_info
    as
       object (charge float, some_date date, some_val varchar (50));
    /
    Type created.
    
    SQL>  create or replace function calculate_info (p_chargeid number)
       return some_info
    as
       v_some_info   some_info := new some_info (0, null, null);
    begin
       -- function body populates the v_some_info
       return v_some_info;
    end calculate_info;
    /
    Function created.
    
    SQL>  select your_view.someinfo.charge,
           your_view.someinfo.some_date,
           your_view.someinfo.some_val
      from (select c.*, calculate_info (c.empno) as someinfo
              from emp c) your_view where rownum <= 3
    
    SOMEINFO.CHARGE SOMEINFO SOMEINFO.SOME_VAL
    --------------- -------- --------------------------------------------------
                  0
                  0
                  0                                                            
    
    3 rows selected.
    
  • How to expose a function that returns a XML as a Web Service?

    ---------------------------------------------------------------------------------
    Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE 11.2.0.3.0 Production."
    AMT for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    ---------------------------------------------------------------------------------

    After reviewing the documentation of oracle on the generation of xml data in the database, I managed to select normal tables and return a result xml exactly as I want:
    -- My types
    create or replace 
    TYPE CHILD_T AS OBJECT ("@ID" VARCHAR2(20), "@NAME" VARCHAR2(20));
    
    create or replace 
    TYPE CHILDREN_T AS TABLE OF CHILD_T;
    
    create or replace 
    TYPE PARENT_T AS OBJECT ("@ID" VARCHAR2(20), CHILDREN CHILDREN_T );
    
    -- The actual select
    SELECT XMLFOREST (
                PARENT_T(d.id,
                CAST ( MULTISET (SELECT c.id, c.name
                                 FROM child c
                                 WHERE c.parent_id = p.id) AS CHILDREN_T )
                ) AS "Parent"
            ) 
    FROM parent p;
    That gets me this:
    <Parent ID="1">
        <CHILDREN>
            <CHILD_T ID="1" NAME="xxxxx" />
            <CHILD_T ID="2" NAME="yyyyy" />
            <CHILD_T ID="3" NAME="zzzzz" />
        </CHILDREN>
    </Parent>
    It's perfect, but how to expose this result as a Web Service like this link?
     http://localhost:8080/orawsv/MY_USER/GET_CHILDREN?wsdl
    I tried this function:
    FUNCTION GET_CHILDREN (
        PARENT_ID IN VARCHAR2
    ) RETURN CLOB
    AS
        L_RESULT CLOB;
    BEGIN
        SELECT to_clob(XMLFOREST (
                PARENT_T (p.id,
                CAST ( MULTISET (SELECT c.id, c.name
                                 FROM child c
                                 WHERE c.parentId = p.id) AS CHILDREN_T )
                ) AS "ParentObj"
          )) AS MY_XML INTO L_RESULT
        FROM parent p
        WHERE p.i = PARENT_ID;
    
        RETURN (L_RESULT);
    END GET_CHILDREN;
    But when I access although .NET Compact Framework, I get this: "'Element' is an invalid XmlNodeType.

    As you can see, I just need a simple way to transport information between a Windows CE handheld computer and our database. Use functions that return simple values.
    Do I have to return the data as xml?
    What return value I should use? Varchar2 throws a buffer error output.

    ---------
    It is my first post here, also my first contact with OracleDB, and Web Services.

    Hello

    Welcome to Oracle and XML DB!

    After reviewing the documentation of oracle on the generation of xml data in the database, I managed to select normal tables and return a result xml exactly as I want:

    Have you also read about the SQL/XML functions?
    You don't have to create objects of type SQL to generate XML data.

    Using only XMLElement, XMLAgg, XMLAttributes, etc., you should be able to generate any kind of structure complex relational data and with total control over the names (which you don't have with the types of objects).
    Your example can be rewritten to:

    SELECT XMLElement("Parent",
             XMLAttributes(p.id as "Id")
           , XMLElement("Children",
               (
                 SELECT XMLAgg(
                          XMLElement("Child",
                            XMLAttributes(
                              c.id as "Id"
                            , c.name as "Name"
                            )
                          )
                        )
                 FROM child c
                 WHERE c.parent_id = p.id
               )
             )
           )
    FROM parent p
    WHERE p.id = :parent_id ;
    

    It's perfect, but how to expose this result as a Web Service like this link?
    [...]
    Do I have to return the data as xml?

    Yes.
    Define the return as XMLType data type:

    FUNCTION GET_CHILDREN (
        PARENT_ID IN VARCHAR2
    )
    RETURN XMLTYPE
    AS
        L_RESULT XMLTYPE;
    BEGIN
    
      SELECT XMLElement("Parent",
               XMLAttributes(p.id as "Id")
             , XMLElement("Children",
                 (
                   SELECT XMLAgg(
                            XMLElement("Child",
                              XMLAttributes(
                                c.id as "Id"
                              , c.name as "Name"
                              )
                            )
                          )
                   FROM child c
                   WHERE c.parent_id = p.id
                 )
               )
             )
      INTO L_RESULT
      FROM parent p
      WHERE p.id = PARENT_ID ;
    
      RETURN (L_RESULT);
    
    END GET_CHILDREN;
    
  • Go to a function that returns a Boolean

    Short version of the question: Boolean values can be returned by a pl/sql function?

    I've implemented a short function which returns a Boolean value; When I compile it I get an error:

    Error report:

    ORA-06550: line 5, column 32:

    PLS-00382: expression is of the wrong type

    ORA-06550: line 6, column 4:

    PLS-00306: wrong number or types of arguments in the call to "PUT_LINE '.

    ORA-06550: line 6, column 4:

    PL/SQL: Statement ignored

    06550 00000 - "line %s, column % s:\n%s".

    * Cause: Usually a PL/SQL compilation error.

    * Action:

    The closest, I appealed


    RETURN sys.diutil.bool_to_int (< foo >);


    and then a caller script can call


    sys.diutil .int_to_bool (< bar >);

    at least this way there is no verification of the Boolean value of 'manual '.  Is it really the only way to return / call a Boolean?


    Thank you

    Chris


    EDIT


    I was aware of the fact I had not provided examples of code - and was just one question fairly open. I hope that this example will show what does not work!


    I have a function that returns a Boolean value:


    create or replace

    FUNCTION myFunc (s_in IN VARCHAR2) RETURN a Boolean value

    IS

    s_out BOOLEAN: = TRUE;

    BEGIN

    RETURN s_out;

    END FUNCTION3;

    I try and call the function in the following script:

    DECLARE

    s_in varchar2 (20): = "Hello";

    s_out boolean;

    BEGIN

    SELECT myfunction (s_in) INTO s_out FROM DUAL;

    END;

    That's when I get the error. But sorry, I was looking for too many error messages! I have worked that the one I posted above is because put_line can accept only strings and numbers not Boolean, the mistake that this function returns is:

    ORA-06550: line 5, column 32:

    PLS-00382: expression is of the wrong type

    ORA-06550: line 5, column 11:

    PLS-00382: expression is of the wrong type

    06550 00000 - "line %s, column % s:\n%s".

    * Cause: Usually a PL/SQL compilation error.

    * Action:

    However, I suppose that the comment of Frank Kulash is perhaps the reason why I see this?


    Post edited by: 2922851

    Hi, Chris,.

    2922851 wrote:

    Short version of the question: Boolean values can be returned by a pl/sql function?

    Sure.  If you are having problems, post your code (both the function and some PL/SQL that calls it).

    The BOOLEAN data type exists only in PL/SQL, not in SQL, so if the function returns a BOOLEAN value, then you can't call it in a SQL statement, even if this SQL statement is used within PL/SQL.  For this reason, a lot of guys write functions that return a NUMBER (1 or 0) or a string (' t ' or 'F') rather than return a BOOLEAN value.

    I've implemented a short function which returns a Boolean value; When I compile it I get an error:

    Error report:

    ORA-06550: line 5, column 32:

    PLS-00382: expression is of the wrong type

    ORA-06550: line 6, column 4:

    PLS-00306: wrong number or types of arguments in the call to "PUT_LINE '.

    ORA-06550: line 6, column 4:

    PL/SQL: Statement ignored

    06550 00000 - "line %s, column % s:\n%s".

    * Cause: Usually a PL/SQL compilation error.

    * Action:

    This error indicates a problem calling put_line; It has nothing to do with what returns the function.

Maybe you are looking for

  • You can use old iMac as a monitor for mini Mac

    You can use 2008 iMac as a monitor for mini Mac?

  • Can not download the full version of DVD Movie Factory for Satellite A100 and clean Vista

    Hello I did a clean Windows Vista update set of Modus link orgianal.Installed and now when a desire to install the DVD Movie Factory patch (DMF5.51_Patch_18in1_for TOSHIBA_147.05_0718)There is no software installed dvd creator and also no cd creator.

  • optical drive

    Superior optical drive does not open. Two records would be recognized before going to El Capitan, now only the lower part is recognized.

  • Bug status definitions

    In the Bug search tool, we can find from many bug status sub-option for every status (open, fixed, Terminated). But the real significance of these suboptions? Fixed (fixed) Fixed (checked) Open (attributed) Open (transmitted) Open (Held) Open (requir

  • Corruption in large file copy to USB - Windows 7 Pro 64-bit SP1

    I have seen other people have reported this problem, but I have not found an answer. When I copy large files (1 GB +) from one hard disk to another (connected to the same computer), and the destination hard disk is on a port USB3 (also maybe USB2), s