Can call a function in the select statement?

Is there any ways to call a function in the select statement?
what I like to do is this:
select deptno, totalEmployees(deptno), TotalSalary(deptno)
from emp;
I know it can be done by count(*) and join tables, but my case
is much more complex and the where clauses are different from
one function to another, and have many tables to join and many
combinations
Thanks

Functions can be used in a select statement subject to certain
restrictions, see
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/
server.817/a85397/statem9b.htm#2062024
It's under "CREATE FUNCTION> Keywords and Parameters> function>
Restrictions on User-Defined Functions"
Here is an except...
When a function is called from within a query or DML statement,
the function cannot:
a) Have OUT or IN OUT parameters
b) Commit or roll back the current transaction, create or roll
back to a savepoint, or alter the session or the system. DDL
statements implicitly commit the current transaction, so a user-
defined function cannot execute any DDL statements.
c) Write to the database, if the function is being called from a
SELECT statement. However, a function called from a subquery in
a DML statement can write to the database.
d) Write to the same table that is being modified by the
statement from which the function is called, if the function is
called from a DML statement.
Except for the restriction on OUT and IN OUT parameters, Oracle
enforces these restrictions not only for the function called
directly from the SQL statement, but also for any functions that
function calls, and on any functions called from the SQL
statements executed by that function or any function it calls.

Similar Messages

  • Calling a function in the select part of a query

    I am integrating Apex with E-Bus Suite 11.5.10.2.
    I have a function in a sql query. The function calls an apps view. When i run the sql query in TOAD, I get the correct data. When I run it in Apex, i get an error - it says "Invalid number"
    My apex report is registered in my 11i menu. Who is the user that is running this report? Is it apps?
    thanks

    When you run it in TOAD, you are passing through a value, correct? Maybe when your EBS call to your APEX report is done, it is passing through a character value as apposed to a number. You might want to convert your passed in value in your function to a number to be sure..
    Also, it is not always the best idea to call a function in a select statement.. Is there a reason you can't do in sql what your function is doing?
    Thank you,
    Tony Miller
    Webster, TX

  • Calling a function in the select clause.

    I am using Oracle 11g.
    I am trying to write a query like this
    select name,age, sal, avg = avg_salary(age)
    from customer
    where sal >= avg;
    However, I am not able to do so. What the query is trying to do is print the name, age and salary of every customer as well as the average salary for the customer's age where the customer's salary is greater than the average salary for his age.
    Please help. Thanks.

    Hi,
    The way to assign a column alias is to put the alais after the expression. It makes your code clearer if you put the keyword AS after the expression and before the alias, but this is not required.
    SELECT     name
    ,     age
    ,     sal
    ,     avg_salary (age)     AS avg_salary_age
    FROM     customer
    WHERE     sal     >= avg_salary (age)
    ;You can't reference a column alais in the same query where it is defined (except in an ORDER BY clause). If you want to reference the alias anywhere else (e.g., in the WHERE clause) you have to define it in a sub-query; then you can use it anywhere you want in the super-query, liek this:
    WITH     got_avg_salary_age     AS
         SELECT     name
         ,     age
         ,     sal
         ,     avg_salary (age)     AS avg_salary_age
         FROM     customer
    SELECT     *
    FROM     got_avg_salary_age
    WHERE     sal     >= avg_salary_age
    ;Since AVG is the name of a built-in function, there could be problems using it as a column alias. You could call it average, if you don't like avg_salary_age.

  • Function in the select

    Hi
    can someone please show me how to call a function from a select* statement.
    Thanks
    Helena

    select age
    from show_details
    where age=func_test();
    Here the function returns some value that function definition is like
    CREATE OR REPLACE FUNCTION func_test RETURN NUMBER
    AS
    lv_a NUMBER;
    BEGIN
    lv_a := 0;
    lv_a := lv_a + 1;
    RETURN lv_a;
    dbms_output.put_line(lv_a);
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Error is '||SQLERRM);
    END;
    This is to manually call a function
    DECLARE
    v_a NUMBER;
    BEGIN
    v_a := func_test();
    dbms_output.PUT_LINE(v_a);
    END;
    ************The o/p is '1'.
    If the show_details table contains the age value as 1 then the field will be selected by calling the function.

  • Will a explain plan consider a function in a select statement.

    Hi gurus,
    I have a question regarding explain plan.
    I ran a query, which returns me explain plan with multiple CPU costs around 300K.
    now i use a function, and the number of lines displayed in explain plan reduces from 12 to 8 lines.
    What i dont understand is.. Is the explain plan considering the function in the select statement ?
    ex.
    explain plan for
    select column1,
             column2,
             function(value1)
    from case
    where case_no = 1will a explain plan consider the functions in a select statement ?
    Thank you.

    What i dont understand is.. Is the explain plan considering the function in the select statement ?Maybe there are tweaks which reveal more information from the explain plan, but a straightforward way won't necessarily expose any function call:
    SQL> create or replace function get_dname (i_deptno integer)
       return varchar2
    as
       l_dname   dept.dname%type;
    begin
       select   dname
         into   l_dname
         from   dept
        where   deptno = i_deptno;
       return l_dname;
    end get_dname;
    Function created.
    SQL> explain plan
       for
          select   ename, deptno, get_dname (deptno) dname
            from   emp
           where   deptno = 10
    Explain complete.
    SQL> select   * from table (dbms_xplan.display ())
    PLAN_TABLE_OUTPUT                                                                                                                                    
    Plan hash value: 3956160932                                                                                                                          
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |                                                                           
    |   0 | SELECT STATEMENT  |      |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    |*  1 |  TABLE ACCESS FULL| EMP  |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    Predicate Information (identified by operation id):                                                                                                  
       1 - filter("DEPTNO"=10)                                                                                                                           
    13 rows selected.
    SQL> truncate table plan_table
    Table truncated.
    SQL> explain plan
       for
          select   ename, deptno
            from   emp
           where   deptno = 10
    Explain complete.
    SQL> select   * from table (dbms_xplan.display ())
    PLAN_TABLE_OUTPUT                                                                                                                                    
    Plan hash value: 3956160932                                                                                                                          
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |                                                                           
    |   0 | SELECT STATEMENT  |      |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    |*  1 |  TABLE ACCESS FULL| EMP  |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    Predicate Information (identified by operation id):                                                                                                  
       1 - filter("DEPTNO"=10)                                                                                                                           
    13 rows selected.

  • Decode in the select Statement

    Hi All,
    I am using the decode function in the select statement....but as i am using the group by in the select statement....i am not able to run the same query
    How to tackle this problem of handling the decode ....while we have group by also.
    This is bit urgent
    Thanks for your help
    Ramya

    Hi,
    Thanks for the quick reply.
    Here is the code...i have included the decode for the customer carrier code...
    SELECT c.trx_number invoice_number,
    c.trx_date invoice_date,
    ctl.sales_order_date order_date,
    c.ship_date_actual ship_date,
    c.purchase_order,
    ctl.sales_order order_number,
    olv.ordered_item item,
    msi.description item_description,
    olv.ordered_quantity quantity,
    olv.unit_selling_price unit_price,
    olv.unit_selling_price * olv.ordered_quantity amount,
    olv.tax_value,
    rc.customer_number,
    csta.customer_carrier_code,
    (SELECT decode(customer_carrier_code, NULL, 'Shipping & Handling', 'Shipping') sh
    FROM xx_cust_ship_to_addresses_v cstaa,
    ra_addresses ara
    WHERE cstaa.location_id = ad.location_id
    AND ara.location_id = ad.location_id) SH,
    rc.customer_name invoice_to_name,
    rct.name invoice_type,
    olv.sold_to,
    olv.ship_to_location,
    olv.ship_to_address1,
    olv.ship_to_address2,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -2, LENGTH(olv.ship_to_address5)) ship_to_country,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -9, 6) ship_to_postalcode,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -12, 2) ship_to_state,
    SUBSTR(olv.ship_to_address5, 1, LENGTH(olv.ship_to_address5) -15) ship_to_city,
    olv.invoice_to_address1,
    olv.invoice_to_address2,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -2, LENGTH(olv.invoice_to_address5)) invoice_to_country,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -9, 6) invoice_to_postalcode,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -12, 2) invoice_to_state,
    SUBSTR(olv.invoice_to_address5, 1, LENGTH(olv.invoice_to_address5) -15) invoice_to_city,
    olv.flow_status_code,
    olv.terms net_terms,
    olv.freight_terms_code freight_terms,
    olv.fob_point_code fob
    FROM ra_customer_trx_all c,
    ra_customer_trx_lines_all ctl,
    ra_cust_trx_types rct,
    jtf_rs_salesreps rs,
    ra_customers rc,
    ra_addresses ad,
    ra_site_uses su,
    mtl_system_items msi,
    oe_order_headers_v ohv,
    oe_order_lines_v olv,
    rcv_lot_transactions tl,
    rcv_shipment_lines sl,
    rcv_shipment_headers rsh,
    rcv_transactions rt,
    wsh_delivery_details wdd,
    xx_cust_ship_to_addresses_v csta
    WHERE to_char(ohv.order_number) = ctl.sales_order
    AND ctl.customer_trx_id = c.customer_trx_id
    AND c.cust_trx_type_id = rct.cust_trx_type_id
    AND c.org_id = rs.org_id
    AND c.primary_salesrep_id = rs.salesrep_id
    AND c.ship_to_site_use_id = su.site_use_id
    AND su.address_id = ad.address_id
    AND ad.customer_id = rc.customer_id
    AND ctl.inventory_item_id = msi.inventory_item_id
    AND ohv.header_id = olv.header_id
    AND olv.line_id = wdd.source_line_id(+)
    AND to_char(olv.line_id) = ctl.interface_line_attribute6
    AND tl.shipment_line_id = sl.shipment_line_id
    AND sl.shipment_header_id = rsh.shipment_header_id
    AND tl.transaction_id = rt.transaction_id
    AND csta.location_id = ad.location_id;
    GROUP BY c.trx_number,
    csta.customer_carrier_code,
    c.trx_date,
    c.creation_date,
    c.ship_date_actual,
    c.sold_to_customer_id,
    c.bill_to_customer_id,
    c.bill_to_site_use_id,
    c.ship_to_customer_id,
    c.ship_to_site_use_id,
    c.purchase_order,
    (SELECT decode(customer_carrier_code, NULL, 'Shipping & Handling', 'Shipping') sh
    FROM xx_cust_ship_to_addresses_v cstaa,
    ra_addresses ara
    WHERE cstaa.location_id = ara.location_id
    AND ara.location_id = ad.location_id),
    ctl.sales_order,
    ctl.sales_order_date,
    ctl.tax_rate,
    ctl.customer_trx_id,
    ctl.taxable_amount,
    rc.customer_number,
    olv.ordered_item,
    olv.unit_selling_price,
    olv.unit_list_price,
    olv.tax_value,
    olv.unit_cost,
    olv.ordered_quantity,
    rs.name,
    rc.customer_name,
    rc.customer_id,
    rc.party_id,
    rc.party_number,
    ad.address_id,
    rct.name,
    msi.description,
    olv.unit_selling_price * olv.ordered_quantity,
    c.org_id,
    ohv.header_id,
    olv.sold_to,
    olv.ship_from,
    olv.ship_to_location,
    olv.ship_to_address1,
    olv.ship_to_address2,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -2, LENGTH(olv.ship_to_address5)),
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -9, 6),
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -12, 2),
    SUBSTR(olv.ship_to_address5, 1, LENGTH(olv.ship_to_address5) -15),
    olv.invoice_to_location,
    olv.invoice_to_address1,
    olv.invoice_to_address2,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -2, LENGTH(olv.invoice_to_address5)),
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -9, 6),
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -12, 2),
    SUBSTR(olv.invoice_to_address5, 1, LENGTH(olv.invoice_to_address5) -15),
    olv.flow_status_code,
    olv.terms,
    olv.freight_terms_code,
    olv.shipping_method_code,
    olv.fob_point_code,
    olv.line_id,
    rsh.attribute1,
    rsh.attribute2,
    su.tax_code,
    su.ship_via,
    wdd.tracking_number
    ORDER BY invoice_number;

  • How can I call a Page Process from the Select statement for Report Page

    I'm able to call a javascript using the below:
    img src="#IMAGE_PREFIX#add2.gif" border="0" alt="Icon 4" onClick="javascript:add_connect1('||CPORT.ID||')"
    But Now,
    I'd like to accomplish (2) New things:
    1. instead of using,....... onClick="javascript:add_connect1,
    I'd like to call a Page Process, onClick=
    2. I'd like to be able to call two different processes onClick.
    a. onClick="javascript:passBack('||ID||')"
    b. onClick= <Please see my question #1 above>
    Can someone please help me with the syntax for this,
    If indeed it can even be done?
    Thanks- Gary

    Greg.
    It seems that my situation is the one you describe in you second paragraph, where you mention:
    you could then add the ID column value as a parameter to the javascript functionBut,
    I do not know how to reference the variable in my javascript nor how to use it in my on-demand process.
    If you can hellp me past this last little bump, then I think I will be able to use these skills in Sooo many different areas of my design.
    Here's what I've got so far:
    A. In the select statement I identify the javascript as:
    onClick="javascript:connect_port('<font color=blue>''||ID||''</font>')";
    B. In my javascript I have this:
    <script language="JavaScript" type="text/javascript">
    function connect_port(ID)
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=CONNECT_PORT',0);
    gReturn = get.get();
    get = null;
    </script>
    C. In my on demand function I have this:
    BEGIN
    INSERT INTO CCONNECTIONS_B
    BLDG_ID,CLST_ID,PORT_ID,STRAND_ID
    ) VALUES
    :P2004_BLDG_ID,:P2004_CLST_ID,:P2004_PORT_ID,:P2004_STRAND_ID1
    END;
    You can see that I dont know how to use the value for 'ID' in either the javascript or the On-Process function.
    If you can help me out with this one, Then I can imitate it for the rest.
    -Gary
    Edited by: garyNboston on Apr 3, 2009 6:44 AM
    Edited by: garyNboston on Apr 3, 2009 6:44 AM
    Edited by: garyNboston on Apr 3, 2009 6:45 AM
    Edited by: garyNboston on Apr 3, 2009 6:47 AM

  • Class not getting called by the Select Statement

    Dear All,
    I have created a new class "Z1_EXIT_VARIABLES" in my Dev system and coded for a new Exit Variable for InfoObject "0FISCPER3" in this class.
    But on debugging the Function module "EXIT_SAPLRRS0_001" (INCLUDE ZXRSRU01), I could find that the Select statement
    <i>select CLSNAME
    into  l_clsname
    from VSEOIMPLEM
    where REFCLSNAME = 'ZBWIF_VAR_EXIT'.
    </i>
    calls ALL the classes mentioned in the table "VSEOIMPLEM" with    REFCLSNAME = ZBWIF_VAR_EXIT, EXCEPT the class "Z1_EXIT_VARIABLES". Therefore, the code written by me is not getting executed.
    Also, after debugging the same function module in Quality system, I could find that not all of the classes mentioned in the table "VSEOIMPLEM"are getting called by the select statement.
    (I do not have authorization for CMOD in my Dev system)
    Can anyone suggest a possible solution to the problem ?
    Regards
    Shalabh Jain

    Hi,
    Still waiting for response.
    The issue is not with finding control and performing action on it.
    The coded UI automation script is able to find the control and performing click on that, and after that is is supposed to display the results, which is not happening.
    I am not able to find out why the results are not displaying with coded UI but it's working as expected with SELENIUM web driver.
    I have to do it with CODED UI VS2013, So i request you to give me some solution for this issue, I have done automation earlier for some similar web applications, but never faced this situation.
    Studio: VS2013
    Scripting Language: C#
    HtmlHyperlink performSearchLink = new HtmlHyperlink(inventoryWindow);
     performSearchLink.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Search");
                Mouse.Click(performSearchLink);
    this code is working fine, it's clicking on search but not displaying the results.
    someone reply asap.
    Thanks
    Adrusta

  • Calling an SP takes over 200% more time over the select statement

    As part of my POC converting a SQL Server application over to SAP HANA, I'm find that CALL is taking over 200% more time than calling the SELECT statement directly. The result is that the application that uses ODBC against HANA with CALL statements is taking much more time than SQL Server. I'm finding this for all stored procedure calls in the application. Here is an example:
    CREATE PROCEDURE dbo.usp_GetOrdersByCustomerID
    (IN C_ID bigint)
    LANGUAGE SQLSCRIPT DEFAULT SCHEMA "DBO" READS SQL DATA
    AS BEGIN
    SELECT  TOP 20
       C_F_NAME,
                C_L_NAME,
                C_EMAIL,
                O_ID,
                O_TOTAL,
                O_DTS,
                O_FM_DTS
    FROM    dbo.Customer JOIN dbo.Orders ON C_ID = O_C_ID
    WHERE   C_ID = :C_ID
        ORDER   BY O_ID DESC;
    END;
    When using the following CALL statement in SAP HANA Studio
    CALL dbo.usp_GetOrdersByCustomerID(3429);
    I get execution times that look like this:
    Statement 'CALL dbo.usp_GetOrdersByCustomerID(3429)'
    successfully executed in 9 ms 663 µs  (server processing time: 8 ms 115 µs)
    Fetched 5 row(s) in 0 ms 69 µs (server processing time: 0 ms 0 µs)
    Statement 'CALL dbo.usp_GetOrdersByCustomerID(3429)'
    successfully executed in 11 ms 851 µs (server processing time: 8 ms 238 µs)
    Fetched 5 row(s) in 0 ms 62 µs (server processing time: 0 ms 0 µs)
    Statement 'CALL dbo.usp_GetOrdersByCustomerID(3429)'
    successfully executed in 8 ms 522 µs  (server processing time: 6 ms 892 µs)
    Fetched 5 row(s) in 0 ms 93 µs (server processing time: 0 ms 0 µs)
    When I execute the select statement with the hard coded parameter value, I get much faster results:
    Statement 'SELECT TOP 20 C_F_NAME, C_L_NAME, C_EMAIL, O_ID, O_TOTAL, O_DTS, O_FM_DTS FROM dbo.Customer JOIN ...'
    successfully executed in 4 ms 430 µs  (server processing time: 2 ms 424 µs)
    Fetched 5 row(s) in 0 ms 73 µs (server processing time: 0 ms 0 µs)
    Statement 'SELECT TOP 20 C_F_NAME, C_L_NAME, C_EMAIL, O_ID, O_TOTAL, O_DTS, O_FM_DTS FROM dbo.Customer JOIN ...'
    successfully executed in 4 ms 105 µs  (server processing time: 2 ms 210 µs)
    Fetched 5 row(s) in 0 ms 69 µs (server processing time: 0 ms 0 µs)
    Statement 'SELECT TOP 20 C_F_NAME, C_L_NAME, C_EMAIL, O_ID, O_TOTAL, O_DTS, O_FM_DTS FROM dbo.Customer JOIN ...'
    successfully executed in 4 ms 694 µs  (server processing time: 2 ms 810 µs)
    Fetched 5 row(s) in 0 ms 60 µs (server processing time: 0 ms 0 µs)
    I have 500,000 rows in the Customers table and 2,500,000 rows in the Orders table. The tables are COLUMN tables.
    Is there an optimization that I'm missing?
    Regards,
    Bill

    Hi Bill,
    Can you please try something:
    tab_cust =
    SELECT
       C_F_NAME,
                C_L_NAME,
                C_EMAIL
    FROM    dbo.Customer
    WHERE   C_ID = :C_ID;
    tab_orders =
    SELECT
                O_ID,
                O_TOTAL,
                O_DTS,
                O_FM_DTS
    FROM    dbo.Orders ON C_ID = O_C_ID
    WHERE   O_C_ID = :C_ID
    SELECT  TOP 20
       C_F_NAME,
                C_L_NAME,
                C_EMAIL,
                O_ID,
                O_TOTAL,
                O_DTS,
                O_FM_DTS
    FROM    :tab_cust JOIN :tab_orders ON C_ID = O_C_ID
        ORDER   BY O_ID DESC;
    END;
    Expected behavior: The data set for each of the tables is filtered out and then joined. Although the filter is expected to be pushed to each of the joined tables even in your case, but this is worth the try.
    Regards,
    Ravi

  • How to get the value from a function using a select statement

    I have a function(user defined not built in) that returns multiple values(like an array). My question is how do i get those values in a select statement. when i tried to retrieve it,
    select pack.my_members from dual;
    i am getting an error
    ORA-00902: invalid datatype
    I am sure this must be a syntax error with the select statement
    The following is the function that give the array of data
    package pack
    package spec
    Type my_table is table of varchar2(25);
    function the_members
    return pack.my_table;
    pakcage body
    function the_members return pack.my_table
    Remarks: This function returns a table containing names of the
    members
    is
    tm pack.my_table:= pack.my_table('first member','second member','third member','fourth member');
    begin
    return tm;
    end the_members;

    Check this example on Pipelinedfunction

  • Can we write the select statement on maintence view for data retreval

    Can we use the select statement on maintence view
    Regrads
    Diva

    No. U cannot write a select on maintenance view.

  • Return multiple values from a function to a SELECT statement

    I hope I've provided enough information here. If not, just let me know what I'm missing.
    I am creating a view that will combine information from a few tables. Most of it is fairly straightforward, but there are a couple of columns in the view that I need to get by running a function within a package. Even this is fairly straightforward (I have a function named action_date in a package called rp, for instance, which I can use to return the date I need via SELECT rp.action_date(sequence_number).
    Here's the issue: I actually need to return several bits of information from the same record (not just action_date, but also action_office, action_value, etc.) - a join of the tables won't work here as I'll explain below. I can, of course, run a separate function for each statement but that is obviously inefficient. Within the confines of the view select statement however, I'm not sure how to return each of the values I need.
    For instance, right now, I have:
    Table1:
    sequence_number NUMBER(10),
    name VARCHAR(30),
    Table2:
    Table1_seq NUMBER(10),
    action_seq NUMBER(10),
    action_date DATE,
    action_office VARCHAR(3),
    action_value VARCHAR(60),
    I can't simply join Table1 and Table2 because I have to do some processing in order to determine which of the matching returned rows I actually need to select. So the package opens a cursor and processes each row until it finds the one that I need.
    The following works but is inefficient since all of the calls to the package will return columns from the same record. I just don't know how to return all the values I need into the SELECT statement.
    CREATE VIEW all_this_stuff AS
    SELECT sequence_number, name,
    rp.action_date(sequence_number) action_date,
    rp.action_office(sequence_number) action_office,
    rp.action_value(sequence_number) action_value
    FROM table1
    Is there a way to return multiple values into my SELECT statement or am I going about this all wrong?
    Any suggestions?
    Thanks so much!

    Hi,
    What you want is a Top-N Query , which you can do using the analytic ROW_NUMBER function in a sub-query, like this:
    WITH     got_rnum     AS
         SELECT     action_seq, action_dt, action_office, action_type, action_value
         ,     ROW_NUMBER () OVER ( ORDER BY  action_date
                                   ,            action_seq
                             ,            action_serial
                           ) AS rnum
         FROM     table2
         WHERE     action_code     = 'AB'
         AND     action_office     LIKE 'E'     -- Is this right?
    SELECT     action_seq, action_dt, action_office, action_type, action_value
    FROM     got_rnum
    WHERE     rnum     = 1
    ;As written, this will return (at most) one row.
    I suspect you'll really want to get one row for each group , where a group is defined by some value in a table to which you're joining.
    In that case, add a PARTITION BY clause to the ROW_NUMBER function.
    If you'd post a little sample data (CREATE TABLE and INSERT statements), I could show you exactly how.
    Since I don't have your tables, I'll show you using tables in the scott schema.
    Here's a view that has data from the scott.dept table and also from scott.emp, but only for the most senior employee in each department (that is, the employee with the earliest hiredate). If there happens to be a tie for the earliest hiredate, then the contender with the lowest empno is chosen.
    CREATE OR REPLACE VIEW     senior_emp
    AS
    WITH     got_rnum     AS
         SELECT     d.deptno
         ,     d.dname
         ,     e.empno
         ,     e.ename
         ,     e.hiredate
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.deptno
                                   ORDER BY          e.hiredate
                             ,                e.empno
                           ) AS rnum
         FROM     scott.dept     d
         JOIN     scott.emp     e     ON     d.deptno     = e.deptno
    SELECT     deptno
    ,     dname
    ,     empno
    ,     ename
    ,     hiredate
    FROM     got_rnum
    WHERE     rnum     = 1
    SELECT     *
    FROM     senior_emp
    ;Output:
    .    DEPTNO DNAME               EMPNO ENAME      HIREDATE
            10 ACCOUNTING           7782 CLARK      09-JUN-81
            20 RESEARCH             7369 SMITH      17-DEC-80
            30 SALES                7499 ALLEN      20-FEB-81 
    By the way, one of the conditions in the query you posted was
    action_office     LIKE 'E'which is equivalent to
    action_office     = 'E'(LIKE is always equivalent to = if the string after LIKE doesn't contain any wildcards.)
    Did you mean to say that, or did you mean something like this:
    action_office     LIKE 'E%'instead?

  • How to pass an array to a function from a SELECT statement

    Hi all. I have a problem with passing an array to a function directly from a SELECT statement.
    Here is what I want. If I have a function
    function AAA(arrayVar <ArrayType>) return number;
    I want to be able to call this function this way
    select AAA((2,3,4))
    from dual
    or this way
    select AAA((10,12))
    from dual
    In other words I want to be able to pass an arbitrary number of numbers to the function. And I want this to work in a SELECT statement.
    Does anyone have any ideas how to implement this? What <ArrayType> should I use?(I've read about VARRAY, nested tables in the Oracle documentation but as far as I've understood these array types are meant to be used within PL/SQL blocks).
    I found only this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:208012348074 through Google but it didn't help me.
    Thank you in advance.

    > What <ArrayType> should I use?
    SQL data types - as 3360 showed above. You cannot use PL/SQL structures and user types in the SQL Engine.
    You can however use all SQL structures and types in PL/SQL.
    Arrays in SQL is created as collection type - basic o-o. The collection type (or class) serve as a container for instantiated objects or scalar type.
    This is covered in detail in [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14260/toc.htm]
    Oracle® Database Application Developer's Guide - Object-Relational Features

  • ODI Error - Calling a function in the source database

    I am using this directly in the Interface mapping and getting the following error
    This is the syntax I am using SUM(CASE WHEN ((main.getCertDate(person_id,getdate()) >= current_timestamp) THEN 1 ELSE 0 END)
    ODI-1228: Task Load_Fact_Table1 (Integration) fails on the target MICROSOFT_SQL_SERVER connection SQLSERVER_USA.
    Caused By: java.sql.SQLException: [FMWGEN][SQLServer JDBC Driver][SQLServer]Cannot find either column "main" or the user-defined function or aggregate "main.dbo.getCertDate", or the name is ambiguous.
    Am I missing any additional steps, before calling a function in the mapping. Do I have to do something in the model to include teh function etc., Please help in fixing this issue.
    Thanks for your time and help.

    Hi Michael, Please see below.
    IKM - MSSQL Incremental Update
    Failing on Step 3 - Integration - Insert flow into I$ table
    insert into db11.dbo.##I$_FCT_TABLE
    COMP_ID,
    CNT_CLP_TARGET_MET,
    CNT_CERTIFIED,
    CNT_NOTCERT_WITHIN_GRACE_PRD,
    CNT_CERT_OR_WITHIN_GRACE_PRD,
    CNT_CERT_DELINQUENT,
    SUM_OF_AGE,
    SUM_OF_YEARS_EXPERIENCE,
    LOAD_DATE,
    IND_UPDATE
    select
    CASE WHEN DIM_COMP.COMP_ID IS null then -9999
    ELSE DIM_COMP.COMP_ID
    END,
    SUM(CASE WHEN ((main.dbo.getCertDate ([DISTINCT_RWF.MASTERKEY],GETDATE()) >= CURRENT_TIMESTAMP) OR DISTINCT_RWF = 'NO') THEN 1 ELSE 0 END),
    CURRENT_TIMESTAMP,
    'I' IND_UPDATE
    from ((
    select DISTINCT
    REPORT_WORKFORCE_REVIEW.REGION as REGION, REPORT_WORKFORCE_REVIEW.COMPO as COMPO, REPORT_WORKFORCE_REVIEW.PERSON_ID as PERSON_ID, REPORT_WORKFORCE_REVIEW.WF_STATUS as WF_STATUS, REPORT_WORKFORCE_REVIEW.PERSON_NAME as PERSON_NAME, REPORT_WORKFORCE_REVIEW.CPCN_NUM as CPCN_NUM, REPORT_WORKFORCE_REVIEW.COMMAND as COMMAND, REPORT_WORKFORCE_REVIEW.UIC as UIC, REPORT_WORKFORCE_REVIEW.UIC_STATE as UIC_STATE, REPORT_WORKFORCE_REVIEW.ORG_STRUCTURE_CODE as ORG_STRUCTURE_CODE, REPORT_WORKFORCE_REVIEW.ORG_DESC as ORG_DESC, REPORT_WORKFORCE_REVIEW.LOCATION as LOCATION, REPORT_WORKFORCE_REVIEW.STATE as STATE, REPORT_WORKFORCE_REVIEW.SVC_COMP_DATE as SVC_COMP_DATE, REPORT_WORKFORCE_REVIEW.YRS_OF_SERVICE as YRS_OF_SERVICE, REPORT_WORKFORCE_REVIEW.POSITION_ENTER_DATE as POSITION_ENTER_DATE, REPORT_WORKFORCE_REVIEW.MTHS_EXP_IN_PRESENT_POS as MTHS_EXP_IN_PRESENT_POS, REPORT_WORKFORCE_REVIEW.MTHS_EXP_IN_CURRENT_APC_ACL as MTHS_EXP_IN_CURRENT_APC_ACL, REPORT_WORKFORCE_REVIEW.AGE as AGE, REPORT_WORKFORCE_REVIEW.SEX as SEX, REPORT_WORKFORCE_REVIEW.SUPV_CODE as SUPV_CODE, REPORT_WORKFORCE_REVIEW.ACF as ACF, REPORT_WORKFORCE_REVIEW.CP as CP, REPORT_WORKFORCE_REVIEW.SERIES as SERIES, REPORT_WORKFORCE_REVIEW.DUTY_TITLE as DUTY_TITLE, REPORT_WORKFORCE_REVIEW.APT as APT, REPORT_WORKFORCE_REVIEW.APT_DESC as APT_DESC, REPORT_WORKFORCE_REVIEW.API as API, REPORT_WORKFORCE_REVIEW.SAA as SAA, REPORT_WORKFORCE_REVIEW.GRADE as GRADE, REPORT_WORKFORCE_REVIEW.HI_DEGREE as HI_DEGREE, REPORT_WORKFORCE_REVIEW.LVL_DESC as LVL_DESC, REPORT_WORKFORCE_REVIEW.APC as APC, REPORT_WORKFORCE_REVIEW.ACL as ACL, REPORT_WORKFORCE_REVIEW.CERT_LVL_ACHIEVED_IN_APC as CERT_LVL_ACHIEVED_IN_APC, REPORT_WORKFORCE_REVIEW.CERT_IN_POSITION as CERT_IN_POSITION, REPORT_WORKFORCE_REVIEW.CERT_BELOW_POSITION as CERT_BELOW_POSITION, REPORT_WORKFORCE_REVIEW.NOT_CERTIFIED as NOT_CERTIFIED, REPORT_WORKFORCE_REVIEW.CLP as CLP, REPORT_WORKFORCE_REVIEW.LAST_IDP_UPDATE as LAST_IDP_UPDATE, REPORT_WORKFORCE_REVIEW.LAST_IDP_UPDATE_MTHS as LAST_IDP_UPDATE_MTHS, REPORT_WORKFORCE_REVIEW.SUPV_REVIEW_DATE as SUPV_REVIEW_DATE, REPORT_WORKFORCE_REVIEW.SUPV_REVIEW_DATE_MTHS as SUPV_REVIEW_DATE_MTHS, REPORT_WORKFORCE_REVIEW.EMAIL as EMAIL, REPORT_WORKFORCE_REVIEW.MASTERKEY as MASTERKEY
    from main.dbo.REPORT_WORKFORCE_REVIEW as REPORT_WORKFORCE_REVIEW
    where (1=1)
    ) as DISTINCT_REPORT_WORKFORCE_REVIEW LEFT JOIN main.dbo.PERSON as PERSON ON DISTINCT_REPORT_WORKFORCE_REVIEW.MASTERKEY=PERSON.MASTERKEY) LEFT JOIN main.dbo.ACQUISITION_CORPS_QUALIFICATION as ACQUISITION_CORPS_QUALIFICATION ON DISTINCT_REPORT_WORKFORCE_REVIEW.MASTERKEY=ACQUISITION_CORPS_QUALIFICATION.MASTERKEY) LEFT JOIN main.dbo.PERSONS_POSITIONS as PERSONS_POSITIONS ON DISTINCT_REPORT_WORKFORCE_REVIEW.PERSON_ID=PERSONS_POSITIONS.MASTERKEY
    AND PERSONS_POSITIONS.POSITION_END_DATE IS NULL) INNER JOIN db11.dbo.DIM_COMP as DIM_COMP ON DISTINCT_REPORT_WORKFORCE_REVIEW.COMPO=DIM_COMP.COMP_CODE AND DIM_COMP.CURRENT_RECORD_IND = 1) LEFT JOIN db11.dbo.DIM_POSITION_TYPE as DIM_POSITION_TYPE ON DISTINCT_REPORT_WORKFORCE_REVIEW.APT=DIM_POSITION_TYPE.POSITION_CODE
    AND DIM_POSITION_TYPE.CURRENT_RECORD_IND=1)

  • Need to fetch only the select statement

    Hi ,
    I am able to fetch all the select statements from my program if program name as my input.
    I want only the select statement where we fetch the field entries like
    select single from mara
    select * from mara
    select count(*)
    select matnr from mara
    like this i want to fetch i dont want to display the select-options or start-of-selection .

    Hello Shwetha
    If the function module <b>RS_PROGRAM_TABLES</b> (function group <b>SEA1</b>) is available on your system you can run this fm with the following parameters:
    - OBJECT_TYPE = 'TRAN'   " transaction
    - OBJECT_NAME = 'VA03'  " example
    - OBJECT_TYPE = 'PROG'   " report
    - OBJECT_NAME = 'SAPMV45A'  " example: report executed by VA03
    The fm returns you a list of tables that are accessed.
    Regards,
      Uwe

Maybe you are looking for

  • HT4623 how do i back up my iphone 4 that does not have any current upgrades

    My Iphone 4 still has system version 4.2.10. How do I back it up so I don't lose my current apps and notes and pictures on my phone and then how do I get all the current software?

  • Business Process Flows for Oracle Cloud

    Hi, Where can I find the Business Process/ Model (BPM) flows for Oracle Cloud (Financials, HCM, Sales, Service, Taleo)? Anything similar to Retail Reference Model from Oracle BPA Suite (Business Process Architect) would be fine, as long as it is rele

  • Currency symbol

    I´m working with several numeric fields that are suposedto be holding amounts of money [actually Euros]. Although my display pattern is set to $Z,ZZ9.99 i can't get the PDF produced afterwards to show any currency symbol. (I've also tried with 9.999,

  • How to create a NULL/Void waveform

    so that the waveform graph will not display anything, when there is no waveform for it

  • ALV Print Version

    Hi, I have displayed some columns in an ALV table. One of the columns has data element length of 400. When I use the print version button the data get exported to PDF but the column which has length of 400 takes the entire page width but then too som