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.

Similar Messages

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

  • Update statement using function

    Environment: Win7 and SQL server 2008 R2
    Tools: SQL management tool 2008 R2
    Problem: I have been trying to update id numbers in the staging table. T-SQL statement updates all id number in the staging table, but what if the we have multiple records for the same person who we are assigning the ID to his/her record. It should generate
    one pn_id per ssn regadless if there are several records for the same individual. for example, my code assigns the following id: 
    Student table (ID, ssn, name, subject, grade, year)
    (288258466,192160792 , Sally Johnson, Math, A, 2014 )
    (176268917, 192160792, Sally Johnson, Spanish, B+, 2014 )
    (900303787, 770616858, Jessica Simpson, Spanish, B, 2014 )
    (704099635, 770616858, Jessica Simpson, IT, A, 2014 )
    (704099640, 444718562, Douglas Mike, IT, A, 2014 )
    (288258450, 31883459, Susan Jesson, IT, A, 2014 )
    (176268960, 260518681, Veronica Floris, IT, A, 2014 )
    The expected results should be as the following in the staging table
    Student table (ID, ssn, name, subject, grade, year)
    (288258466,192160792 , Sally Johnson, Math, A, 2014 )
    (288258466, 192160792, Sally Johnson, Spanish, B+, 2014 )
    (900303787, 770616858, Jessica Simpson, Spanish, B, 2014 )
    (900303787, 770616858, Jessica Simpson, IT, A, 2014 )
    (704099640, 444718562, Douglas Mike, IT, A, 2014 )
    (288258450, 31883459, Susan Jesson, IT, A, 2014 )
    (176268960, 260518681, Veronica Floris, IT, A, 2014 )
    My code:
    UPDATE a
    SET pn_id = (Select dbo.gen_id())
    from [dbo].[Staging_Table] a
    where SSN in (Select SSN from [dbo].[staging_Table]
    group by SSN having count(SSN) > 1)
    GO
    I also tried the following code but no success
    ;with cte
    As
    Select * , ROW_NUMBER() Over(Partition BY ssn Order by ssn) As MyCount
    from dbo.Staging_Table
    Select * into #a from cte where MyCount=1
    UPDATE a
    SET pn_id = (Select dbo.fn_gen_id())
    from staging_table a
    Full join #a b on a.ssn = b.ssn
    Drop table #a
    please help.

    I ran some tests and Sandra is correct, you don't always get the same value for all occurrences of the same SSN.
    After thinking about this, I think I understand why this happens.
    With functions, SQL is allowed to assume that multiple calls to a function in a single command with the same parameter values always return the same result.  That's why functions cannot use side-effecting functions and is not allowed to make changes
    to any table except table variables declared in the function.
    And SQL is allowed to rearrange the processing of a command in any manner it believes is most efficient as long as it returns the same result.  So even though the query I gave says first get a set of distinct SSN's and then calls the function only once
    for each SSN, it is valid for SQL to instead call the function once for each row in the original table since this function has no parameters and is therefore should return the same value on each call.  But since the function being called apparently (we've
    not seen the code of the function) returns different values on different calls, the same SSN could be assigned different values, but SQL would still be working correctly.
    Note that it would also be valid for SQL to notice that this function has no parameters and therefore should return the same value every time it is called within the same command and so just call the function once per execution of the command.  This
    would mean that every SSN would get the same ID.  As far as I can determine currently SQL does not do that but a different version in the future with a different optimizer might.
    Tom

  • UPDATE Table through Function Module

    Update delivery document LIKP wit new route LIKP-ROUTE. suggest the correct function Module

    Hi,
    Use BAPI
    BAPI_OUTB_DELIVERY_CHANGE  Change Outbound delivery
    In this BAPI a Parameter called HEADER_DATA of type BAPIOBDLVHDRCHG.
    There is field called Route, pass value in it.
    Also Set field ROUTE_FLG in Parameter HEADER_CONTROL   to X or U for Change.
    Thanks &regards,
    ShreeMohan

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

  • 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

  • I cannot download nor update apps through Apps Store, error message states that app cannot be downloaded, to try again later, this has been happening for the  last five days. Help!

    I cannot download nor update apps through Apps Store, error message states that app cannot be downloaded, to try again later, this has been happening for the  last five days. Help!
    It started when tryung to update Twitter. Now the problem is with every app I try to update or download.

    I have this issue as well. The App Store icon indicates there are updates available but when I open the app a popup says it can't connect to the store and the screen remains white. I have tried a hard reset (power &amp; home button) and several other suggestions I have found throughout the forums here without success.

  • Update statement with Aggregate function

    Hi All,
    I would like to update the records with sum of SAL+COMM+DEPTNO into SALCOMDEPT column for each row. Can we use SUM function in Update statement. Please help me out this
    See below:
    Table
    CREATE TABLE EMP
    EMPNO NUMBER(4) NOT NULL,
    ENAME VARCHAR2(10 CHAR),
    JOB VARCHAR2(9 CHAR),
    MGR NUMBER(4),
    HIREDATE DATE,
    SAL NUMBER(7,2),
    COMM NUMBER(7,2),
    DEPTNO NUMBER(2),
    SALCOMDEPT NUMBER
    Used update statement :
    UPDATE emp e1
    SET e1.salcomdept= (select sum(sumsal+comm+deptno) from emp e2 where e2.empno=e1.empno)
    WHERE e1.deptno = 10
    commit
    Thanks,
    User

    Adding these columns makes no sense, so I'll assume this is just an exercise.
    However, storing calculated columns like this is generally not a good idea. If one of the other columns is updated, your calculated column will be out of sync.
    One way around this is to create a simple view
    SQL> CREATE view EMP_v as
      2  select EMPNO
      3        ,ENAME
      4        ,JOB
      5        ,MGR
      6        ,HIREDATE
      7        ,SAL
      8        ,COMM
      9        ,DEPTNO
    10        ,(nvl(sal,0) + nvl(comm,0) + nvl(deptno,0)) SALCOMDEPT
    11  from   emp;
    View created.
    SQL> select sal, comm, deptno, salcomdept from emp_v;
                     SAL                 COMM               DEPTNO           SALCOMDEPT
                     800                                        20                  820
                    1600                  300                   30                 1930
                    1250                  500                   30                 1780
                    2975                                        20                 2995
                    1250                 1400                   30                 2680
                    2850                                        30                 2880
                    2450                                        10                 2460
                    3000                                        20                 3020
                    5000                                        10                 5010
                    1500                    0                   30                 1530
                    1100                                        20                 1120
                     950                                        30                  980
                    3000                                        20                 3020
                    1300                                        10                 1310
    14 rows selected.

  • Using named parameters with an sql UPDATE statement

    I am trying to write a simple? application on my Windows 7 PC using HTML, Javascript and Sqlite.  I have created a database with a 3 row table and pre-populated it with data.  I have written an HTML data entry form for modifying the data and am able to open the database and populate the form.  I am having trouble with my UPDATE function.  The current version of the function will saves the entry in the last row of the HTML table into the first two rows of the Sqlite data table -- but I'm so worn out on this that I can't tell if it is accidental or the clue I need to fix it.
    This is the full contents of the function . . .
         updateData = new air.SQLStatement();
         updateData.sqlConnection = conn;
         updateData.text = "UPDATE tablename SET Gsts = "Gsts, Gwid = :Gwid, GTitle = :GTitle WHERE GId = ":GId;
              var x = document.getElementsById("formname");
              for (var i = 1, row, row = x.rows[i]; i++) {
                   updateData.parameters[":GId"] = 1;
                   for (var j = 0, col; col=row.cells[j]; j++) {
                        switch(j) {
                             case 0: updateData.parameters[":GTitle"] = col.firstChild.value; break;
                             case 1: updateData.parameters[":Gsts"] = col.firstChild.value; break;
                             case 2: updateData.parameters[":Gwid"] = col.firstChild.value; break;
    Note: When I inspect the contents of the col.firstChild.value cases, they show the proper data as entered in the form -- it just isn't being updated into the proper rows of the Sqlite table.
    Am I using the named parameters correctly? I couldn't find much information on the proper use of parameters in an UPDATE statement.

    Thank you for the notes.  Yes, the misplaced quotes were typos.  I'm handtyping a truncated version of the function so I don't put too much info in the post. And yes, i = 1 'cuz the first rows of the table are titles.  So the current frustration is that I seem to be assigning all the right data to the right parameters but nothing is saving to the database.
    I declare updateData as a variable at the top of the script file
    Then I start a function for updating the data which establishes the sql connection as shown above.
    The correctly typed.text statement is:
            updateData.text = "UPDATE tablename SET Gsts=:Gsts, Gwid=:Gwid, GTitle=:GTitle WHERE GId=:GId";
    (The data I'm saving is entered in text boxes inside table cells.) And the current version of the loop is:
            myTable = document.getElementById("GaugeSts");
            myRows= myTable.rows;
              for(i=1, i<myRows.length, i++) {
                   updateData.parameters[":GId"]=i;
                   for(j=0; j<myRows(i).cells.length, j++) {
                        switch(y) {
                             case 0: updateData.parameters[":GTitle"]=myrows[i].cells[y].firstChild.value; break;
                             case 1: updateData.parameters[":Gsts"]=myrows[i].cells[y].firstChild.value; break;
                             case 2: updateData.parameters[":Gwid"]=myrows[i].cells[y].firstChild.value; break;
                             updateData.execute;
    The whole thing runs without error and when I include the statements to check what's in myrows[i].cells[y].firstChild.value, I'm seeing that the correct data is being picked up for assignment to the parameters and the update. I haven't been able to double check that the contents of the parameters are actually taking the data 'cuz I don't know how to extract the data from the parameters. ( The only reference  I've found so far has said that it is not possible. I'm still researching that one.) I've also tried moving the position of the updateData execution statement to several different locations in the loop andstill nothing updates. 
    I am using a combination of air.Introspector.Console.log to check the results of code and I'm using Firefox's SQlite manager to handle the database.  The database is currently sitting on the Desktop to facilitate testing and I have successfully updated/changed data in this table through the SQLite Manager so I don't think I'm having permission errors and, see below, I have another function successfully saving data to another table.
    I currently have another function that uses ? for the parametersin the .text of a INSERT/REPLACE statement and that one works fine.  But, only one line of data is being saved so there is no loop involved.  I tried changing the UPDATE statement in this function to the INSERT/REPLACE just to make something save back to the database but I can't make that one work either.I've a (And, I've tried so many things now, I don't even remember what actually saved something --albeit incorrectly --to the database in one of my previous iterations with the for loops.)
    I'm currently poring through Sqlite and Javascript tomes to see if I can find what's missing but if anything else jumps out at you with the corrected code, I'd appreciate some ideas.
    Jeane

  • Find affected rows when using OCIBindArrayOfStruct for UPDATE statement

    If I run a bulk UPDATE query using OCIBindArrayOfStruct, is there a way I can tell which+ rows successfully updated?
    I have a file of records of which 75% of PKs are already in the table and will be updated, the other 25% aren't and should be inserted later. I want to attempt an UPDATE statement on each entry in the file, using OCIBindArrayOfStruct to execute in bulk, and then check which entries in my bulk array successfully updated. If an array entry isn't successfully updated then I will assume it should be inserted and will store it for a Direct Path load later.
    Many thanks for any advice you can give as I've been trawling through the docs trying to find a solution for ages now.
    Edited by: Alasdair on 15-Oct-2010 02:13

    To get count from DB using dynamic SQL, you might need form to call a DB function that can run a query and return a number.
    ie
    CREATE OR REPLACE FUNCTION get_count(pTable VARCHAR2, pWhere VARCHAR2) RETURN NUMBER IS
       vCount VARCHAR2(2000);
    BEGIN
       EXECUTE IMMEDIATE
          'SELECT COUNT(1) FROM '||pTable||' WHERE '||pWhere
       INTO vCount;
       RETURN vCount;
    END;Then in your form you do:
       vUpDCnt := get_count(pTable=>'some_table',pWhere=>'...');Hope this helps.

  • Running SQL stored within a varchar2 for an update statement

    I have a table that stores option settings for different programs that run in our system. It just has an id (number), name (varchar2(4000)) and value (varchar2(4000)). I will have one record (id=1) that stores sql code to generate a date that is converted into a character format, something like "to_char(sysdate-60,'YYYY-MM-DD HH24:MI:SS')", and I have two records that store dates (id=2 and 3) as text.
    I want to run something like "update options set value=(select value from options where id=1) where id=2;", but I know that will store my sql code ('to_char(sysdate-60,''YYYY-MM-DD HH24:MI:SS'')'), and not a text-formatted date ('2009-04-16 13:04:05'). Is there any way within sql that I can use an update statement to store the results of value and not value itself? I generally use C++, so if I had to write a function to accomplish this, I would probably place it in the C++ program instead of a pl/sql function.

    "triggers...<shivers>
    Are you allowed to change database-side functionality?"
    For the most part, yes. We're a small group, and I still do most of the DBA work, despite being a C++ developer and having a part-time DBA. The few triggers we have created are for record id numbers on data that a customer will input through APEX, and I will have to keep those. They're only on inserts, do nothing if the id is populated, and don't exist on this table. The trigger here seems to be something deep within oracle that I cannot change.
    CREATE DATABASE LINK LOOPBACK USING '(description=(address=(protocol=beq)(program=/your/path/to/bin/oracle)))';
    UPDATE options SET VALUE = dbms_xmlgen.getxmltype('SELECT VALUE FROM options@loopback WHERE id = 1').EXTRACT('//text()').getstringval () WHERE id = 2;
    ERROR at line 1:
    ORA-12899: value too large for column "TEST"."OPTIONS"."VALUE" (actual: 65, maximum: 55)The "VALUE" column is a varchar(4000). I'm guessing something is too large for one of the oracle functions or there is a problem with a datatype, but I haven't found any answers. Will using extract affect my data in any way, say if my formula has a less than character for some strange reason? I happened to see a comparison between extract().getstringval() and extractval() at [http://pbarut.blogspot.com/2007/01/oracle-xmltype-exctractvalue-vs-extract.html], which makes it look like EXTRACT('//text()').getstringval () will change the less than to '&lt'. I can run tests to check once I get this working, but I'm not sure I can switch the procedure to extractval().
    Edited by: jbo5112 on Jun 15, 2009 5:25 PM -- The forum mangled my response when I actually typed the less than character

  • Optimizing an update statement

    I have the following update statement that I want to run everyday to perform a logical lock on records that are older than so many days. Here is my query
    Update treatment
    set locked_flag = 'Y'
    where treatment_date <= sysdate -90
    and locked_flag = 'N';
    There is an index on the treatment_date and locked_flag columns. Using the <= on the date causes this index to not be used. This table has 3+ million records, and I am updating about 1,500 a day. I would really like to prevent this update statement from doing a full table scan.
    Thanks.

    jspinelli wrote:
    I have the following update statement that I want to run everyday to perform a logical lock on records that are older than so many days. Here is my query
    Update treatment
    set locked_flag = 'Y'
    where treatment_date <= sysdate -90
    and locked_flag = 'N';
    If you can't change the code then the advice to create a histogram on column locked_flag and an index on (locked_flag, treatment_date) could be sufficient to solve the problem,
    The nicest solution, though is probably to create a function-based index:
    create index treatment_fbi on treatment(case locked_flag when 'N' then treatment_date else null end);
    execute dbms_stats.gather_table_stats({table_owner},'treatment',method_opt=>'for all hidden columns size 1')Then change the code to
    Update treatment set
            locked_flag = 'Y'
    where    case locked_flag when 'N' then treatment_date else null end <= sysdate - 90If I've got my case statements right, this gives you an index which is as small as it can be (it will hold the treatment_date for just those rows where locked_flag = 'N') and will allow the optimizer to see that you want to update a very small fraction of the data.
    The only trouble will be if the rows to be updated are very widely scattered through the table - in which case the optimizer might think that even this optimal index isn't worth using.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
    "For every expert there is an equal and opposite expert"
    Arthur C. Clarke                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • If we use DML statement in function then that function can be used inside s

    if we use DML statement in function then that function can be used inside select query or any DML query?

    select f from t2;I think you meant to query t1.
    It works if the function is an autonomous transaction:
    create or replace function f return number
    is
    PRAGMA AUTONOMOUS_TRANSACTION;
    begin
        update t1 set c=2;
        commit;
        return 1;
    end;
    select f from t1But as Billy said why would you want to do DML this way. And this is not the way autonomous procedures should be used either.
    An an answer to an interview question though nothing wrong with it.

  • Printing ALV Report output through Function Modules

    Hi All,
    I want to print my ALV Grid output through function modules/statement (not through print option in menu).
    This is because, i am generating a PDF from spool when user clicks on a button. If any changes happened in the ALV output layout, they will be captured in spool through printing it.
    So can you please tell me how to print the ALV Output through FMs or sending the ALV output to spool.
    Thanks & Regards,
    Senthil.
    Edited by: senthil nathan on May 17, 2010 2:49 PM

    Hi Dev,
    Thanks for the reply.
    I want to print the ALV when the user clicks on a button in toolbar. Lets say the user has made some changes to the layout, (E.g hiding a field) and when i print that output it should use the changed layout, If i use the FM suggested by you, i cant acheive this.
    If you try to print this manually, the system uses the changed layout and not the original. Thats why i want to know FMs/statement to print.
    Regards,
    Senthil.

Maybe you are looking for

  • ICal year view colors

    Is there a way to change the color of the calendar events when you are viewing the calendar in the Year View? My wife and I both share each other's calendars. Her color is blue and mine is orange in the daily/weekly/monthly views it shows up with the

  • HP Officejet Pro 8500 A909a Series email address to print from an ipad

    Where do I find the email address for my HP Officejet Pro 8500 A909a Series so I can use my new HP app on my ipad for printing from my ipad to my printer? Tina This question was solved. View Solution.

  • Adobe Reader & Acrobat Pro Extended 9.2 are now available

    Hi all, Note that Adobe Reader & Acrobat Pro Extended 9.2 are now available http://www.adobe.com/support/downloads/new.jsp Or simply go to  Help / Check for updates in order to get the latest build available. The Adobe® Acrobat® 9.2 Pro Extended upda

  • CS5 - how to delete artboard AND the art on it

    Hello! Is there a way to delete an artboard and everything on it with one command?  I always have to do <shift><o> and <delete> for the artboard, then <esc> and select the art to delete it.

  • DG4ODBC 11.2 to MySQL lost RPC connection to heterogeneous remote agent

    Hi, I'm running into an issue when executing a procedure in Oracle 11.2 which inserts into a table in a MySQL database over a database link. MOS suggested it is an issue with my unixODBC driver. MOS pointed me to a resolution, but I'm not sure how to