Function call in update statement

Hi,
I have an update statement as follows
update
tableA
set
some_Ind = 0
where
cond1=val1
and some_Ind = 1
and f_test(param1, param2) ='Y'
If i have say total 5 rows in tableA and the some_Ind is set to 1 for 2 rows.
Will this update stmt, call the funtion for all 5 rows ? and then update only the rows matching the condition?
Because i am expecting this update stmt to call the function for only the 2 rows which has the some_Ind as set but i get the message printed out 5 times for 5 rows but it updates only 2 rows.
Since this function f_test is very complex, i need to call it for only those rows to be updated.
Please give your suggestions....thanx...

I just gave the test function to display the two parameters.
This function is displaying the messages for all the 5 rows and not for the 2 rows which match the condition.
CREATE OR REPLACE FUNCTION f_test1 (param1IN VARCHAR2,param2 IN VARCHAR2)
RETURN VARCHAR2 IS
retInd varchar2(1);
begin
dbms_output.put_line('param1: '||param1);
dbms_output.put_line(param2: '||param2);
retInd := 'Y';
DBMS_OUTPUT.PUT_LINE('Val of retInd:'||retInd);
RETURN retInd;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('other exception ');
RETURN 'N';
END;

Similar Messages

  • Problems with asynchronous(?) function call before return statement

    I have a function as following inside a class deriving from CustomNode:
    override protected function create () : Node {
                    parseContent();
                    return group;
            }parseContent() executes a HttpRequest and then a PullParser. At least that's what it should do. But actually, it doesn't. Is this because the HttpRequest is asynchronous and is "cancelled" because of the return statement? Or can't this be the problem?

    You would have to update or create the view in the finally block of the onOutput: or onInput methods within the request.
    You could also try
    var viewContent: Node;
    override protected function create () : Node {
                    parseContent();
                    FX.deferAction(function():Void{
                           viewContent = group;
                    return Group{ content: bind viewContent }
            }I never tried that, but it might work.
    Another option is to bind the parsed content to whatever view you are pushing it to. Then whenever the request is done, the view will populate its content on the change of the variable where the content is stored.
    Example:
    var allTables: TableModel[];      
    //***************start of table list decleration****************************\\
    public var list: SwingJList = SwingJList {
        var shortcutKey: Boolean = false;
        focusTraversable: true
        selectedIndex: 0
        action: function(){
            FX.deferAction(function():Void{
                openButton.fire();
        items: bind for( table in allTables ){
            table.name
    var searchDataXml = xmlGenerator.generateSearchXMLString(searchData);
    var contentLength: Integer = searchDataXml.getBytes().length;
    def postRequest: HttpRequest = HttpRequest {
        location: "{WEB_APPLICATION_REQUEST_URL}searchData/?database={DATABASE_KEY}";
        method: HttpRequest.POST;
        headers: [
                HttpHeader {
                    name: HttpHeader.CONTENT_TYPE;
                    value: "application/xml";
                HttpHeader {
                    name: HttpHeader.CONTENT_LENGTH;
                    value: "{contentLength}";
        onStarted: function() {
            println("onStarted - started performing method: {postRequest.method} on location: {postRequest.location}");
        onConnecting: function() { println("onConnecting") }
        onDoneConnect: function() { println("onDoneConnect") }
        onWriting: function() { println("onWriting") }
        onOutput: function(os: java.io.OutputStream) {
            try {
                os.write(searchDataXml.getBytes());
            } finally {
                println("onOutput - about to close output stream.");
                os.close();
                os.flush();
        onToWrite: function(bytes: Long) { println("onToWrite - entire content to be written: {bytes} bytes") }
        onWritten: function(bytes: Long) { println("onWritten - {bytes} bytes has now been written") }
        onDoneWrite: function() { println("doneWrite") }
        onReadingHeaders: function() { println("onReadingHeaders") }
        onResponseCode: function(code:Integer) { println("onResponseCode - responseCode: {code}") }
        onResponseMessage: function(msg:String) { println("onResponseMessage - responseMessage: {msg}") }
        onResponseHeaders: function(headerNames: String[]) {
            println("onResponseHeaders - there are {headerNames.size()} response headers:");
            for (name in headerNames) {
                println("    {name}: {postRequest.getResponseHeaderValue(name)}");
        onReading: function() { println("onReading") }
        onToRead: function(bytes: Long) {
            if (bytes < 0) {
                println("onToRead - Content length not specified by server; bytes: {bytes}");
            } else {
                println("onToRead - total number of content bytes to read: {bytes}");
        onRead: function(bytes: Long) {
            // The toread variable is non negative only if the server provides the content length
            def progress =
            if (postRequest.toread > 0) "({(bytes * 100 / postRequest.toread)}%)" else "";
            println("onRead - bytes read: {bytes} {progress}");
        var parser = new XmlPullParser();
        onInput: function(is: java.io.InputStream) {
            // use input stream to access content here.
            // can use input.available() to see how many bytes are available.
            try {
                allTables = parser.processResults(is);
            } finally {
                is.close();
        onException: function(ex: java.lang.Exception) {
            println("onException - exception: {ex.getClass()} {ex.getMessage()}");
        onDoneRead: function() { println("onDoneRead") }
        onDone: function() { println("onDone") }
    postRequest.start();
    } In this case an array of tableModel names are bound to the list view.
    When the httprequest ends, it sets the parsed tableModel array to the array declared in this class.
    The list view will populate the table names from the array when the request finishes.

  • Function call in Callable statement

    Hi,
    I have a function in pl/sql.
    Am trying to use that using callable statement.
    How to fetch the return value of the function?
    Moreover, is it a good practise to use the function or is there
    any other way in OAF
    Thank you.
    kumar

    This would help.
    Re: calling funcntions from OA Framework
    Thanks
    Tapash

  • Decode function in Update statement

    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!

    882300 wrote:
    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!If you really really really want to update the entire table, the syntax would be...
    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
    ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
    Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
    http://wikis.sun.com/display/Forums/Forums+FAQ

  • Function module In Update Task is called more than once

    Hi experts!!
    I had a requirement to Create a Customer ( i will call it B) when another Customer (A)  is created (ON SAVE).
    I used a Badi to implement the requirement, and inside my Badi i have 2 Function Calls in Update Task.
    The first one to create Customer B and the second one to send Customer's B data to another System.
    Even though the second function call is inside an IF-ENDIF condition ( so that only Customer's B data are sent) the function is called twice sending the same data. My guess is that since the First Function saves the Customer to the database, that is the reason why the second Function is called twice.
    Is there any way i can control how many times a Function In Update Task is called????
    Please help!!
    Thank you in advance!!

    Hi BreakPoint & thank you for your reply!!
    I tried your suggestion but even if i fill the flag during the first call the function is called twice. Looks like during the second database commit the function is called with the correct conditions met but twice.
    Also while debugging it looks like it is only called once. It s very strange!
    Any other ideas???

  • How can i use multiple row subquery in update statement

    Hai All
    I using group function in my update statement.. and i need to update more rows so i need to use multiple row
    subquery pls tell me how to use multiple row subquery in update statement
    For example
    while i am using this like this i got an error
    update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
    barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
    Pls tell me how to use with example
    Thanks & regards
    Srikkanth.M

    Hai Man
    Thanks for ur response Let me clear what i need
    First step Fetch the records as text file and stores into table T1
    and the next step is i have seperated the text using substring and stores in different columns of a table
    There are two shifts 0815 to 1645 and 1200 and 2000
    Here I rep IN and O rep OUT
    Empno date time inout
    001 01-01-10 0815 I
    002 01-01-10 0815 I
    003 01-01-10 0818 I
    001 01-01-10 1100 0
    001 01-01-10 1130 I
    002 01-01-10 1145 0
    002 01-01-10 1215 I
    004 01-01-10 1200 I
    005 01-01-10 1215 I
    004 01-01-10 1315 O
    004 01-01-10 1345 I
    001 01-01-10 1645 0
    002 01-01-10 1715 0
    003 01-01-10 1718 0
    004 01-01-10 2010 0
    005 01-01-10 2015 0
    This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
    T2 contains like this
    Empno Intime Intrin Introut Outtime Date
    001 0815 1100 1130 1645 01-01-10
    002 0815 1145 1215 1715 01-01-10
    003 0818 1718 01-01-10
    004 1200 1315 1345 2010 01-01-10
    005 1215 2015 01-01-10
    This what i am trying to do man but i have little bit problems Pls give some solution with good example
    And my coding is
    declare
         emp_code varchar2(25);
    in_time varchar2(25);
    out_time varchar2(25);
    Cursor P1 is
    Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    From temp_att
    group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    ORDER BY enpno,pdate,ptime;
    begin
         for r2 in p1 loop
    declare
    bar_code varchar2(25);
    begin
    select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
    For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
    if r2.inout ='O' then
    update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
    end if;
    end loop;     
    exception
         when no_data_found then
         if r2.inout ='I' then
                   insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
         end if;
    end;
    end loop;
    commit;     
         end;
    Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
    and how can i use it in the update statement
    Thanks In Advance
    Srikkanth.M

  • Using package functions in an update

    Okay, I have a package function that returns a correct value when used in a SELECT, but when used in an UPDATE, it returns Null. Why can't I used its result in the UPDATE?
    Package Spec
    FUNCTION fpub_get_contract_attribute
         (     n_contract_id_in                    IN               CONTRACT.CONTRACT_ID%TYPE,
              s_attribute_in                         IN               VARCHAR2 )
    RETURN VARCHAR2;
    PRAGMA RESTRICT_REFERENCES(fpub_get_contract_attribute,TRUST,WNDS);
    Source :
    clear;
    rollback;
    select
         contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL') "Before",
         original_sales_channel
    from contract
    where contract_id = 52549615;
    update contract
    set original_sales_channel = NVL(contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL'),'Null')
    where contract_id = 52549615;
    select
         NVL(contract_functions.fpub_get_contract_attribute(52549615,'ORIGINAL_SALES_CHANNEL'),'Null') "After",
         original_sales_channel
    from contract
    where contract_id = 52549615;
    rollback;
    Result :
    Rollback complete
    Before                ORIGINAL_SALES_CHANNEL
    RE                                                                              
    1 row updated
    After                 ORIGINAL_SALES_CHANNEL
    Null                  Null
    Rollback completeAny ideas?
    Thanks,
    Jason

    Pragma restrict_references has not been required since 8i, so you can get rid of that. However, certain things will still be enforced, with or without the pragma. For example, you cannot perform DML from within a packaged function when that function is used in a select statement, although you can perform DML within a packaged function when it is used in an update statement. So, if you are performing some sort of DML in your function, it would not raise an error when used in the update statement, but would cause it to return whatever is specified in the exception block when used in a select statement, causing the different results.
    Please see the demonstration below in which I have created a sample function that contains an insert statement. When I use the function from a select statement, it raises an error and does not insert a row. However, when I use the function in an update statement, it does not raise an error and inserts a row. I have then added an exception clause to the function and re-tested. When I used the function in a select statement, it now returns the value in the exception block, but still does not insert a row. When I used the function in an update statement, it returns a different value, not from the exception block, and inserts a row. Then I removed the insert statement from the function and re-tested. Now it returns the same value, whether used in a select statement or an update statement.
    scott@ORA92> SELECT banner FROM v$version
      2  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE     9.2.0.1.0     Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    scott@ORA92> CREATE TABLE test
      2    (col1 VARCHAR2(30))
      3  /
    Table created.
    scott@ORA92> CREATE TABLE contract
      2    (contract_id            NUMBER,
      3       original_sales_channel VARCHAR2(30))
      4  /
    Table created.
    scott@ORA92> INSERT INTO contract (contract_id) VALUES (52549615)
      2  /
    1 row created.
    scott@ORA92> COMMIT
      2  /
    Commit complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2;
      7  END contract_functions;
      8  /
    Package created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- test with insert statement and no exception handling:
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        INSERT INTO test (col1) VALUES ('inserting');
    10        RETURN 'Null';
    11    END fpub_get_contract_attribute;
    12  END contract_functions;
    13  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> SELECT * FROM contract
      2  /
    CONTRACT_ID ORIGINAL_SALES_CHANNEL
       52549615
    scott@ORA92> COLUMN "Before" FORMAT A30
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> COLUMN "After" FORMAT A30
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> --
    scott@ORA92> -- repeat test with insert statement and exception handling:
    scott@ORA92> ROLLBACK
      2  /
    Rollback complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        INSERT INTO test (col1) VALUES ('inserting');
    10        RETURN 'Null';
    11    EXCEPTION
    12        WHEN OTHERS THEN RETURN 'RE';
    13    END fpub_get_contract_attribute;
    14  END contract_functions;
    15  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    Before                         ORIGINAL_SALES_CHANNEL
    RE
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    After                          ORIGINAL_SALES_CHANNEL
    RE                             Null
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> --
    scott@ORA92> -- repeat test with no insert statement and no exception handling:
    scott@ORA92> ROLLBACK
      2  /
    Rollback complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        RETURN 'Null';
    10    END fpub_get_contract_attribute;
    11  END contract_functions;
    12  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    Before                         ORIGINAL_SALES_CHANNEL
    Null
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    After                          ORIGINAL_SALES_CHANNEL
    Null                           Null
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92>

  • Make an update statement from a proc

    That is, how is possible to call an update statement from
    within a procedure?
    I have tried
    execute update TT_Livraison set ...
    without success.
    Any idea?

    In a procedure, you just include the SQL statement
    CREATE OR REPLACE PROCEDURE foo ...
    AS
    BEGIN
      UPDATE <<some table>>
         SET ...
    END;Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Call function module in update task

    Hi
    I am using the follwoing logic in my prog
    CALL FUNCTION 'Z_Update _Task'    In update task
      EXPORTING
        t_vbak        =  t_vbak.
    But the program goes to dump at call function
    Please let me know if the syntax i am using is correct.
    Edited by: kittu reddy on Feb 28, 2008 5:29 AM

    It might be the type conflict . Please check once .
    Here am giving some information abt UPDATE TASK.
    Why do we use this " In Update Task " ??
    The main update technique for bundling database changes in a single  
    database LUW is to use CALL FUNCTION... IN UPDATE TASK.
    How do we Use ??
    A typical R/3 installation contains dialog work processes and at least one update work process. The update work processes are responsible for updating the database. When an ABAP program reaches a COMMIT WORK statement, any function modules from CALL FUNCTION... IN UPDATE TASK statements are released for processing in an update work process. The dialog process does not wait for the update to finish. This kind of update is called asynchronous update.
    What is the Use... ??
    Asynchronous update is useful when response time from the transaction is critical, and the database updates themselves are so complex that they justify the extra system load
    Thanks
    Jagadeesh

  • Update Statement through function

    Hi,
    I've got the following select statement that is pulling 29 records:
    select distinct aqh.quote_number, aqh.quote_header_id,aqh.quote_version, aql.line_number, msi.inventory_item_id, msi.segment1
    ,aqh.price_list_id, aqh.quote_expiration_date,aql.line_list_price, qpv.operand
    from aso_quote_headers_all aqh, aso_quote_lines_all aql,mtl_system_items msi
    ,qp_list_headers qlh, qp_list_lines qpl, qp_list_lines_v qpv
    where aqh.quote_header_id = aql.quote_header_id
    and aql.inventory_item_id = msi.inventory_item_id
    and aqh.price_list_id = qlh.list_header_id
    and qlh.list_header_id = qpl.list_header_id
    and qlh.list_header_id = qpv.list_header_id
    and qpl.list_line_id = qpv.list_line_id
    and msi.inventory_item_id = qpv.product_id
    and aqh.quote_number = :quote_number --56530
    i need to update the operand = list_line_price, for all the multiple 29 records. for every quote_number and quote_version_no.
    i need help in this to write a function with update statement.
    Thanks and Regards

    Hi,
    whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements) for all the tables, and the results you want from that data. In the case of a DML operation (like UPDATE) the results will be the contents of the changed table after the DML is finished.
    MERGE may be easier to use than UPDATE in this case.
    Put your existing query in the USING clause. The only columns it needs to include in the SELECT clause are those that identify which rows to update, and the new values (line_list_price in this case). I assume that the table to be updated has a unique key, which I called primary_key in the example below. This can actually be two or more columns, but it can't include the column being updated (operand).
    I assume that all the tables and all the conditions in your original query are necessary to get the columns in the SELECT clause. If not, you can simplify the query.
    MERGE INTO     qp_list_lines_v     dst
    USING     (
         select distinct aql.line_list_price, qpv.primary_key
         from aso_quote_headers_all aqh, aso_quote_lines_all aql,mtl_system_items msi
         ,qp_list_headers qlh, qp_list_lines qpl, qp_list_lines_v qpv
         where aqh.quote_header_id = aql.quote_header_id
         and aql.inventory_item_id = msi.inventory_item_id
         and aqh.price_list_id = qlh.list_header_id
         and qlh.list_header_id = qpl.list_header_id
         and qlh.list_header_id = qpv.list_header_id
         and qpl.list_line_id = qpv.list_line_id
         and msi.inventory_item_id = qpv.product_id
         and aqh.quote_number = :quote_number --56530
         )     src
    ON     (src.primary_key     = dst.primary_key)
    WHEN MATCHED THEN UPDATE
    SET     dst.operand     = src.list_line_price;You can use a MERGE statement like this in a PL/SQL procedure or function. (If you put this in a function, then you can only call the function from PL/SQL; you can't use a function that performs DML in a SQL query.)
    As posted above, the statement will use a single, given quote_number. (You mentioned another column, quote_version_number, that does not appear in your original query. It's unclear what you want with that column.)
    You can replace the bind variable :quote_number with an argument to the procedure, as Achyut suggested. It will still only work on a single, given quote_number.
    If you want it to work on all quote numbers at once, then omit the last condition (the one that references quote_number), or change it to
    AND   aqh.quote_number  IS NOT NULLdepending on your needs.
    If you want more help, post some sample data and the desired results.

  • Calling Function Module in Update Task

    Hello Experts,
                              Can anyone let me know about
    Calling Function Module in Update Task.
    Why do we use this " In Update Task "  ??
    How do we Use ??
    What is the Use... ??
    Kindly let me know....
    Thanks and Regards
    Pramod

    hi,
    Why do we use this " In Update Task " ??
    The main update technique for bundling database changes in a single database LUW is to use CALL FUNCTION... IN UPDATE TASK.
    How do we Use ??
    A typical R/3 installation contains dialog work processes and at least one update work process. The update work processes are responsible for updating the database. When an ABAP program reaches a COMMIT WORK statement, any function modules from CALL FUNCTION... IN UPDATE TASK statements are released for processing in an update work process. The dialog process does not wait for the update to finish. This kind of update is called asynchronous update.
    What is the Use... ??
    Asynchronous update is useful when response time from the transaction is critical, and the database updates themselves are so complex that they justify the extra system load
    Real time scenario.
    Suppose a user wants to change an entry in a database table, or add a new one. He or she enters the necessary data, and then starts the update process by choosing Save. This starts the following procedure in the ABAP program:
    Firstly, the program locks the database entry against other users, using the enqueue work process (or the message server in the case of a distributed system). This generates an entry in the lock table. The user is informed whether the update was successful, or whether the lock could not be set because of other users.
    If the lock is set, the program reads the entry that is to be changed and modifies it. If the user has created a new entry, the program checks whether a record with the same key values already exists.
    In the current dialog work process, the program calls a function module using CALL FUNCTION... IN UPDATE TASK, and this writes the change details as an entry in table VBLOG.
    When the program is finished (maybe after further dialog steps), a COMMIT WORK statement starts the final part of the SAP LUW. The work process that is processing the current dialog step starts an update work process.
    Based on the information passed to it from the dialog work process, the update work process reads the log entries belonging to the SAP LUW from table VBLOG.
    The update work process passes this data to the database for updating, and analyzes the return message from the database. If the update was successful, the update work process triggers a database commit after the last database change and deletes the log entries from table VBLOG.
    If an error occurred, the update work process triggers a database rollback, leaves the log entries in table VBLOG, flags them as containing errors, and sends a SAPoffice message to the user, who should then inform the system administrator.
    The corresponding entries in the lock table are reset by the update work process.
    Hope this is helpful, Do reward.

  • How to use User defined Function in Update statement

    Hi All,
    I have written below update statement to update column based on value return by function. but it is not working. Could any one help me on this. This function will return only one value for each project.
    thanks in advance.
    UPDATE dg2.OD_PROJ_LOOKUP_TEMP o
    SET Months_In_Stage_Cnt = select Months_In_Stage_Cnt_ret(o.project_id) from dual;
    thanks
    deb

    hi,
    CREATE FUNCTION fn_emp_ename (p_empno IN emp.empno%TYPE)
       RETURN VARCHAR2
    IS
       v_ename   emp.ename%TYPE;
    BEGIN
       SELECT ename
         INTO v_ename
         FROM emp
        WHERE empno = p_empno;
       RETURN v_ename;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          RETURN NULL;
       WHEN OTHERS
       THEN
          RETURN NULL;
    END fn_emp_ename;
    SQL>
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    14 rows selected.
    SQL>  select fn_emp_ename (empno) as  emp_name from emp;
    EMP_NAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> update emp
      2  set ename= fn_emp_ename (7936)
      3  where empno=7934;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL>  select * from emp where empno=7934;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTN
          7934            CLERK           7782 23-JAN-82       1300                    1
    SQL> i hope this helps .........
    Thanks,
    P Prakash
    Edited by: prakash on Nov 17, 2011 11:52 PM

  • How to call UPDATE statements in the timesten

    Hi i want to know how can i call UPDATE statements from the c program
    as of now i am using SQLPREPARE and SQLEXECUTE for the same.
    but i get the following error.
    Is there any special way of calling UPDATE and INSERT routines.
    As my select statements are doing fine, but i m getting error with UPDATE and INSERT. I am getting the following error
    Can Anyone guide me ?
    ========================================================
    [TimesTen][TimesTen 6.0.4 ODBC Driver][TimesTen]TT5102: Cannot load backend library 'libttorD.a' for Cache Connect. OS error message 'Symbol resolution failed
    for /disk3/users/timesten/TimesTen/TT_EUDEV10G/lib/libttorD.a because:
    Symbol ora_ldap_unbind (number 224) is not exported from dependent
    module /disk1/users/oracle/product/9.2.0/lib/libclntsh.a[shr.o].
    Symbol ora_ldap_memfree (number 225) is not exported from dependent
    module /disk1/users/oracle/product/9.2.0/lib/libclntsh.a[shr.o].
    Symbol
    *** ODBC Error/Warning = S1000, Additional Error/Warning = 5102
    *** (Note: error message was truncated.
    Disconnecting from the data source...
    ==========================================================

    Hi,
    It looks like you are using either :
    1. A READONLY CACHE GROUP with PassThrough > 0.
    or
    2. An SWT CACHE GROUP
    Is that correct? This looks like a mismatch between the TT Oracle library and the version of the Oracle client that you have installed (or maybe a bad setting of LD_LIBRARY_PATH).
    What is the exact version of TimesTen you are using (output of ttVersion command)?
    What is the exact version of Oracle?
    Thanks, Chris

  • Explain plan on Update statement in function

    All,
    I have an update statement in a function and my explain plan shows:
    "Optimizer"     "Cost"     "Cardinality"     "Bytes"     
    "UPDATE STATEMENT"     "ALL_ROWS"     "2"     "1"     "7"     
    "UPDATE user.<table_name>"     ""     ""     ""     ""     
    "INDEX(UNIQUE SCAN) <table_name>.<PK_column_cons>"     "ANALYZED"     "1"     "1"     "7"
    Filtering is on index unique column, but cost is 1 what does that mean?
    do i need to change my update statement in function?
    Any ideas?
    Regards,
    ~ORA

    The cost is the optimizer's measure of how much effort it will take to execute the statement. For any statement the optimizer will evaluate a number of execution plans and choose the one with the lowest cost. I wouldn't worry too much about what it actually "means". However if you want to understand this subject in a lot more detail I would recommend the book Cost-Based Oracle Fundamentals by Jonathan Lewis.
    For your update statement the optimizer has chosen to access a single row by the primary key index, which is probably good enough, so you should not need to change it.
    The only faster way to access the data would be to use the row's ROWID directly. You would need to have fetched this explicitly in a previous SELECT statement, or you could use it implicitly with the WHERE CURRENT OF syntax for a cursor opened with FOR UPDATE.

  • Function modules called in update task

    Hi,
    I am calling two function modules in update task sequentially. I want to know whether these two function modules are also called sequentially in update debugging also?
    My code is like this
    1. call FM1 in update task
    2. Call FM2 in update task
    will this be the same sequence at the time of execution also? or will it be random?
    Thanks in advance.

    ya it will this be in  the same sequence only...........
    Regards
    Anbu

Maybe you are looking for