Dynamic Update Queries - SQL Script

Hi All,
I have a table Account_info where columns are ACCT_NO and flag with other information (columns). We are receving a file which contains ACCT_NO and FLAG. Now i need to compare ACCT_NO for Table and file and based on it need to update FLAG column in table.
To automate this process, i can develop a shell script, which load data from file to temp table and then update statement to update Account_info table. For batch process, i can write a for loop, which commit data after every 10,000 update.
but client does not want this way. We have to send file to Production team, where they will load data manually into temp table.
Once done, i have to write a update statement which will take 10000 records to update on every run and then commit it, so there will not be space/memory issue.
For example, if table has 50,000 records, i have to create 5 update statement. and then i have to send all 5 queries as sql script and send it to Production support.
It is difficult for me to do it daily.
Is there any other way, where SQL script is dynamic and based on number of rows/10000 , it create UPDATE statement and run it daily.
Regards,
ACE

ace_friends22 wrote:
Hi All,
I have a table Account_info where columns are ACCT_NO and flag with other information (columns). We are receving a file which contains ACCT_NO and FLAG. Now i need to compare ACCT_NO for Table and file and based on it need to update FLAG column in table.
To automate this process, i can develop a shell script, which load data from file to temp table and then update statement to update Account_info table. For batch process, i can write a for loop, which commit data after every 10,000 update.Why not simply use an external table pointing at the file and use a single update statement? If you write a loop with intermittent commits, this is one of the worst known ways of processing data.
but client does not want this way.And the client knows how to technically implement a solution then? Why aren't they doing it themselves then?
We have to send file to Production team, where they will load data manually into temp table.Unnecessary. Use an External table
Once done, i have to write a update statement which will take 10000 records to update on every run and then commit it, so there will not be space/memory issue.Oracle is an enterprise level database engine capable of processing millions of rows without space/memory issues. If you've encountered shuch an issue you should be trying to identify the cause of it rather than suppress the symptoms.
For example, if table has 50,000 records, i have to create 5 update statement. and then i have to send all 5 queries as sql script and send it to Production support.Bad Idea ^tm^

Similar Messages

  • How to submit an input dynamically to an sql script in a shell script

    Dear all,
    I have a shell script myscript.sh, in that I am running an sql script , say mysql.sql, the sql script prompts for a value, and I have to type that prompted value to run the script. How can I give this value in my shell script itself.
    Sample script
    #!/bin/bash
    echo "script starting at $(date)"
    sqlplus apps/apps @mysql.sql
    echo "script completed at $(date)"
    exit
    Regards,
    Charan

    Hi,
    Please see
    $cat sql_para.sh
    #!/bin/bash
    . .bash_profile
    sqlplus -s apps/apps @status $1
    $cat status.sql
    select status from v$instance where host_name='&1';
    exit;$./sql_para.sh TEST
    You may also see
    http://www.nsa.no/259/shell-scripting-dbas-using-awk-manipulate-oratab
    https://communities.bmc.com/communities/docs/DOC-9942
    Thanks

  • SQL script with a prompt functionality.

    Hello experts,
    I tried searching this on the net but was unsucessful...
    Bascially I need to update an sql script with a prompt functionality..Basically I would like a user prompt that would enter 'Yes or No' to compile invalid objects using utlrp.
    If Yes, it should compile it
    If No it should exit out...
    Can anyone please help.. Need to do this today.
    Edited by: user568296 on Oct 2, 2009 8:18 AM

    Hi,
    As someone suggested, you're probably better off doing this at the OS level.
    SQL*Plus does not have any good mechanism for conditional branching. One trick you can do in SQL*Plus is to run one script from another by saying <tt>@@filename</tt>. By using a substitution variable (which can be defined based on the results of a query) in place of a literal filename, you can make this dynamic.
    For example, the following script runs either
    recompile.sql or
    goodbye.sql
    based on the answer to a prompt:
    ACCEPT     recompile_now      PROMPT        'Do you want to recompile objects now?  '
    COLUMN     next_script_col        NEW_VAL next_script
    SELECT     CASE     
              WHEN  UPPER ('&recompile_now') LIKE 'Y%'
              THEN  'recompile'
              ELSE  'goodbye'
         END     AS next_script_col
    FROM     dual;
    @@&next_script<tt>@@filename</tt> assumes filename.sql is on the same directory as the calling script. You could also give a full path name using only one @-sign:
    <tt>@pathname</tt>

  • Effect of NLS_LANG in SQL scripts

    DB version: 11.2.0.2
    Platform : RHEL 5.6
    We have a software vendor who occasionaly sends us SQL scripts to deploy.
    The scripts will usually contain few DDLs and lots DMLs
    From textpad, i can the see the DMLs (INSERTs , UPDATEs) in SQL Script. It usually contain non-english characters (Dutch, German, French) like
    'Übersicht Buchungssätze' .
    'Fehler beim Löschen der zugeordneten Referenzen!'They always ask us to set NLS_LANG like following.
    export NLS_LANG="AMERICAN_AMERICA.WE8ISO8859P15"After the INSERT, I queried the inserted values from PL/SQL developer. The values appear as it appears in the SQL Script text file as shown above.
    So, what was the effect of setting NLS_LANG ? What could have happened if I hadn't set NLS_LANG ?
    NLS info within out DB
    SQL > select * from nls_Database_parameters;
    PARAMETER                      VALUE
    NLS_LANGUAGE                   ENGLISH
    NLS_TERRITORY                  UNITED KINGDOM
    NLS_CURRENCY                   #
    NLS_ISO_CURRENCY               UNITED KINGDOM
    NLS_NUMERIC_CHARACTERS         .,
    NLS_CHARACTERSET               AL32UTF8
    NLS_CALENDAR                   GREGORIAN
    NLS_DATE_FORMAT                DD-MON-RR
    NLS_DATE_LANGUAGE              ENGLISH
    NLS_SORT                       BINARY
    NLS_TIME_FORMAT                HH24.MI.SSXFF
    NLS_TIMESTAMP_FORMAT           DD-MON-RR HH24.MI.SSXFF
    NLS_TIME_TZ_FORMAT             HH24.MI.SSXFF TZR
    NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH24.MI.SSXFF TZR
    NLS_NCHAR_CHARACTERSET         AL16UTF16
    NLS_DUAL_CURRENCY              ?
    NLS_COMP                       BINARY
    NLS_LENGTH_SEMANTICS           BYTE
    NLS_NCHAR_CONV_EXCP            FALSE
    NLS_RDBMS_VERSION              11.2.0.2.0
    20 rows selected.

    Check your input script encoding first. If it is not UTF8 you may have issues.
    It is important to setup the NLS_LANG when you want to use other encoding in your input than your DB character set.
    Your database character set is AL32UTF8, your default linux locale is UTF8 so when you execute an sql command oracle does not translate the characters just simple executes it.
    If you setup NLS_LANG oracle automatically translates characters from your input to the database character set accordingly. That's the difference.
    So if you did not set the NLS_LANG all characters went into the database as it is because there were no conversion as oracle expected an UTF8 input because that is the default.
    Try to get an UTF8 export of your data if that looks good you are good if not you have to fix. I assume you could have issues with specific characters.
    Please check your data using Oracle SQL Developer as well.
    If you have MOS account see Oracle Support Document 179133.1 [url https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=179133.1]The correct NLS_LANG in a Windows Environment and / or
    [url https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=264157.1]The correct NLS_LANG setting in Unix Environments Doc ID: 264157.1
    for detailed info.

  • SCOM 2012 SP1 Update Rollup 5 - DB and DW SQL script and the Management Packs

    Hi,
    I am applying SCOM 2012 SP1 update rollup 5 from KB article : 2904680.
    Step#  4 and 5 from the "Installation Information" sections says to run the SQL queries(UR_Datawarehouse.sql and Update_rollup_mom_db.sql) located at "%SystemDrive%\Program Files\System Center 2012 SP1\Operations
    Manager\Server \SQL Script for Update Rollups\."
    But I do not have "System Center 2012 SP1\Operations Manager\Server \SQL Script for Update Rollups\." folder location on  my SCOM Management Servers. Similarly I do not have the MPs given in Step #6.
    Can someone please let me know from where else can I get these SQL scripts and the MPs. What if I don't run these SQL scripts. Is that OK?

    You will find it on below path%SystemDrive%\Program Files\System Center 2012\Operations Manager\Server \SQL Script for Update Rollups\.
    inside system center 2012 folder> search to Server folder and inside it you will find SQL Script
    Please remember, if you see a post that helped you please click (Vote As Helpful" and if it answered your question, please click (Mark As Answer).

  • How to reference dynamic parameters in the PL/SQL script

    The meaning of dynamic parameter is the position and name of parameters will be changed based on the data structure of a referenced text file reading by the concerned PL/SQL script. Anybody can post a sample code will be very appreciated.

    The SQL and PL/SQL discussion forum is a good source for this kind of information.
    The URL is:
    PL/SQL

  • How to dynamically update columns in a where clause to a SQL query in OSB?

    Hi Gurus,
    I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
    For example:
    If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
    We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
    I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
    Thanks in advance
    Surya

    I solved my problem.
    In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
    Thank you to who took some time to think about it.
    Marc

  • Dynamic table in a pl/sql script

    Hi everybody
    how can I design a sql query in a pl/sql script when the table I want to access is built dynamically ?
    for instance
    select to_char(sysdate,'MON')
    into v_month
    select * from table_'v_month' --> this is not working
    Thanks for your replies
    Alain

    You will need to use dynamic sql to create a sql statement in PL/SQL.
    If you have 8.1.x, you can use EXECUTE IMMEDIATE. You would need to have something like this in you proc.
    SELECT TO_CHAR(sysdate,'MON')
    INTO v_month;
    tname:= 'table_'||v_month;
    sqlstr := 'SELECT * FROM '||tname;
    EXECUTE IMMEDIATE sqlstr;If you have 8.0.x or less, you will need to use the DBMS_SQL package. This is a little more complicated because you need to do a few more steps, but the principle is similar.
    You can see how to use dynamic sql in the PL/SQL manuals, and in the Application Developer guide.

  • SQL script: dynamic table creation

    Hello,
    I should write a sql script to do the following (simplified):
    - Create a table if it doesn't exist yet
    - Select something from the newly created table and do further conditional actions
    I've tried something like that:
    DECLARE
    lv_count INTEGER;
    BEGIN
    DBMS_OUTPUT.enable();
    SELECT COUNT(*) INTO lv_count FROM user_tables WHERE table_name = 'DATABASEINFO';
    IF(lv_count = 0)
    THEN
         DBMS_OUTPUT.PUT_LINE('Create DatabaseInfo');
    EXECUTE IMMEDIATE
         'CREATE TABLE DATABASEINFO(
              ZDatabaseInfoId RAW(16) NOT NULL,
              ZInfo VARCHAR2(30) NOT NULL,
              ZValue VARCHAR2(100) NOT NULL,
    CONSTRAINT DatabaseInfo_U_NC_PK PRIMARY KEY
    ZDatabaseInfoId
    END IF;
    SELECT COUNT(*) INTO lv_count FROM DatabaseInfo WHERE ZInfo = 'anything';
    The select statement fails with error message "Table or view cannot be found". As far as I know, this is because the table is created dynamically and validation of the sql script fails because the table doesn't exist on compile time.
    How to solve that?
    Best Regards
    Andreas

    866121 wrote:
    Hello,
    I should write a sql script to do the following (simplified):
    - Create a table if it doesn't exist yet
    - Select something from the newly created table and do further conditional actions
    I've tried something like that:
    DECLARE
    lv_count INTEGER;
    BEGIN
    DBMS_OUTPUT.enable();
    SELECT COUNT(*) INTO lv_count FROM user_tables WHERE table_name = 'DATABASEINFO';
    IF(lv_count = 0)
    THEN
         DBMS_OUTPUT.PUT_LINE('Create DatabaseInfo');
    EXECUTE IMMEDIATE
         'CREATE TABLE DATABASEINFO(
              ZDatabaseInfoId RAW(16) NOT NULL,
              ZInfo VARCHAR2(30) NOT NULL,
              ZValue VARCHAR2(100) NOT NULL,
    CONSTRAINT DatabaseInfo_U_NC_PK PRIMARY KEY
    ZDatabaseInfoId
    END IF;
    SELECT COUNT(*) INTO lv_count FROM DatabaseInfo WHERE ZInfo = 'anything';
    The select statement fails with error message "Table or view cannot be found". As far as I know, this is because the table is created dynamically and validation of the sql script fails because the table doesn't exist on compile time.
    How to solve that?
    why, oh why, are you dynamically making table?
    DDL should be done only once via static SQL.
    dig a deeper hole & EXECUTE IMMEDIATE the SELECT.

  • SQL script to update details of Peoplesoft database

    Hello all,
    I'm a new DBA for a UK charity running both PS financials & HR that often needs to build test, training & dev instances from our production environments. Doing this currently requires a number of manual steps to update the various nodes & paths to those required for the new instance, and naturally I didn't become a DBA to do manual work ;-)
    I'm looking to script these steps, but the PS schema being as it is, I'm not having a great deal of joy finding where the relevant data might be. If anyone had a script to do something similar, or could point me in the direction of the tables I'd be extremely grateful. The kind of things that we are currently having to do via the interface are:
    Peopletools > Integration Broker > Integration Setup > Nodes
    Peopletools > Security >Security Objects >Single Sign-on
    Peopletools > Utilities > Administration > URLs
    Peopletools > Integration Broker > Configuration > Quick Configuration > Integration Broker Domains
    Peopletools > Portal > Node Definitions
    Peopletools > Ren Server Configuration > Ren Server Cluster
    We are running MS SQL Server, but any PL SQL scripts would be great - I just need to know which tables hold the data.
    Many thanks,
    Andy

    Well, it is very Peopletools version dependant.
    An easy way could be to open to corresponding page you are talking about, then view the page definition and the associated record. At least this is what I use to do.
    Then you update the background table and see if it is taking your new values.
    To be short, here an extract of those tables (non-limited list, on PT.48) :
    Single sign-on tructed node : pstrustnodes
    Process scheduler definition : ps_serverdefn
    Run control : psprcsruncntl
    Message channels : pschnldefn
    Messaging tables contents : psapmsgpub*, psapmsgsub*, psapmsgarc*
    Message node definition : psmsgnodedefn
    URL : psurldefn
    Job definition : ps_prcsjobdefn
    OPRID (email address) : psoprdefn
    Then you should complete your own list with the method I gave above.
    Nicolas.

  • Sql Script-Update Recepient Reference Password

    Hi All,
                I am very new to Biz-talk server and this is my first task in biz-talk. And I have task to Update Recipient Reference Password in agreements of the parties folder.
               In my Biz-talk Administration console I had the folder with name "Parties" and it holds party name called "NZ" and this NZ is having some agreements. 
               When I click for one of this agreement I am getting 3 taps and in the second tap I am having the column called "Recipient Reference Password" in Identifiers sub-tab in this column I need to write the Sql
    Script command and set the default value as "NZ".Below is the image.
        Can any one help me how can I do this
    Samar

    Not using a SQL script but with C# code and using Microsoft.BizTalk.ExplorerOM can try this..
    The classes which could get you closer are Microsoft.BizTalk.Deployment.Binding.Party and Microsoft.BizTalk.Deployment.IEdiParty. More probably you may have deal with XML and use XPath to update your setting in the XML and then
    Loadthe XML into party settings using EdiData.LoadXml
    Use the following article as the reference to start exploring options..
    http://btserver.blogspot.co.uk/2010/05/exporting-specific-party-from-biztalk.html
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Executing sql script from file, with multiple queries

    Hello,
    I am trying to load an SQL script from a file, parse the script into separate SQL statements, and execute each of them. The final statement will always be a query, and thus will return a result.
    Three problems arise:
    1. I don't know what TYPE of statement each one is (i.e. whether it is an UPDATE or a QUERY), which seems to be required in order to execute it in java (via executeQuery and executeUpdate).
    2. I am not sure of the best way to execute a series of statements (the Statement object has some "batch" functionality, but I'm not sure if there is a better way, or even of the proper way to use this).
    3. I need to be able to make sure the final statement is a QUERY, and thus will return a ResultSet. Otherwise I need to be able to throw an exception.
    This has been causing me a lot of trouble. Any help would be much appreciated.
    Thanks,
    Kevin

    Hi Kevin,
    Have you got any solution for your mentioned problem????
    I am facing almost the same kind of problem like I have some sql files containg simple sql statements as well as code for writting Procs , triggeres, index...functions..and so on. I need to execute this XYZ.sql file from Java side.
    Can you guide me about my problem?????
    Thanks in advance.............
    Mak

  • Dynamic UPDATE statement with parameters for column names.

    Hello,
    On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
    On the other hand, in this Re: execute immediate with dynamic column name update and many other
    posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
    dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
    WHERE ST IN
    (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
    '||P_ST||' = CO.ST AND
    CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
    CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
    EXECUTE IMMEDIATE dynSQL ;
    Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
    The compiling works fine and I use Oracle 11g.
    http://psoug.org/definition/EXECUTE_IMMEDIATE.htm

    OK I extracted from all of your posts so far that I have to use "bind-variables with :"
    From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
    set serveroutput on format wraped;
    DECLARE
    dynSQL VARCHAR2(5000);
    P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
    P_ST                VARCHAR2 (100) :='32132';
    BEGIN
    dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
                  WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
                  '||:P_ST||'                           = CO.ST                  AND
                  CO.'||:P_ENT_E_G_NAME||'     > '||:P_ENT_E_G_WE||' AND
                  CO.'||:P_ENT_B_G_NAME||'    
    < '||:P_ENT_E_G_WE||')';
    --this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
    dbms_output.enable;
    dbms_output.put(dynSQL);
    --EXECUTE IMMEDIATE dynSQL;    
    END;Problem:I think I figured it out, the dates that I parse into the query need additional '

  • Migrating SQL Script to stored procedure...

    I created a SQL script file to run in SQLPlus to
    generate a fixed-format text file (See EDI_PrepForSend
    below)
    How do i do the same thing in a stored
    package/procedure? Can I utilize the
    script I already have working? I need to
    do it in a stored procedure because I need
    to do dynamic queries.
    TIA
    Chuck Plinta
    [email protected]
    ++++++++++++++++++++++++++
    -- EDI_PrepForSend.sql
    SET CONCAT '#';
    SET ESCAPE OFF;
    SET TERM OFF
    -- Set's for flat file
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 50
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET HEADING OFF
    SET VERIFY OFF
    SPOOL o:\ClientData\EDI-Send\&2\EDI-HCFA-Dtl-&1-&3.txt
    COLUMN MC_Number FORMAT A15 HEADING MC_Number
    COLUMN MC_Line_Number FORMAT A3 HEADING Ln#
    COLUMN MC_CPT_Code FORMAT A5 HEADING Code
    COLUMN MC_CPT_Modifier FORMAT A2 HEADING Mod
    COLUMN MC_FDOS FORMAT A8 HEADING FDOS
    COLUMN MC_LDOS FORMAT A8 HEADING LDOS
    COLUMN MC_Line_Charge FORMAT 99999.99 HEADING Charge
    SELECT MC.ICN MC_Number,
    '???' MC_Line_Number,
    MC.CPT_Code MC_CPT_Code,
    MC.CPT_Modifier_1 MC_CPT_Modifier,
    TO_CHAR(MC.First_DOS,'YYYYMMDD') MC_FDOS,
    TO_CHAR(MC.Last_DOS,'YYYYMMDD') MC_LDOS,
    MC.Charge MC_Line_Charge
    FROM &1.Decision_Support DS,
    &1.Medical_Claims MC
    WHERE DS.Reprice_Status = 'U' AND
    MC.CID = DS.CID
    ORDER BY MC.ICN, MC.CID;
    SPOOL OFF

    You need to put your select statement in a parameterised function that returns a REF CURSOR. This is all well documented in the PL/SQL users guide.
    Then you amend your SQL*PLUS script to call the function
    VAR rc REFCURSOR
    EXEC :rc := yr_function('&1')
    PRINT rc
    Cheers, APC

  • IF statement syntax in SQL script view

    I need to include a "IF" condition in the "SELECT" section of my SQL script view.
    I tried the following syntax's but I get the error 'Incorrect SQL syntax near 'IF'
    1.  IF(Revenue <> '0' AND Quantity <> '0', Revenue/Quantity, '0') AS Gross Price
    2.  IF(Revenue != '0' AND Quantity != '0', Revenue/Quantity, '0') AS Gross Price
    3.  IF(Revenue <> '0' AND Quantity <> '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    4.  IF(Revenue != '0' AND Quantity != '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    My final SQL would read like follows:
    SELECT field1, field2, IF(......) AS field3
    FROM table1
    Can anybody please help with the correct IF statement syntax to be used in the SQL script based view?

    Hi Lakshmi,
    below is the syntax for IF statement.
    IF <bool_expr1> THEN
    <then_stmts1>
    ELSEIF <bool_expr2>
    THEN <then_stmts2>
    [ELSE <else_stmts3>]
    END IF
    eg :
    BEGIN
    DECLARE found INT := 1;
    SELECT count(*) INTO found FROM books WHERE isbn = :v_isbn;
    IF :found = 0 THEN
    INSERT INTO books VALUES (:v_isbn, 'In-Memory Data Management', 1, 1, '2011', 42.75, 'EUR');
    ELSE
    UPDATE books SET price = 42.75 WHERE isbn =:v_isbn;
    END IF;
    END;
    Sreehari

Maybe you are looking for