Can sql merge statement be used in a batch (oracle 10g)?

Hello,
I am trying to insert into an oracle table multiple rows of values selected from a web page. Can I use a merge statement as a preparedStatement to avoid inserting duplicate records?
Does anybody have any examples they would like to share?
Any suggestions are greatly appreciated.
Thank you,
Logan

I've implemented this by batch inserting into a temp table then running a merge then dropping the temp table.
public void mergeMethod() {
        final String createsql = "CREATE TABLE temp (a INTEGER, b INTEGER, c INTEGER)";
        final String insertsql = "INSERT INTO temp (a, b, c) VALUES (?,?,?)";
        final String mergesql = "MERGE INTO my_table A " +
           "USING temp B ON (A.a = B.a AND A.b = B.b) " +
           "WHEN MATCHED THEN UPDATE SET A.c = B.c " +
           "WHEN NOT MATCHED THEN INSERT (A.id, A.a, A.b, A.c) " +
           "VALUES (my_seq.Nextval,B.a,B.b,B.c)";
        final String dropsql = "DROP TABLE temp";
     Connection conn = null;
     Statement cs = null;
     Statement ms = null;
     Statement ds = null;
     PreparedStatement ps = null;
     boolean retValue = false;
     try {
          conn = getConnection();
          conn.setAutoCommit(false);
          cs = conn.createStatement();
          ms = conn.createStatement();
          ds = conn.createStatement();
          ps = conn.prepareStatement(insertsql);
          for (int i=0; i< 10; i++){
               ps.setInt(1, i);
               ps.setInt(2, i+1);
               ps.setInt(3, i+2);
               ps.addBatch();
          // create temp table
          cs.execute(createsql);
          // execute in batch
          final int updateCount[] = ps.executeBatch();
          // merge the two tables
          ms.execute(mergesql);
          // drop the temp table
          ds.execute(dropsql);
          conn.commit();
          System.out.println("Rows is updated: " + updateCount.length);
     } catch (final SQLException e) {
          if (conn != null) {
              conn.rollback();
          throw e;
     } finally {
          if (ps != null) {
              ps.close();
          if (cs != null) {
              cs.close();
          if (ms != null) {
              ms.close();
          if (ds != null) {
              ds.close();
          if (conn != null) {
              conn.close();
}

Similar Messages

  • Give me the sql query which calculte the table size in oracle 10g ecc 6.0

    Hi expert,
    Please  give me the sql query which calculte the table size in oracle 10g ecc 6.0.
    Regards

    Orkun Gedik wrote:
    select segment_name, sum(bytes)/(1024*1024) from dba_segments where segment_name = '<TABLE_NAME>' group by segment_name;
    Hi,
    This delivers possibly wrong data in MCOD installations.
    Depending on Oracle Version and Patchlevel dba_segments does not always have the correct data,
    at any time esp. for indexes right after being rebuild parallel (Even in DB02 because it is using USER_SEGMENTS).
    Takes a day to get the data back in line (never found out, who did the correction at night, could be RSCOLL00 ?).
    Use above statement with "OWNER = " in WHERE for MCOD or connect as schema owner and use USER_SEGMENTS.
    Use with
    segment_name LIKE '<TABLE_NAME>%'
    if you like to see the related indexes as well.
    For partitioned objects, a join from dba_tables / dba_indexes to dba_tab_partitions/dba_ind_partitions to dba_segments
    might be needed, esp. for hash partitioned tables, depending on how they have been created ( partition names SYS_xxxx).
    Volker

  • Example of using pie graphs in oracle 10g or 9i forms (not JDeveloper)

    Hi..
    Please can anyone show me how to use pie graphs in oracle 10g or 9i forms using bean?
    i also want to know how to put data in pie graph.. as u know in column graph for example we have an x-axis and y-axis,and in pie there is no x-axis and y-axis.. so how i can put the same data in pie graph.. and also i may need more than one value for the x-axis or the y-axis to use in pie graph so how can i do it??
    i use set_custom_property to call properties in beans.
    I would so thankful for how can answer me.. please its urgent
    thanks

    Hi,
    Thanks for your reply..but i already have this demo and it doesn't contain an example for a pie graph..if u know where i can find any example for a pie graph and how to pass data to it i would be so thankful
    Thanks again.
    Eyad Basheer

  • Can I call host file ( Unix Shell script ) from Oracle 10g trigger

    Hi,
    I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
    thanks & regards
    parag

    user12009546 wrote:
    Hi,
    I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
    thanks & regards
    paragIf you are in 10g, you can simple call shell script from DBMS_SCHEDULER:
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'TEST_SCRIPT',
    job_type => 'EXECUTABLE',
    job_action => 'PATH_OF_YOUR_SCRIPT',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=MINUTELY; INTERVAL=1',
    enabled => TRUE,
    comments => 'Shell script from Oracle'
    END;
    /

  • SQL Tuning using Enterprise manager in oracle 10g

    Hi,
    In oracle 10g you have the enterprise manager which can be used to tune sql statements using the SQL Tuning ADvisor and SQL access advisor.
    I believe in oracle 10g the process of SQL Tuning is slightly easier using the Enterprise Manager ...so if some one could explain me that process...
    Again thanking you in advance
    regds
    Manoj Gokhale

    Hi Manoj,
    Didn't you already start two other threads about this same question the SQL forum?
    How do i do the SQL Statement tuning
    Enterprise Manager - sql tuning advisor , Access advisor for SQL Tuning

  • Reading BLOB from SQL Server 2005 using DB Link from Oracle 10g

    Hi All,
    I am trying to read a table's data from SQL Server 2005 using ODBC DB Link created in Oracle 10g (10.2.0.3/4) database. I am not using oracle gateway.
    I am able read all data except for the BLOB data from SQL server 2005. It gives error given below when I try to execute query SELECT * from T_TRANSACTION_DATA@sdeslink inside a stored procedure:
    ORA-22992: cannot use LOB locators selected from remote tables
    Kindly help how to read BLOB from SQL server 2005 inside Oracle 10g.
    Best Regards!
    Irfan

    Irfan,
    If you can read the blob data using 10.2 HSODBC then there should be no problem using the 11g gateway.
    I recommend you download the latest version which is 11.2.0.3 available from My oracle Support as -
    Patch 10404530: 11.2.0.3.0 PATCH SET FOR ORACLE DATABASE SERVER
    This is a full version and does not need a previous version to have bene installed. When installing it needs to be in a completlely separate ORACLE_HOME from the existing 11.2 install.
    For the Ora-22992 problem have a look at this note in My Oracle Support -
    Ora-22992 has a workaround in 10gR2 (Doc ID 436707.1)
    Regards,
    Mike

  • Converting SQL statements from MS server 2000 to Oracle 10g

    We are moving over from MS server 2000 to Oracle 10g as our database for Peoplesoft system.
    There are several embedded SQL statements that I need to investigate to see what needs converting.
    So far I can see a need to convert the following:
    Dates.     GetDate() to ?
    Outer joins. *= to LEFT OUTER JOIN
    Has anyone else done a similar exercise and what other functions do I need to convert?
    Thanks.

    Hello
    A quick google search (http://www.google.co.uk/search?hl=en&q=ms+sql+server+oracle+differences&spell=1)
    came up with this:
    http://dba-oracle.com/oracle_news/2005_12_16_sql_syntax_differences.htm
    There's a quite a few more sites listed.
    HTH
    David

  • SQL 2008 Problem Calling an SP on an Oracle 10G Linked Server

    Hi everyone
    I've read through a number of posts on many sites about this issue but haven't found anything that has helped me so far. The machine I'm using is running Microsoft SQL Server 2008 64bit and the linked server I've created to Oracle 10G is using OraOLEDB.Oracle. If I test the connection in SQL Management Studio it succeeds and for any queries I have using OpenQuery to select from the Oracle DB I have no problem getting results.
    The Oracle 32bit client and 64bit client versions are installed on the machine.
    My problem is that I need to exec an Oracle SP which in turn inserts into various Oracle tables. I previously had this all working fine on 32bit SQL Server 2000 installation connected to Oracle 10G. Using the same code in SQL Server 2008 I get the following error:
    Msg 7357, Level 16, State 2, Line 1
    Cannot process the object "{CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, 'BLPO0099998', 'BLPO0099998', '', '', 39804, 21883, 'BLPO0099998', 249, 1, 950, 'Main', 190506, 37336, '1', TO_DATE( '20090706','YYYYMMDD' ), TO_DATE( '20090706','YYYYMMDD' ), 'INCOMPLETE',37336, {RESULTSET 1, P_Success})}". The OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" indicates that either the object has no columns or the current user does not have permissions on that object
    The call is made by the following piece of code in SQL:
    SET @execCmd = N'SELECT
    P_Success
    FROM
    OPENQUERY( ORACLE, '''+ @oracleCmd + ''')';
    EXECUTE (@execCmd);
    Where @oracleCmd = {CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, ''BLPO0099998'', ''BLPO0099998'', '''', '''', 39804, 21883, ''BLPO0099998'', 249, 1, 950, ''Main'', 190506, 37336, ''1'', TO_DATE( ''20090706'',''YYYYMMDD'' ), TO_DATE( ''20090706'',''YYYYMMDD'' ), ''INCOMPLETE'',37336, {RESULTSET 1, P_Success})}
    I also tried using the below snippet from another post I found and got no joy either.
    declare @result varchar(255)
    exec ('BEGIN
    ?:= your_SP_Name(''arg1'', ''arg2'', etc);
    END;
    ',@result OUTPUT) at your_LinkedServerName;
    select @result;
    OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" returned message "ORA-06550: line 3, column 7:
    PLS-00222: no function with name 'INTF_TW_PO_REQ_INTERFACE' exists in this scope
    ORA-06550: line 3, column 1:
    PL/SQL: Statement ignored".
    I can't figure out why it doesn't work in SQL 2008 when it worked fine in SQL 2000 - PLEASE HELP!
    Thank you
    Alida Hope

    Why development on 10g and production on 8i? Either both should be 8i or both should be 10g.
    If you will keep production on 8i and development on 10g then you cannot stop such errors as there are features that are enabled by default in 10g and both the versions have very big differences.
    Just go ahead and install 8i.

  • Errors using DBMS_SQLTUNE Advisors for Oracle 10g

    I get errors trying to tune the below query for Oracle 10g using the DBMS_SQLTUNE advisors.
    It happens when I wrap either a large block of PL/SQL code that uses bind variables or multiple nested subqueries with multiple JOIN conditions in a SELECT query statement that I wish to tune using the 10g SQLTUNE advisors.
    Message was edited by:
    benprusinski

    Hi, I was trying to use the DBMS_SQLTUNE package to tune my sql statements used in the huge procedure. I can successfully create a task and execute it. But when I run report tuning task, I'm always getting error like the one in below example. Two questions I have now.
    1) Is this becuase I'm using bind, but not passing any values?
    2) Can I able to use to this package to tune a procedures instead of sql statement?
    Example output...
    SQL&gt; SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'my_sql_tuning_task3')
    2 FROM DUAL;
    DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK3')
    GENERAL INFORMATION SECTION
    Tuning Task Name : my_sql_tuning_task3
    Tuning Task Owner : SCOTT
    Scope : COMPREHENSIVE
    Time Limit(seconds) : 3000
    Completion Status : COMPLETED
    Started at : 02/26/2009 21:44:41
    Completed at : 02/26/2009 21:44:41
    Number of Errors : 1
    DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK3')
    Schema Name: KPRAVEEN
    SQL ID : 479831s42xj1n
    SQL Text : SELECT a.pdrorn, a.pdrcto, a.pdrlln FROM f4311 a
    WHERE a.pddoco = receiptsrcrec.prdoco AND a.pddcto = :2 AND
    a.pdkcoo = :3 AND a.pdsfxo = :4 AND a.pdlnid = :5
    ERRORS SECTION
    SQL&gt;

  • Use css file in oracle 10g report builder

    hi every one
    i am using oracle 10g report buidler. i want control paramform by usign css file.
    any body have idea how can i use css file in oracle report builder 10g and how can i modify it's path and i how can i manage any css class on a perticular field.

    Thanks Billy.
    Yes you are right.
    Here why I discarded that option is,
    I may get the source files with changing layouts.
    My Actual scenario is as follows.
    Initially we developped all the things using PL/SQL packages. Its working fine.
    But as per the inputs we received from requirements group, the file structure changes dynamically. and we would able to consider those new columns also. We should be able to changes the rules dynamically.
    Lets say, we doing fullouter join on Src_A and Src_B. on columns col1_A and col1_B.
    Now the requirement changes in a way that, the join should be done on Src_A and Src_C. on columns col1_A and col_C.
    For this I need to define a new package.
    Instead of that, I would like to do everything dynamically based on configuration parameters given as input.
    Thank you,
    Regards,
    Gowtham Sen

  • Error while sending a mail using UTP_MAIL package in Oracle 10g

    Hi,
    We are using UTP_MAIL package to send a mail from Oracle 10g.We have follwed the following steps ...
    SQL> connect sys/password as sysdba
    Connected.
    SQL> @$ORACLE_HOME/rdbms/admin/utlmail.sql
    Package created.
    Synonym created.
    SQL> @$ORACLE_HOME /rdbms/admin/prvtmail.plb
    Package body created.
    SQL > alter system set smtp_out_server = '<mail_server_ip:25>' scope =spfile;
    System altered..
    Now we try the code
    begin
    utl_mail.send(
    sender => 'sender's mail',
    recipients => 'receiver mail',
    CC => 'optional',
    subject => 'Testing utl_mail',
    message => 'Test Mail'
    end;
    But we get the following error...
    ERROR at line 1:
    ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512: at "SYS.UTL_SMTP", line 21
    ORA-06512: at "SYS.UTL_SMTP", line 97
    ORA-06512: at "SYS.UTL_SMTP", line 139
    ORA-06512: at "SYS.UTL_MAIL", line 405
    ORA-06512: at "SYS.UTL_MAIL", line 594
    ORA-06512: at line 2
    We also tried connecting to the mail server through telnet .But it is not getting connected..
    Please help us to solve the issue.

    From your own posting you may have the clue, if you try to access your mail server through telnet and it is not successful, it means the service is down or there are networking issues.
    On pre 10gR2 versions there was a bug 4083461.8. It could affect you if you are on 10gR1
    "Bug 4083461 - UTL_SMTP.OPEN_CONNECTION in shared server fails with ORA-29278 Doc ID:      Note:4083461.8"
    This was fixed on 10gR2 base and on 9.2.0.8.0
    ~ Madrid

  • Error while using UTP_MAIL package in oracle 10g

    Hi,
    I am using the UTP_MAIL package to send a mail from oracle 10g.
    I hane connected to the database as sysdba,but while setting the SMTP_SERVER_OUTPUT parameter i get the following error.
    SQL> ALTER SYSTEM SET smtp_out_server='blrkecmbx02.ad.abc.com:25' scope=both;
    ERROR at line 1:
    ORA-02095: specified initialization parameter cannot be modified
    Pls help to figure out a solution.

    This parameter is not modifiable, check the Oracle Reference: SMTP_OUT_SERVER Initialization Parameter
    Try the scope=spfile instead of both.
    ~ Madrid

  • How can I solve memory lick, which occurs when operate Oracle 10g DB ?

    I'm using Dell power Edge2850 server(dual CPU, 4GB Ram), RedHat AS 3 and Oracle 10g SE ONE. When I started the server, transaction speed was very fast. But after several day, the system has been getting slower seriously.
    So I monitored my system using 'top'. And I've found that almost 30MB swap memory has been used and CPU usage has been only 23%. But there has been 2GB idle Ram memory. Besides when Oracle don't execute any operation, swap memory is not freed. After I started my server, swap memory allocated has been getting larger and larger. And the speed of my system has been getting slower and slower.
    I think that it is very strange thing not to free swap memory when there is no operation on the server.
    Of course, swapping which rise with large transaction is not problem. But it is a serious problem not to free swap memory when there is no transaction.
    How can I solve this ploblem? Thanks.

    This means the the URL for database control will use the http protocol. To convert to the https protocol (using the included SSL certificate), use the steps documented above. Before doing so, pl review MOS Doc 1222603.1
    HTH
    Srini

  • How to find exception occured while using LOGON function in oracle 10g

    Hi,
    I am using LOGON function to login with a different user name in oracle 10g forms.
    LOGON ( User, Pass@tns, FALSE)
    The third parameter is passed as 'FALSE' to avoid the login screen to be opened. If any of the other parameter ( User Name, Password, TNS) is passed wrong, connection is not established but no exception is occurred. The value for 'FORM_FAILURE' is set to 'TRUE'.
    What i need is the ORA error for connection failure. The error message related to user name/password (ORA-01017) or connection identifier (ORA-12155).
    How i can get this error code if connection is failed. Is there any other way to login in oracle forms other than 'LOGON'.
    Habib

    Habib Ahmad wrote:
    Hi,
    I am using LOGON function to login with a different user name in oracle 10g forms.
    LOGON ( User, Pass@tns, FALSE)
    The third parameter is passed as 'FALSE' to avoid the login screen to be opened. If any of the other parameter ( User Name, Password, TNS) is passed wrong, connection is not established but no exception is occurred. The value for 'FORM_FAILURE' is set to 'TRUE'.
    What i need is the ORA error for connection failure. The error message related to user name/password (ORA-01017) or connection identifier (ORA-12155).
    How i can get this error code if connection is failed. Is there any other way to login in oracle forms other than 'LOGON'.As salamu alikum, Habib
    If you pass FALSE in login you can't catch anything. Want to catch the error ?
    Then change
    LOGON ( User, Pass@tns, FALSE)
    to
    LOGON ( User, Pass@tns, TRUE) Now Create On-Error trigger at form level
    and try the following code
    if error_code=01017 then
         message('invalid user name or password');
         message('invalid user name or password');
         raise form_trigger_failure;
    elsif error_code=12154 or error_code=1215 then
         message('invalid connection string');
         message('invalid connection string');
         raise form_trigger_failure;
    end if;Hopes this helps
    If someone's response is helpful or correct, please mark it accordingly.

  • How to find the db accounts using default passwords in oracle 10g

    Hi, can someone pleas tell me , how to find the oracle accounts in the database which are using default passwords. DB verion is 10g and 9i.
    in 11g version we can query the view DBA_USERS_WITH_DEFPWD to view the users....
    any idea in 10g and 9i ?
    thanks in advance.

    951658 wrote:
    Hi, can someone pleas tell me , how to find the oracle accounts in the database which are using default passwords. DB verion is 10g and 9i.
    in 11g version we can query the view DBA_USERS_WITH_DEFPWD to view the users....
    any idea in 10g and 9i ?
    thanks in advance.the only way I've found is to search the web for lists of default users and their passwords, then attempt to log on with said credentials. I'd start with Pete Finnigan's site (google is your friend). He may already have some scripts ready to go, or at least the lists you'd need to get started.

Maybe you are looking for

  • What's wrong with my iPhone 4 battery?!?

    The phone dies really fast, and this has only been happening recently.  I also leave it overnight to charge every night, and nowadays, it only charges to 30%.  I ran the battery down every month prior like its recommended. Also, is it possible that t

  • Roaming Network Problem

    Hi everybody In my home I have setup a roaming network using the following base stations: AirPort Extreme connected to modem over ethernet - creates a wireless network AirPort Express 1 connected to AirPort Extreme over ethernet - creates the same wi

  • Folder size is twice that of its contents????

    Startup Disk > Users > Username My Username folder shows a folder size that is just about double the size of all of its visible folders.  I can see this when viewed in the Finder in List View with Folder Size Shown as my default View setting.    Any

  • I have downloaded over 100 books from apple on my I Pad1. Now I can not get into the store because the iBook stops working

    I buy books to read when I need quiet time but it seem that the I Book store is not working and every time I try it shuts itself down, maybe apple might know what is wrong with this app or I will have to stop trying to buy books and go to Amazon for

  • SMTP COnfiguration

    Hi, We are doing SMTP configuration in our production system , i have a very basic question on this regards. Does the SAP System must be have direct internet connection in order to send mails to internet address or we can connect the internet via SAP