Generate update statement from select results

I'm trying to generate an update statement based off select statement results.  A very basic example,
SELECT ListID FROM DListing WHERE Status = 2
Results return 3 rows.
1234
2345
3456
How can I take those results and turn them into WHERE criteria for UPDATE statement?
Generated UPDATE statement should look like this.
UPDATE DListing SET Status = 1 WHERE ListID IN (1234,2345,3456)
I have started by creating a temp table to hold my SELECT results, but I don't know how to get those results into format for IN condition.  Right now I get 3 UPDATE statements with 1 ListID in each IN condition.
CREATE TABLE #TempStatusUpdate(ListID INT)
INSERT INTO #TempStatusUpdate
SELECT ListID FROM DListing WHERE Status = 2
SELECT 'UPDATE DListing SET Status = 1 WHERE ListID IN (' + CONVERT(VARCHAR(30),ListID) + ') AND Status = 2'
DROP TABLE #TempStatusUpdate

So what wrong with
UPDTATE DListing
SET     Status = 1
WHERE   ListID IN (SELECT ListID FROM #TempStatusUpdate)
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Where to see generated SQL statement from jdbc adapter?

    Hi everybody,
    where can I see the generated SQL statement from JDBC adapter?
    Regards Mario

    Yes and True lterally means the same, but alas XI does not understand literature..
    Just checked the note as well, as you are correct!
    Regards
    Bhavesh

  • 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

  • Update Statement using SELECT statement

    The following select query return 1 record to me
    [code]
    select  deptno , dname, empno , max_date, max(v_num)
      from (select  d.deptno , d.dname , e.empno ,max (ver_date)  over(partition by d.id ,d.no) max_date  ,v_num
                from  emp e ,dept d
              where  e.deptno=d.deptno and e.dname = d.dname and e.empno=1 and d.deptno =3 )
    group by  deptno , dname, empno , max_date  
    [/code]
    Now I need to update the above value to the emp table itself
    In emp table for the empno=1  I need to update the columns mx_Date and v_num columns with the above last 2 columns in the select statement (max_date, max(v_num) )
    How can I write the update statement for this.
    Thank You

    Something like this
    merge into emp e1
    using (
              select deptno
                   , dname
                   , empno
                   , max_date
                   , max(v_num) v_num
                from (
                       select d.deptno
                            , d.dname
                            , e.empno
                            , max (ver_date)  over(partition by d.id , d.no) max_date 
                            , v_num
                         from emp e
                            , dept d
                        where e.deptno = d.deptno
                          and e.dname  = d.dname
                          and e.empno  = 1
                          and d.deptno = 3
               group
                  by deptno
                   , dname
                   , empno
                   , max_date  
          ) e2
       on (
            e1.empno = e2.empno
    when matched then
        update set e1.mx_date = e2.max_date,
                   e1.v_num   = e2.v_num

  • How to generate Income Statement from Crystal Report

    Hi, Experts,
    I have:
    SAP BUSINESS ONE 2007A
    CRYSTAL REPORT 2008
    I have a problem with generating Income Statement related reports from CRYSTAL.
    For example,
    My revenue accounts are: '411000-00-00' and '412000-00-00', my expense accounts are: '510000-00-00' and '520000-00-00'.
    I'd like to generate the Income statement for Dec 1 - 31, 2008. Please advise how to generate this report. Thanks!
    Lorrie

    Hi, Experts,
    Currently, what I tested to generate the income statement is:
    1. find out the account detail table: JDT1. My database path: Company Name -> dbo -> Tables -> JDT1
    2. follow the standard report menu: add 'JDT1', show 'RefDate', 'ContraAct'; group by'Account', summarize by 'Account'.
    I have the following problems:
    1. with this method, I am not able to find the amount for each transaction. Because the amount does not have a name as 'RefDate' or some other fields.
    2. the 'Account' and 'ContraAct' are all shown as 'SYS00000001685'. It's sysmtem message but not the actual account number or contra account number.
    Thanks!
    Lorrie

  • Generating multiple rows through select result

    Hi,
    I have the requirement to generate rows based on the return of my select.
    This is the source of my table mytab
    COL1    CO2
    ROWS    5
    f01         ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f02         ^[0-9]{1,}$Now I need this output.
    ITEM       REGEXPR
    f01_0001   ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f01_0002   ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f01_0003   ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f01_0004   ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f01_0005   ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f02_0001   ^[0-9]{1,}$
    f02_0002   ^[0-9]{1,}$
    f02_0003   ^[0-9]{1,}$
    f02_0004   ^[0-9]{1,}$
    f02_0005   ^[0-9]{1,}$The value of Rows in my example "5" can be dynamically (could be 50 as well).
    The rows for f01 and f02 could also be 10
    So the source of my table could also look like this:
    COL1    CO2
    ROWS    50
    f01         ^[a-zA-Z0-9ÖÄÜüöäß%_ .,:;!?&[:space:]\(\)-]+$
    f02         ^[0-9]{1,}$
    f03         ^[0-9]{1,}$
    f04         ^[0-9]{1,}$
    f05         ^[0-9]{1,}$
    f06         ^[0-9]{1,}$
    f07         ^[0-9]{1,}$
    f08         ^[a-z]{1,}$
    f09         ^[a-z]{1,}$
    f10         ^[a-z]{1,}$Hope for help.
    Best regards,
    Tobias

    Hi,
    The usual way to do that is to join your table to a Counter Table , a table (or, as in the example below, a sub-query result set) that counts 1, 2, 3, ... as high as you need to go.
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= 50     -- max value needed (or higher)
    SELECT       m.col1 || '_'
                 || TO_CHAR (c.n, 'FM0000')     AS item
    ,       m.col2                          AS regexpr
    FROM       mytab          m
    JOIN       cntr          c  ON  c.n     <= 5     -- or some expression from m
    ORDER BY  item
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Jul 5, 2012 7:32 AM

  • Generating a footnote from selected text

    I am trying to script InDesign CS4 using ExtendScript. I  want the script to cut the selected text, insert a footnote and paste  the text into the footnote body. What I have tried:
    function makeFootnoteOfSelection(){
       var fnText = app.activeDocument.selection[0];
             // this should actually clone the selected text, not reference it, because the next statement zaps it from memory
       app.activeDocument.selection[0].remove();  // works
       var fNote = app.activeDocument.selection[0].footnotes.add();  // works, adds an empty footnote with a reference
       fNote.contents = fnText.contents;
             // this replaces the reference number, I was hoping to retain it and just add the text
             // fNote.contents += fnText.contents; also replaces the reference number
    Any help will be greatly appreciated.

    A problem with 'contents' could be that it works with just the plain characters, no formatting.
    Try this (it's cheating a bit, but it works):
    app.cut();
    var fNote = app.activeDocument.selection[0].footnotes.add();
    app.select (fNote.insertionPoints[-1]);
    app.paste();

  • How to convert update,delete statement into select stmt

    Hi all,
         I have a field called dml_stmt, i am getting the dml statement has input from the user.
         My requirement is, if user is giving "update set col_name = 'xyz' from table_name where codition = 'aa'", before updating the table, i need to get old values from the table and put it in the audit table
         For that,i need to convert those update statement into select stmt and need to execute the query to get the data and then i will put it in the audit table..
         can anyone guide how to convert the update or delete stmt into select(need to write in pl/sql)
    Please do needfull things ......
    Regards,
    Jame

    Maybe I'm missing something, but why would auditing help here? It sounds like the user wants to know the prior values of the data, not the SQL UPDATE statement that was issued. Auditing would tell you that a table was updated, fine-grained auditing would tell you what the UPDATE statement was, but you'd need something else to capture the state of the data prior to the update.
    Depending on why putting triggers on every table was discounted, you may also want to take a look at using Workspace Manager or Total Recall (in 11g) to track a history of data changes. But triggers would be the common solution to this sort of problem.
    Justin

  • Update statement getting ORA-00904 invalid identifier

    I am getting this ORA error when I try to conduct an update statement from a column value in one table to a like-named column in another table.
    For instance, in my select, shown below, this query runs like a champ, returning all of my records
    SELECT
    b.ID,
    b.ZIP, a.ZIP,
    a.NAME,
    a.LOCATION
    FROM TBL_ARCHIVE a
    INNER JOIN TBL_UAT b ON
    a.ID = b.ID
    WHERE
    b.ID > 470000  And b.ID <470100;However, if I try to run an update statement with any of the following, I get this error. It seems so strange to me that I'd get an error using the same columns in the update statement, but would return the desired results effectively from the select statement!
    one version of UPDATE
    UPDATE TBL_ARCHIVE a
    SET a.ZIP = TBL_UAT.ZIP
    WHERE TBL_UAT.ID = a.ID;and another
    UPDATE TBL_ARCHIVE
    SET a.ZIP  =
    (SELECT b.ZIP
    FROM TBL_UAT b
    WHERE b.ID <472500 And b.ID >471000)
    FROM TBL_ARCHIVE a
    WHERE a.ID = b.ID)
    WHERE ID IN
    (SELECT ID
    FROM TBL_UAT b
    WHERE b.ID  <472500 And b.ID >471000
    );^ - this one produces a SQL not properly ended. Error ORA-00933: SQL command not properly ended.
    I'm really unsure though, how what I thought was a fairly basic update statement wouldn't work. I'm using Oracle 11g but through either Toad or SQL Plus. I've gotten these same errors in both.
    Though MS Access runs slow as snails, I can manage to run the update statement successfully with it, a thousand records or so at a time. Problem is, I've got about 300K records needing updating.
    I've looked around for similar problems but haven't found one where someone wasn't either using a reserved word for a column, which I'm not, I don't believe, or a problem that really dealt with this error in the context of an update statement.
    But I'd welcome any enlightenment on this.

    rp0428 wrote:
    UPDATE TBL_ARCHIVE a
    SET a.ZIP = TBL_UAT.ZIP
    WHERE TBL_UAT.ID = a.ID;That isn't a valid query and neither is the other one.
    Please post the actual query you are using and the actual complete error message you are getting (everything about the error that is displayed).^^
    That is NOT a valid query?
    How else would you have an UPDATE statement created to set the value of a column in table A to the value of a (in this case, same named) column in table B?
    And keep them in order to update the records appropriately?
    I'll append the create statements momentarily.
    Thanks!
    CREATE TABLE TBL_UAT
    ( ID NUMBER(6),
    ZIP VARCHAR2(10 BYTE) ) and
    CREATE TABLE TBL_ARCHIVE
    ( ID NUMBER(6) NOT NULL, NAME VARCHAR2(50 BYTE),
    EMAIL VARCHAR2(50 BYTE),
    LOCATION VARCHAR2(50 BYTE),
    DEPARTMENT VARCHAR2(50 BYTE),
    PRIORITY VARCHAR2(50 BYTE),
    APPROVING_MGR_NAME VARCHAR2(50 BYTE),
    TYPE1 VARCHAR2(50 BYTE),
    TYPE2 VARCHAR2(50 BYTE),
    CONTACT_NAME VARCHAR2(50 BYTE),
    CONTACT_PHN_NO VARCHAR2(50 BYTE),
    LOAN_NUM VARCHAR2(50 BYTE),
    REF_ID VARCHAR2(50 BYTE),
    BORROWER_NAME VARCHAR2(50 BYTE),
    ADDRESS VARCHAR2(50 BYTE),
    CITY VARCHAR2(50 BYTE),
    ST VARCHAR2(50 BYTE),
    ZIP VARCHAR2(10 BYTE),
    SALE_DATE DATE,
    COMMENTS VARCHAR2(800 BYTE),
    TIME_REQ DATE,
    ACCTLOC VARCHAR2(50 BYTE),
    OTHER_ACCTLOC VARCHAR2(50 BYTE)) Hope this can be of assistance.
    Thanks, folks!
    Edited by: user515689 on Feb 7, 2012 11:59 AM

  • Update statement problem !!

    Hi,
    I need some specific features for my school project and BDB is almost providing me with this functionality. In my project, I want to provide the user with the functionality to provide the update statements from the user screen. I want to then take the user input in a java variable for manipulation of the xml data and display the end result. The only option I have for the user is to provide the xquery updates with the following syntax: ( I need this syntax for update statements as I use a parser to convert the user input to involve fuzziness):
    "insert nodes &lt;b4&gt;inserted child&lt;/b4&gt; after doc('dbxml:/test.dbxml/book)/Bookstore";
    Now I am trying to run these with the below Code but I am not actually getting the required output. Can somebody help me to debug or fix this code for my requirement. I use the following xml data :
    &lt;Bookstore&gt;
    &lt;Book&gt;
    &lt;book_ID&gt;1&lt;/book_ID&gt;
    &lt;title&gt;Harry Potter and the Order of the Phoenix&lt;/title&gt;
    &lt;subtitle/&gt;
    &lt;author&gt;
    &lt;author_fname&gt;J.K.&lt;/author_fname&gt;
    &lt;author_lname&gt;Rowling&lt;/author_lname&gt;
    &lt;/author&gt;
    &lt;price&gt;9.99&lt;;;/price&gt;
    &lt;year_published&gt;2004&lt;/year_published&gt;
    &lt;publisher&gt;Scholastic, Inc.&lt;/publisher&gt;
    &lt;genre&gt;Fiction&lt;/genre&gt;
    &lt;quantity_in_stock&gt;28997&lt;/quantity_in_stock&gt;
    &lt;popularity&gt;20564&lt;/popularity&gt;
    &lt;/Book&gt;
    &lt;/Bookstore&gt;
    I have track points in my code to find the mistake and I get the following ouput.
    Track 3
    Track 3.1
    Track 3.2-----
    The code I use fails to compile the xquery statement with .prepare API.
    import java.io.*;
    import com.sleepycat.db.*;
    import com.sleepycat.dbxml.*;
    public class phone{
    public static void main(String[] args)
    String document1 = "C:/Documents and Settings/cjmadall/Desktop/BDB/book.xml";
    String docName = "book";
    XmlManager myManager = null;
    XmlContainer myContainer = null;
    try {
    myManager = new XmlManager();
    myContainer = myManager.openContainer("test.dbxml");
    String myQuery = "insert nodes &lt;b4&gt;inserted child&lt;/b4&gt; after doc('dbxml:/test.dbxml/book)/Bookstore";
    // This Works and displays the entire document-&gt; String myQuery = "collection('test.dbxml')";
    // This Doesnt Work, ends with the above output -&gt; String myQuery = "insert nodes &lt;newNode&gt;Some new text&lt;/newNode&gt; after collection("dbxml:/test.dbxml")/Bookstore";
    // collection('test.dbxml')/Bookstore";
    System.out.println("Track 3 ");
    XmlQueryContext managerContext = myManager.createQueryContext();
    System.out.println("Track 3.1 ");
    // Get a context for the document queries
    // XmlQueryContext documentContext = myManager.createQueryContext();
    System.out.println("Track 3.2 ");
    // Prepare the XmlManager query
    *XmlQueryExpression managerQuery = myManager.prepare(myQuery, managerContext);*
    System.out.println("Track 3.3 ");
    // Perform the query.
    XmlResults results = managerQuery.execute(managerContext, 0);
    // Display the result set
    System.out.println("Track 3.4 ");
    XmlValue value;
    while ((value = results.next()) != null){
    System.out.println(value.asString());
    System.out.println("Track 3.5 ");
    results.delete();
    managerQuery.delete();
    // documentContext.delete();
    managerContext.delete();
    } catch (XmlException e) {
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    try {
    if (myContainer != null) {
    myContainer.close();
    if (myManager != null) {
    myManager.close();
    } catch (XmlException ce) {
    // Exception handling goes here
    }//end finally
    Thanks.

    I was using a old version of BDB and the latest version fixed this issue.

  • Doubt about UPDATE STAT COLUMN

    Hi,
    I have a doubt of when to execute update stat:
    i create this SQL to generate an SQL script to generate update stat for all my tables:
    select 'UPDATE STAT ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
    and created this SQL to generate an SQL script for update stat for all columns.
    select 'UPDATE STAT COLUMN(*) FOR ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
    my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
    thanks for any insight
    Clóvis

    > my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
    Hi Clovis,
    hmm... good question.
    There are a few things to know about the UPDATE STAT command here.
    1) It will always generate statistics for key or indexed columns.
    2) The optimizer won't be able to generate a better plan when there are column statistics for non-indexed columns present.
    3) The command will also collect column statistics for all columns that already have statistics.
    The direct effect of 3) is that by running your second command just once - all column statistics will always be collected.
    Since you can easily change the default sample size for your tables via
    ALTER TABLE SAMPLE SIZE 20 PERCENT
    I would say: drop your script and just use
    UPDATE STAT DBUSER.* ESTIMATE
    This single command would lead to the same statistics as your script does.
    And if you really, really want to leave out the JDBC tables - then just set their default sample size to 0 and they will be ignored by the UPDATE STAT command.
    regards,
    Lars

  • Update statement not working inside DBMS_PARALLEL_EXECUTE

    CREATE OR REPLACE procedure
    proc_table_mask_par2 (p_tblName in varchar2
    ,p_strmCount in number)
    IS
    | Name: proc_table_mask
    | Version: 1.0
    | Function: The procedure generates the block which will mask the table based on inputrs from
    MSK_INVENTORY_COLS table
    | Modification History:
    | Ver: Date: Who: What:
    | 1.0 2012-11-26 HB Created
    vtbl_Name varchar2(100);
    vtbl_Count number(19,0);
    vStrm_row_count number(19,0);
    vCurs_count number(19,0) := 1;
    vsql varchar2(30000);
    vsql1 varchar2(30000);
    vstragg varchar2(4000);
    v_try number;
    v_status number;
    v_status1 number;
    vtaskName varchar2(100) := 'Mask job for '||p_tblName ;
    pstartnum number(19,0);
    pendnum number(19,0);
    v_prim_key varchar2(100);
    --retries_in  PLS_INTEGER DEFAULT 2;
    --l_attempts    PLS_INTEGER := 1;
    begin
    -- Use function Stragg to get the update statement from MSK_INVENTORY_COLS
    select stragg(MIC.COLUMN_NAME || ' = ' || MIC.FUNCTION_NAME|| '(' ||MIC.COLUMN_NAME||')') into vstragg from MSK_INVENTORY_COLS mic
    WHERE MIC.TABLE_NAME = p_tblName;
    EXECUTE IMMEDIATE 'select count(1) from '||p_tblName into vtbl_Count;
    --DBMS_OUTPUT.PUT_LINE ( 'vtbl_Count : ' ||vtbl_Count);
    vStrm_row_count := round( vtbl_Count/p_strmCount);
    dbms_output.put_line(' vStrm_row_count : ' || vStrm_row_count);
    -- Update statement
    vsql := vsql ||chr(10) || ' UPDATE '|| p_tblName || ' /*+ parallel ( '||p_tblName ||', '||p_strmCount||') */ ' ;
    vsql := vsql ||chr(10) || ' SET '|| vstragg;
    vsql := vsql ||chr(10) || ' , lock_id = -1 ' ;
    vsql := vsql ||chr(10) || 'WHERE ROWID BETWEEN :starting_rowid AND :ending_rowid' ;
    vsql := vsql ||chr(10) || ' and lock_id <> -1 ; ' ;
    dbms_output.put_line (' vsql : ' || vsql);
    DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName);
    DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID (task_name => vtaskName
    , table_owner => SYS_CONTEXT ('USERENV', 'SESSION_USER') --USER
    , table_name => p_tblName
    , by_row => TRUE
    , chunk_size => vStrm_row_count
    DBMS_PARALLEL_EXECUTE.RUN_TASK (task_name => vtaskName
    , sql_stmt => vsql
    , language_flag => DBMS_SQL.native
    , parallel_level => p_strmCount
    -- Only resume for the following
    -- INVALID_STATE_FOR_REDSUME ORA - 29495
    -- Attempts to resume execution, but the task is not in FINISHED_WITH_ERROR or CRASHED state
    -- Constant value for CRASHED = 8
    -- Constant value for FINISHED_WITH_ERROR = 7
    v_try := 0;
    v_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    dbms_output.put_line (' v_status : ' || v_status);
    dbms_output.put_line (' v_try : ' || v_try);
    WHILE(v_try < 2 and v_status != DBMS_PARALLEL_EXECUTE.FINISHED and ((v_status = 7) or( v_status = 8) ))
    LOOP
    v_try := v_try + 1;
    DBMS_OUTPUT.PUT_LINE (' Why am I getting into this loop : ' );
    DBMS_PARALLEL_EXECUTE.RESUME_TASK(vtaskName);
    v_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    END LOOP;
    DBMS_PARALLEL_EXECUTE.DROP_TASK(vtaskName);
    exception
    when
    others then
    raise;
    dbms_output.put_line(sqlerrm);
    end;
    Gurus
    I am executing the procedure above using the following anonymous block.
    DECLARE
    P_TBLNAME VARCHAR2(32767);
    P_STRMCOUNT NUMBER;
    BEGIN
    P_TBLNAME := 'EMPLOYEE_DIM';
    P_STRMCOUNT := 10;
    A516907.PROC_TABLE_MASK_PAR2 ( P_TBLNAME, P_STRMCOUNT );
    COMMIT;
    END;
    I have used dbms_output for getting values for the following variables. When I check the values the update does not seem to be working.
    vStrm_row_count : 60143
    vsql :
    UPDATE EMPLOYEE_DIM /*+ parallel ( EMPLOYEE_DIM, 10) */
    SET
    BUSINESS_TITLE_NM = FN_TITLE_DRM_ENCRYPTNSUM(BUSINESS_TITLE_NM),COST_CENTER_CD =
    FN_COSTCTR_DRM_ENCRYPTNSUM(COST_CENTER_CD),DIRECT_MGR_NM =
    FN_DRM_REG_ADDR_TEXT(DIRECT_MGR_NM),FIRST_NM =
    FN_FNM_DRM_ENCRYPTNSUM(FIRST_NM),LAST_FIRST_FULL_NM =
    FN_DRM_REG_ADDR_TEXT(LAST_FIRST_FULL_NM),LAST_FIRST_MIDDLE_FULL_NM =
    FN_DRM_REG_ADDR_TEXT(LAST_FIRST_MIDDLE_FULL_NM),LAST_NM =
    FN_LNM_DRM_ENCRYPTNSUM(LAST_NM),PHONE_NO =
    FN_PHONE_DRM_ENCRYPTNSUM(PHONE_NO),PRIMARY_EMAIL_ADDRESS_NM =
    FN_EMAIL_DRM_ENCRYPTNSUM(PRIMARY_EMAIL_ADDRESS_NM)
    , lock_id = -1
    WHERE ROWID
    BETWEEN :starting_rowid AND :ending_rowid
    and lock_id <> -1 ;
    v_status : 4
    v_try : 0

    I tried to do the update using chunk sql and ran the procedure again..No updates are made.
    CREATE OR REPLACE procedure
    proc_table_mask_chunk_sql (p_tblName in varchar2
    ,p_strmCount in number)
    IS
    | Name: A516907.proc_table_mask
    | Version: 1.0
    | Function: The procedure generates the block which will mask the table based on inputrs from
    MSK_INVENTORY_COLS table
    | Modification History:
    | Ver: Date: Who: What:
    | 1.0 2012-11-26 HB Created
    vtbl_Name varchar2(100);
    vtbl_Count number(19,0);
    vStrm_row_count number(19,0);
    vCurs_count number(19,0) := 1;
    vsql varchar2(1000);
    vsql_pk varchar2(1000);
    vstragg varchar2(4000);
    vtaskName varchar2(100) := 'Mask Data in table '||p_tblName ;
    pstartnum number(19,0);
    pendnum number(19,0);
    upd_st number(19,0) := 1;
    v_prim_key varchar2(100);
    l_try NUMBER;
    l_status NUMBER;
    begin
    DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName);
    -- Use function Stragg to get the update statement from MSK_INVENTORY_COLS
    select stragg(MIC.COLUMN_NAME || ' = ' || MIC.FUNCTION_NAME|| '(' ||MIC.COLUMN_NAME||')') into vstragg from MSK_INVENTORY_COLS mic
    WHERE MIC.TABLE_NAME = p_tblName;
    select stragg(UCC.COLUMN_NAME) COLUMN_NAME into v_prim_key
    from user_constraints uc , user_cons_Columns ucc
    where UC.CONSTRAINT_TYPE = 'P'
    and UC.CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
    and UCC.TABLE_NAME = p_tblName;
    vsql_pk := 'SELECT distinct ' || v_prim_key || ','|| v_prim_key || ' FROM ' || p_tblName;
    DBMS_OUTPUT.PUT_LINE ( 'vsql_pk : ' ||vsql_pk);
    --EXECUTE IMMEDIATE ' select stragg(COLUMN_NAME ||''=''||FUNCTION_NAME||''(''||COLUMN_NAME||'')'') from MSK_INVENTORY_COLS WHERE TABLE_NAME = ' ||p_tblName  INTO vstragg ;
    --EXECUTE IMMEDIATE 'select count(1)   from vtbl_Name' into vtbl_Count;
    EXECUTE IMMEDIATE 'select count(1) from '||p_tblName into vtbl_Count;
    --DBMS_OUTPUT.PUT_LINE ( 'vtbl_Count : ' ||vtbl_Count);
    vStrm_row_count := round( vtbl_Count/p_strmCount);
    DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_SQL(vtaskName, vsql_pk, false);
    --DBMS_OUTPUT.PUT_LINE ( 'vStrm_row_count : ' ||vStrm_row_count);
    --EXECUTE IMMEDIATE 'SELECT MIN( '||v_prim_key||') from ' ||p_tblName into pstartnum;
    ----dbms_output.put_line (' pstartnum : ' || pstartnum);
    --pendnum :=  vStrm_row_count;
    ----dbms_output.put_line (' pendnum : ' || pendnum);
    -- Update statement
    vsql := vsql ||chr(10) || ' UPDATE '|| p_tblName || ' /*+ parallel ( '||p_tblName ||', '||p_strmCount||') */ ' ;
    vsql := vsql ||chr(10) || ' SET '|| vstragg;
    vsql := vsql ||chr(10) || ' , lock_id = -1 WHERE ' ;
    vsql := vsql ||chr(10) || v_prim_key|| ' BETWEEN :start_id and :end_id ';
    vsql := vsql ||chr(10) || ' and lock_id <> -1 ; ' ;
    --DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName||'_'||upd_st);
    DBMS_PARALLEL_EXECUTE.RUN_TASK ( vtaskName
    , vsql
    , DBMS_SQL.native
    , parallel_level => p_strmCount
    L_try := 0;
    L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    WHILE(l_try < 2 and L_status != DBMS_PARALLEL_EXECUTE.FINISHED and ((L_status = 7) or( L_status = 8) ))
    Loop
    L_try := l_try + 1;
    DBMS_PARALLEL_EXECUTE.RESUME_TASK(vtaskName);
    L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    END LOOP;
    end;
    Block run :
    DECLARE
    P_TBLNAME VARCHAR2(32767);
    P_STRMCOUNT NUMBER;
    BEGIN
    P_TBLNAME := 'EMPLOYEE_DIM';
    P_STRMCOUNT := 10;
    A516907.PROC_TABLE_MASK_CHUNK_SQL ( P_TBLNAME, P_STRMCOUNT );
    COMMIT;
    END;
    /

  • What is the difference between the two update statements

    Hi Everyone
    Along with the emp table in scott kindly insert the to ins statement into emp.
    Insert into EMP
    (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
    (8000, 'JAMES', 'CLERK', 7698, sysdate,
    1000, 10, 30);
    Insert into EMP
    (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    Values
    (8001, 'JAMES', 'CLERK', 7698, sysdate,
    1000, 10, 30);
    Consider the below two update statements.
    1) update emp a
    set ename=(select loc
    from dept b
    where a.deptno=b.deptno)
    where exists(select loc
    from dept b
    where a.deptno=b.deptno)
    2) update emp a
    set ename=(select loc
    from dept b
    where a.deptno=b.deptno)
    What is the difference between the 1st and 2nd update statement? what is the use of exists clause in the first update statement ? Can u suggest in what case will the two update statements provide different results.
    Thanks in advance

    Second one updates all records in emp. If there is no record in dept then ename will be updated to null.
    The first one only updates records in emp where a record in dept exists. It does not matter whether loc is non-null in dept or not. In an EXISTS query it doesn't matter if you do SELECT *, SELECT LOC, SELECT 1, SELECT NULL - Oracle just checks for existence.
    So most often an update like the first one is meant to improve performance by only updating those emp records that are needed. Usually that is a good idea.
    For this very specific case where all employees do belong to a department, all records in emp will be updated anyway, so for this specific case it actually makes worse performance because it does work to make an unnecessary check.
    Normally the EXISTS query is good for performance, but always figure out if they are needed first ;-)

  • 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

  • DB13 CheckDb and Update Stats Error

    Hi,
    I am getting below error in CheckDb and Update stats:
    Update Stats:
    BR0301E SQL error -20003 at location stats_tab_collect-20, SQL statement:
    'BEGIN DBMS_STATS.GATHER_TABLE_STATS (OWNNAME => '"SAPCRM"', TABNAME => '"WSSOAPPROP_DARK"', ESTIMATE_PERCENT => NULL, METHOD_OPT => 'FOR ALL COLUMNS SIZE 1', DEGREE => NULL
    ORA-20003: Specified bug number (5099019) does not exist
    ORA-06512: at "SYS.DBMS_STATS", line 14537
    ORA-06512: at "SYS.DBMS_STATS", line 14558
    ORA-06512: at line 1
    Check Db :
    BR0301E SQL error -1031 at location BrDbdiffRead-1, SQL statement:
    'PREPARE stmt_5 STATEMENT FROM'
    'SELECT OBJNAME FROM "SAPSR3".DBDIFF WHERE DBSYS IN ('ORACLE', ' ') AND OBJTYPE = 'TABL' AND DIFFKIND IN ('02', '61', '99') ORDER BY OBJNAME'
    ORA-01031: insufficient privileges
    BR0806I End of BRCONNECT processing: ceeuoqja.chk 2010-12-17 06.30.46
    BR0280I BRCONNECT time stamp: 2010-12-17 06.30.46
    BR0804I BRCONNECT terminated with errors
    Above both errors are of different System and both system are just get ready after System Copy of PRD Server.
    Please suggest possible route cause of this error.
    Shivam

    for update stats issue check Note 1417124 - Error ORA-20001 in statistics class CL_SDB_ORA_UPDATE_STATS
    for DB check error go through note 400241
    Please search before you post your thread on SDN

Maybe you are looking for

  • Report Painter for FI

    Hello, Anyone can send me the report painter study material? I had screwed up with the report painter, don't know how to add a sub element in my Profit and Lost Consolidation report. Anyone have training material for CA705? Please give me a coy to  s

  • Oracle Validated RPM - Which to download?

    I'm preparing a couple Linux x86_64 servers for building a RAC cluster and thought I'd give the Oracle Validated RPM a try. The specifics - Red Hat Linux RHEL 5.5 (kernel level 2.6.18-194) Oracle Grid Infrastructure release 11.2.0.2.2 Oracle Database

  • Creating Repository in Oracle 817 on NT...??

    Hi !! I have two database one 817 and other 816 on two differet NT servers. The main development database is 817 . As I didnot want to hinder the development work I created PFDs,FHDs,ERDs,DFDs and generated the database design in 816. All went fine.

  • Making the unloading point as mandatory in MB21

    Hi, I need to make the 'unloading point' (RESB-ABLAD) as a mandatory field in the transaction MB21. Can anyone let me know how to make the configuration changes for this? Thanks in advance, Regards, Swati

  • How to add Actionscript cuepoints in the latest version?

    I can't figure out how to add  Actionscript cuepoints...I see some documentation from November 2009  online but it doesn't match the OSMF docs online for Sprint 10. I seem to be  able to add a cuepoint by writing: var cuePoint:CuePoint = new  CuePoin