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

Tags: Database

Similar Questions

  • How to perform this procedure and get the result?

    I created a procedure, the source code for the same thing is provided below.

    create or replace procedure vin_test (p_deptno in number
    p_cursor ON SYS_REFCURSOR)
    as
    v_res Emp % rowtype;
    Start
    Open the p_cursor FOR
    Select *.
    WCP
    where deptno = p_deptno;

    end vin_test;

    Now, if I want to see that the out put of this Proc
    I first put the Serveroutput on and then...
    Exec vin_test (10);
    I get an error message indicating an incorrect number of arguments, then someone can tell me what is the value of the parameter I should move on so that I can get the desired output.


    Thanks in advance
    OraCrazy

    In sqlplus you can do like this.

    SQL> create or replace procedure vin_test( p_deptno IN number, p_cursor OUT SYS_REFCURSOR)
      2  as
      3     v_res Emp%rowtype;
      4  begin
      5     open p_cursor for
      6     select *
      7       from emp
      8      where deptno = p_deptno;
      9  end;
     10  /
    
    Procedure created.
    
    SQL> var lcur refcursor
    SQL> exec vin_test(30,:lcur)
    
    PL/SQL procedure successfully completed.
    
    SQL> print lcur
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO        DIV
    ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30         10
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30         10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30         10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30         10
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30         10
    
    6 rows selected.
    

    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.

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

  • Decoding the date to sysdate and return the result as possible

    Hello

    I would like to create an expression that compares a date with the sysdate field and then he categorizes with decoding, this is what I tried so far but it through a mistake of the closing parenthesis.
    SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 31 16:51:21 2009
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    SQL> SELECT DECODE((date_expired < sysdate), date_expired, 'CURRENT')
      2    FROM tablename
      3  /
    SELECT DECODE((date_expired < sysdate), date_expired, 'CURRENT')
                                *
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    
    SQL>
    The error corresponds to the 28 column that lies between date_expired and <.

    Thank you
    Ben

    Hi Ben,

    Decode is a function SQL and SQL ignores Boolean values. If the Analyzer does not provide the< sign="" and="" expects="" a="" right="" parenthesis="" at="" that="">

    You can use something like:

    case
      when date_expired < sysdate then ...
      when date_expired = sysdate then ...
      else ...
    end
    

    Kind regards
    Rob.

  • Plink and return the results

    I tried to find out if it was possible with plink to return data to powershell?  If so anyone got examples of that?

    You can find an example in 12 Re: get the details of the HBA hardware  

  • Procedure to take income data set and return the result set

    Hi all

    I have a situation where there will be a 'standard' set of data (source_data below), and I need to get information on outcomes for certain groups of customers (client_data for example). As SQL right it would be very easy (see below) - real world problem is a bit more complicated. However, what I would do is set up a procedure so that I can pass on my data of client variables and it will spit back on a set of data that is identical to the output of the given SQL.

    A pointer in the right direction would be appreciated. If I could 'pass customer data' as a string that contains an SQL query, which would be even better, for example

    GetResults ("select client_id, min (whatever_date) from some_client_data which...", MyOutputRefCursor?)
    create table source_data
    (client_id integer,
    tdate date,
    amount number(6,2));
    
    create table client_data
    (client_id integer,
    critical_date date);
    
    insert into source_data values(1,to_date('20090104','yyyymmdd'),1000);
    insert into source_data values(1,to_date('20100104','yyyymmdd'),2000);
    insert into source_data values(1,to_date('20110104','yyyymmdd'),3000);
    insert into source_data values(1,to_date('20120104','yyyymmdd'),4000);
    insert into source_data values(2,to_date('20090104','yyyymmdd'),5000);
    insert into source_data values(2,to_date('20090604','yyyymmdd'),1000);
    insert into source_data values(2,to_date('20100104','yyyymmdd'),2000);
    insert into source_data values(3,to_date('20091004','yyyymmdd'),3000);
    insert into source_data values(3,to_date('20091104','yyyymmdd'),4000);
    insert into source_data values(4,to_date('20090104','yyyymmdd'),5000);
    insert into source_data values(4,to_date('20090604','yyyymmdd'),2000);
    
    insert into client_data values(1,to_date('20110104','yyyymmdd'));
    insert into client_data values(2,to_date('20090604','yyyymmdd'));
    
    
    select c.client_id,
      sum(CASE WHEN tdate < critical_date then amount else null end) used_before,
      sum(CASE WHEN tdate >= critical_date then amount else null end) used_after
    from source_data s
    inner join client_data c on s.client_id = c.client_id
    GROUP BY c.client_id;
    Thank you

    Jon

    Hello

    You can do this with a view. Make settings of the view a global temporary table:

    create GLOBAL TEMPORARY table client_data
    (       client_id       integer
    ,     critical_date      date
    )
    ON COMMIT PRESERVE ROWS
    ;
    

    Then, you can create a view based on your real of the table and the parameter array:

    CREATE OR REPLACE VIEW     special_clients
    AS
    select c.client_id,
      sum(CASE WHEN tdate < critical_date then amount else null end) used_before,
      sum(CASE WHEN tdate >= critical_date then amount else null end) used_after
    from source_data s
    inner join client_data c on s.client_id = c.client_id
    GROUP BY c.client_id;
    

    Because the table of parameters is a global temporary table, each session will have its own private copy of the table of parameters and therefore his own private version of the view.

  • How to add two fields and show the result in a third

    All,
    I have 2 InputText field; both are related to the fields of the associated database.

    I want to display the sum of these two fields on a text output.

    I declare the value of the output in this way text link:
    #{sessionScope.PersonalNrBean.summeDB.value + sessionScope.PersonalNrBean.kmGeldMlp.value}

    But I get this error:
    Cannot find resource for bundle java.util.PropertyResourceBundle, key el.convert

    ADF_FACES - 60097:Weitere desKomitees find DEM Fehlerlog einen entry as servers, der mit: ADF_FACES - 60096:Server - Exception while PPR, beginnt #3

    If I declare the value binding to contain the field even two times:
    #{sessionScope.PersonalNrBean.summeDB.value + sessionScope.PersonalNrBean.summeDB.value}
    It works as expected, but it's not really what I need...

    Any ideas?

    Thanks in advance,
    Sergio.

    Edited by: user5414451 the 14.07.2011 02:57

    Try following:

    #{bindings.summeDB.inputValue.value + bindings.kmGeldMlp.inputValue.value}
    

    Jean Lou

  • Tax calculation based on the user in the box input and displaying the result.

    Thanks to WhyIsThisMe for starting me on my first draft script & Jono! I'm almost there with my purchase requisition form (90% manufactured from the tutorial).  Everything works except for the taxable column

    form.JPG

    I can't understand the correct syntax to check the value of the checkbox in the column taxable and then do the math for the tax based on user input in the field % tax

    (total * stateTaxPercent / 100)

    Essentially, I want to make the calculation only the taxable = 1, and then display the cumulative tax in the tax field.

    Should I use mouseup as trigger to perform the calculation of the tax and save the result as a variable and displays the variable in the tax field? Then if another taxable box gets checked, I could add the new calculation of the variable. Not sure whether in an elegant way to get there.

    ?

    I would put the following text in the change event of each taxable check box (in formcalc):

    If ($ == 1) then

    tax = tax + (amount * 0,0825)

    ElseIf ($ == 0) then

    tax = tax - (quantity * 0,0825)

    endif

    (where 'tax' is what you called your total tax box and the 'amount' is what you called your box of price).

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

  • My iPhone6 has convinced himself that he has a helmet connected - how can I convince otherwise and return to the normal setting?

    My iPhone6 has convinced himself that he has a helmet connected - how can I convince otherwise and return to the normal setting?  I tried turning it off and back on after awhile, but did not.

    Double check with a magnifying glass and a good lighting that nothing has been slain. Then, try insertion and withdrawal of your headphones a couple of times. If this does not work, it may be while the shooting went wrong. In this case, make an appointment at the Genius Bar at your local Apple store for the assessment.

  • How to write a function to estimate the number of rows returned SQL?

    How to write a function to estimate the number of rows returned SQL through SQL Execution Plan?
    My idea is
    Call dbms_sql.parse to create the SQL PLAN, then ask the PLAN for the number of estimated return lines.
    But how to get SQL plan through "id cursor?
    Thank you.

    You can use EXECUTE IMMEDIATE to explain plan statement. About the STATEMENT_ID generation, it could be anything. Even a SYSTIMESTAMP cast as TANK would work.

  • 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

  • How can I take an anchored frame and return the paragraph tag used?

    I need to analyze through anchored frames and return the tag of paragraph that it is spotted. I can't find a property which returns the paragraph tag. Anyone have any ideas?

    Try this on the anchored frame selected:

    #target framemaker
    
    var doc = app.ActiveDoc;
    var aFrame = doc.FirstSelectedGraphicInDoc;
    var pgf = aFrame.TextLoc.obj;
    
    alert (pgf.Name);
    

    Rick

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

Maybe you are looking for

  • Why can't I retrieve my favorites after installation of new Firefox blank even though I have the key to the synchronization?

    Before I Change my old BONES, I created an account on Firefox Sync to save my favorites, after the installation of the new operating system windows 8.1 specifically and configure Firefox new Virgin "29.0.1", and then try to recover my data using my s

  • Tecra 9100 for TV connection problems

    Hello I hope that im asking this question in line. I tried to connect my laptop to my tv without success I pass the cable in the left side of the laptop and plug the other end to the video output on the tv I have both put power off and power on, but

  • Using local variables to 'clean up' diagram

    I have attached a photo with red circles indicating my use of local variables to 'clean up' a block diagram. If I meet problems this? I leave this task and the unwired error? -Sarah

  • Function of zero crossing

    Hello I found this passage function to zero in one of the old forums and I'm trying to understand how it works. In my case, I have two sine waves, instead of a square pulse but I can really understand how this feature works. I know that the first, th

  • Editing external source to the traces

    Hi all I'm new to Ultiboard and trying to do something that should be relatively simple.  I want to connect an external power supply DC, ending in pods, to my card.  I can't figure out how to put in a hole that connects to the trace.  It's a Terminal