ODP OracleCommandBuilder. Updating a table including DATE columns.

Hi
I have a problem with the OracleCommandBuilder not creating the correct update commands when I have DATE type columns in the table.
I have created a test table (called DATETEST) with three columns:
STRINGCOLUMN     VARCHAR2 10
DATECOLUMN DATE
NUMBERCOLUMN     NUMBER
The STRINGCOLUMN is the primary key.
Then I created a typed dataset that looks like this:
STRINGCOLUMN     string
DATECOLUMN string
NUMBERCOLUMN     long
This is the XML schema for the typed dataset:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="DateDS" targetNamespace="http://tempuri.org/DateDS.xsd" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/DateDS.xsd" xmlns:mstns="http://tempuri.org/DateDS.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
     <xs:element name="DateDS" msdata:IsDataSet="true">
          <xs:complexType>
               <xs:choice maxOccurs="unbounded">
                    <xs:element name="DATETEST">
                         <xs:complexType>
                              <xs:sequence>
                                   <xs:element name="DATECOLUMN" type="xs:string" minOccurs="0" />
                                   <xs:element name="STRINGCOLUMN" type="xs:string" minOccurs="0" />
                                   <xs:element name="NUMBERCOLUMN" type="xs:long" minOccurs="0" />
                              </xs:sequence>
                         </xs:complexType>
                    </xs:element>
               </xs:choice>
          </xs:complexType>
     </xs:element>
</xs:schema>
And this is the test code:
Dim connection As Oracle.DataAccess.Client.OracleConnection
Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter()
Dim dbCommand As New Oracle.DataAccess.Client.OracleCommand()
Dim sqlstring As String
Dim data As New DateDS() 'Typed dataset
Const ConnectionString As String = "User Id=............."
Try
'Connect to database
connection = New OracleConnection(ConnectionString)
connection.Open()
'Get data from table DATETEST
dbCommand.CommandText = "SELECT STRINGCOLUMN, TO_CHAR(DATECOLUMN) AS DATECOLUMN, NUMBERCOLUMN FROM DATETEST"
dbCommand.Connection = connection
adapter.SelectCommand = dbCommand
adapter.Fill(data, "DATETEST")
'Make changes to dataset
data.DATETEST(0).DATECOLUMN = Now()
data.DATETEST(0).NUMBERCOLUMN = data.DATETEST(0).NUMBERCOLUMN + 1
'Update database
sqlstring = "SELECT * FROM DATETEST"
adapter.SelectCommand = New OracleCommand(sqlstring, connection)
Dim custCB As New Oracle.DataAccess.Client.OracleCommandBuilder()
custCB.DataAdapter = adapter
adapter.Update(data, "DATETEST")
'Disconnect
connection.Close()
connection.Dispose()
Catch exc As Exception
MessageBox.Show(exc.Message)
End Try
Getting the data from the database is not a problem.
The dataset contains the correct information.
But updating the database is impossible.
I get errors like:
ORA-01861: literal does not match format string
And if I don't specify a DATE format in the TO_CHAR statement I get this error:
Concurrency violation: the UpdateCommand affected 0 records.
I think I've tried everything.
I've used the OracleGlobalization class, with the SetSessionInfo method.
I've tried all different types of date conversions to make sure that
the date format on the database is the same as in the dataset.
I've tried to change the NLS parameters on the DB server and in the registry on the client.
I've tried to change the DATECOLUMN type in the typed dataset from string to Oracle.DataAccess.Types.OracleDate
But it still doesn't work.
The default date format on the DB 9i server is AMERICAN,(DD-MON-RR).
A strange thing is that when I instead of using the ODP classes use
the System.Data.OracleClient and its OracleCommandBuilder
the code works perfectly without any errors.
This is the test code that works:
Dim connection As System.Data.OracleClient.OracleConnection
Dim adapter As New System.Data.OracleClient.OracleDataAdapter()
Dim dbCommand As New System.Data.OracleClient.OracleCommand()
Dim data As New DateDS()
Dim sqlstring As String
Const ConnectionString As String = "User Id=......."
Try
'Connect to database
connection = New System.Data.OracleClient.OracleConnection(ConnectionString)
connection.Open()
'Get data from table DATETEST
dbCommand.CommandText = "SELECT STRINGCOLUMN, TO_CHAR(DATECOLUMN,'YYYY-MM-DD HH24:MI:SS') AS DATECOLUMN, NUMBERCOLUMN FROM DATETEST"
dbCommand.Connection = connection
adapter.SelectCommand = dbCommand
adapter.Fill(data, "DATETEST")
'Make changes to dataset
data.DATETEST(0).DATECOLUMN = Now()
data.DATETEST(0).NUMBERCOLUMN = data.DATETEST(0).NUMBERCOLUMN + 1
'Update database
sqlstring = "SELECT * FROM DATETEST"
adapter.SelectCommand = New System.Data.OracleClient.OracleCommand(sqlstring, connection)
Dim custCB As New System.Data.OracleClient.OracleCommandBuilder()
custCB.DataAdapter = adapter
adapter.Update(data, "DATETEST")
'Disconnect
connection.Close()
connection.Dispose()
Catch exc As Exception
MessageBox.Show(exc.Message)
End Try
My experience until this came up is that the ODP provider is better on everything
than the microsoft Oracle provider so I don't want to switch unless I have to.
Could someone that have used the ODP OracleCommandBuilder for updating a table including DATE columns with a typed dataset please give me some tips on how to make this work?
I would be the happiest man on earth if someone had a solution :-)
Erik

Don't convert the dates to strings. Ever.
The command builder uses the metadata returned from the select command to build the insert/update commands. Using to_char in the query tells ODP that that is a varchar2 column. If you omit the to_char the commandBuilder will know to bind a date parameter in that spot.
Also in your typed dataset you should change the type from a string to a date.
David

Similar Messages

  • Updating target table with date in owb using mapping

    I want to update the effetive begin date (month begin date) when we load the target table. I have field in target table has Eff_updated_dt defined as DATE.
    If I use the Data generator operator and then expression operator (trunc (sysdate,'mm' ) it giving error. It says data generator operator should be connected to flat file .
    What other operators can I use to update the column with month begin data.
    Also which operator I have use to have sequence key in the table.
    Thanks

    you can always use a constant for the date field.
    just create a constant of type date and give it the value you want, trunc (sysdate,'mm' ) and connect it to your target column, Eff_updated_dt defined.
    you have a sequence operator that you can use to link to your "sequence key" as well.
    Borkur

  • Updates on table on specified columns

    Hi Techies,
    I have updated the table with one specified condition, based on the specified condition updation is done successfully(2000 rows).
    again I wanted to verify the records updated on the table. But when I checking the condition on the table it gives more records(5000 rows).
    Can you please tell me ,in which data dictionary table we can check the updation history (date,column,table)
    OS :Solarix 5.10
    DB 10.2.0.4
    thanks
    tippu

    Tippu wrote:
    Hi Techies,
    I have updated the table with one specified condition, based on the specified condition updation is done successfully(2000 rows).
    again I wanted to verify the records updated on the table. But when I checking the condition on the table it gives more records(5000 rows).
    Can you please tell me ,in which data dictionary table we can check the updation history (date,column,table)
    OS :Solarix 5.10
    DB 10.2.0.4
    thanks
    tippuso you updated SOMECOLUMN to value 'ABCD' and the update hit 2000 rows. Now you find that more that 2000 rows have SOMECOLUMN value of 'ABCD'. Is it possible that there were some number of rows already set to 'ABCD' before your update?

  • Performance tuning -index on big table on date column

    Hi,
    I am working on Oracle 10g with Oracle Apps 11i on Sun.
    we have a large non-partition table "GL_JE_HEADERS" with 7 million rows.
    Now we want to run the query for selecting rows using between clause on date column.
    I have created Btree index on the this table.
    Now how can I tune the query? Which hint should I use for the query?
    Thanks,
    rane

    Hi Rane,
    Now how can I tune the query?Indexes on DATE datatypes are tricky, as the SQL queries must match the index!
    For example, an index on ship_date would NOT match a query:
    WHERE trunc(ship_date) > trunc(sysdate-7);
    WHERE to_char(ship_date,’YYYY-MM-DD’) = ‘2004-01-04’;
    You may need to create an function-basd index, so that the DATE reference in your SQL matches the index:
    http://www.dba-oracle.com/oracle_tips_index_scan_fbi_sql.htm
    To start testing, go into SQL*Plus and "set autotrace on" and run the queries.
    Then confirm that your index is being used.
    Which hint should I use for the query?Hints are a last resort!
    Your query is fully tuned when it fetches the rows you need with a minimum of block touches (logical reads, consistent gets).
    See here for details:
    http://www.dba-oracle.com/art_sql_tune.htm
    Hope this helps . . .
    Donald K. Burleson
    Oracle Press author
    Author of "Oracle Tuning: The Definitive Reference"
    http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

  • AQ tables have DATE columns in 9i and TIMESTAMP in 10g

    Hi,
    I created a queue table on 9i and 10g database's using
    eg:
    dbms_aqadm.create_queue_table(queue_table => 'TEST',
    queue_payload_type => 'RAW',
    multiple_consumers => TRUE,
    compatible => '8.1.3');
    But in 9i
    ENQ_TIME DATE
    and 10g
    ENQ_TIME TIMESTAMP(6)
    Why does date column change to timestamp?
    Thanks
    Reynold.

    My strong suggestion would be to convert all dates to char and then go from there. Doing anything other than that will force Applications to convert the dates (and I can only assume the timestamps). It is the nature of the application/datatype design. Converting everything to a CONSISTANT format, even if that is a varchar goes a long way to removing many unknowns.
    My two cents,
    Scott

  • Update oracle table using data through ODBC

    Hi,
    I want to update tables inside an Oracle 8i database.
    The updates depend on data in a mySql database that I want to approach using an ODBC connection.
    I cannot figure out what I need to do to select data from an ODBC source from an oracle session.
    What do I have to call this external table ...
    Edward

    The following link may be relevant. Check it out.
    http://download-east.oracle.com/docs/cd/A87860_01/doc/server.817/a76960/hs_admin.htm

  • Can you update a table with a column field that has a default value

    I am looking at a developer table(table_one) and basically, he has a column field called is_update and the default for that field is 1,
    I was just wondering whether it would still be possible for me to use an update syntax of the form
    update table_one t
    set t.is_update = 0;
    where t.id = 221;because I have tried doing so and the update isnt working

    Semicolon (;) is the problem!
    update table_one t
    set t.is_update = 0 --Removed semicolon here!.
    where t.id = 221;http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_10008.htm#SQLRF01708
    query & URL added: Saubhik on Oct 21, 2010 7:02 AM

  • How to update existing table using Data Load from spreadsheet option?

    Hi there,
    I need to update an existing table, but in Data Load application when you select csv file to upload it inserts all data by replacing existing one. How can i change this?
    Let me know,
    Thank you.
    A.B.A.

    And how do you expect your database server to access a local file in your machine ?
    Is the file accessible from outside your machine say inside a webserver folder so that some DB process can poll on the file ?
    Or, is your DB server in the same machine where you have the text file ?
    You will have to figure out the file acess part before automating user interaction or even auto-refreshing.

  • Update a table with data from another table

    Hi to All,
    I have in my 'schema' 2 tables:
    CREATE TABLE T_ITEMS
    ITEM_GROUP VARCHAR2(10 BYTE) NOT NULL,
    ITEM_CODE VARCHAR2(25 BYTE) NOT NULL,
    ITEM_DESCRIPTION VARCHAR2(40 BYTE) NOT NULL,
    ITEM_QTA NUMBER(16,4),
    ITEM_PRICE NUMBER(18,5)
    TABLESPACE DOM8DATI
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 2M
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE TABLE T_PRICES
    ITEM_GROUP VARCHAR2(10 BYTE) NOT NULL,
    ITEM_CODE VARCHAR2(25 BYTE) NOT NULL,
    ITEM_PRICE NUMBER(18,5)
    TABLESPACE DOM8DATI
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 2M
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    I need to create a script that for each record in T_ITEMS, read if exist the code (ITEM_GROUP,ITEM_CODE) in T_PRICES and update ITEM_PRICE in T_ITEMS.
    Can anyone help me?
    Thank You and Best Regards
    Gaetano

    MERGE INTO T_ITEMS B USING (
    SELECT
    ITEM_GROUP ,
    ITEM_CODE,
    ITEM_PRICE
    FROM T_PRICES) E
    ON (B.ITEM_CODE= E.ITEM_CODE)
    WHEN MATCHED THEN
    UPDATE SET B.ITEM_PRICE= E.ITEM_PRICE
    WHEN NOT MATCHED THEN
    INSERT (ITEM_GROUP ,
    ITEM_CODE,
    ITEM_DESCRIPTION ,
    ITEM_QTA ,
    ITEM_PRICE )
    VALUES (E.ITEM_GROUP,
    E.ITEM_CODE,
    'UNKNOWN',
    'UNKNOWN',
    E.ITEM_PRICE);
    COMMIT;

  • Updating a table with data from another table with joins involving 3 other

    update party_relship pr
    set pr.COMMENT_TEXT = temp.notes
    from party p,
    party p1,
    party_reference pref,
    TEMP_DEPT_NOTE temp
    where pr.FROM_PARTY_ID = p.PARTY_ID
    and p.CMA_CUSTOMER_NUMBER = temp.cma_num
    and pr.TO_PARTY_ID = p1.PARTY_ID
    and p1.PARTY_ID = pref.PARTY_ID
    and pref.REFERENCE_VALUE = temp.deptnum
    ORA-00933: SQL command not properly ended
    What is the problem here.
    Thanks !

    There are a few issues here 1) no from clause is directly part of the update stmt,
    2) temp.notes is not available directly
    I am not 100% sure this update is correct since I am selecting temp.notes using the same query as the in the where clause but I wanted to show the complete syntax. Basically if you need to limit the number of updates done then change the select that is part of the exists clause, if you need to change the way the pr.comment_text is being set then to need to change the sub_query.
    update party_relship pr
    set pr.comment_text =
                     (select temp.notes
                      from   party p,
                             party p1,
                             party_reference pref,
                             temp_dept_note temp
                      where  pr.from_party_id = p.party_id
                      and    p.cma_customer_number = temp.cma_num
                      and    pr.to_party_id = p1.party_id
                      and    p1.party_id = pref.party_id
                      and    pref.reference_value = temp.deptnum)
    where  exists(select 1
                  from   party p,
                         party p1,
                         party_reference pref,
                         temp_dept_note temp
                  where  pr.from_party_id = p.party_id
                  and    p.cma_customer_number = temp.cma_num
                  and    pr.to_party_id = p1.party_id
                  and    p1.party_id = pref.party_id
                  and    pref.reference_value = temp.deptnum)Message was edited by:
    Bob C

  • How to auto update date column without using trigger

    Hi,
    How to write below MYSQL query in Oracle 10g :
    CREATE TABLE example_timestamp (
    Id number(10) NOT NULL PRIMARY KEY,
    Data VARCHAR(100),
         Date_time TIMESTAMP DEFAULT current_timestamp on update current_timestamp
    I need to auto update the Date_Time column without using trigger when ever i update a record.
    Example shown below is from MYSQL. I want to perform the below steps in ORACLE to auto update Date_Time column.
    mysql> INSERT INTO example_timestamp (data)
    VALUES ('The time of creation is:');
    mysql> SELECT * FROM example_timestamp;
    | id | data | Date_Time |
    | 1 | The time of creation is: | 2012-06-28 12:37:22 |
    mysql> UPDATE example_timestamp
    SET data='The current timestamp is: '
    WHERE id=1;
    mysql> SELECT * FROM example_timestamp;
    | id | data | Date_Time |
    | 1 | The current timestamp is: | 2012-06-28 12:38:55 |
    Regards,
    Yogesh.

    Is there no functionality in oracle to auto update date column without using trigger??
    I dont want to update the date column in UPDATE statement.
    The date column should automatically get updated when ever i execute an Update statement.

  • 3.1EA2 simple table copy including data - gives error

    hi
    3.1EA2 simple table copy including data - results in error-message "Ora-01403 data not found Ora-06512 line 1 ....."
    ..... copy failed
    although the copy did succeed and the table including data was copied.
    regards Karsten

    Hi Brian,
    3.1EA2 shows a little bit improvement on the copy paste from grid.
    However, these are another cases which I found :
    1. This happens everytime
    -invoke any select
    select sysdate
    from dual;
    - leave the cursor position on after semicolon
    - copy and paste the grid result, unto worksheet, so it will become like this
    select sysdate
    from dual;17-NOV-2011 10:42:29
    - now, again copy the grid result using (ctrl + C)
    - the selection on grid suddenly loose its focus (the yellow rectangle is disappear), instead the cursor on SQL worksheet makes selection.
    - therefore the clipboard does not store the grid value
    2. Intermittently, usually happens on the third attempts
    - invoke any select
    - copy and paste any cell into worksheet, press Enter
    - copy and paste different cell into worksheet, press Enter
    - copy and paste another different cel into worksheet, press Enter
    - you'll notice the copy does not copy the correct value
    - the workaround for this problem is to press Ctrl + C several times on the cell before pasting.
    Regards,
    Buntoro

  • Need a pattern to update a table's contents

    The goal here is to update a table's data when new data is imported into my application.
    I was looking thru the Swing trail and see that the TabelModelListener is more appropriate for when the data in the table itself changes -- I cannot find a good trail to base my codes off of.
    more details:
    1. the import is fired off via a button press.
    2. On that button defined a listener, in which I call a service that handles the import.
    3. The import gathers data from a text file and updates a DB.
    It seems to me that after the import, I would want to fire an event, for which the table (or tablemodel) is listening, so it can update itself. I can't find out how to do this. Help is appreciated.

    I think I might be on the correct track.
    1. I am using Factory pattern to serve out gui elements.
    2. In that factory I have created a static Observable object.
    3. I have created a subclass that implements observer. In the update method I can reset the tablemodel. In the factory I create and instance of my table class and register it on the Observable.
    4. After I import some data, i simply call the appropriate method on observable, and my table should do its update.
    I think this solution is pretty clean. If anybody has a better suggestion please let me know. I am always interested in writing the cleanest/most elegant code possible.

  • Cross database join Oracle - SQL server date column - nQSError: 46008

    Hi,
    I am using OBIEE 10.1.3.4.2 and
    I am able to make cross database join between Oracle and SQL server using varchar columns, but I am getting this error:
    nQSError:22024-A comparison is being carried out between noncompatible type when I try to make "foreign key" join between two tables (one from Oracle, second from SQL Server) using number columns (INT, DOUBLE...). It is strange, but I when I make "complex join" on physical layer no error is thrown and everything works fine.
    But I am not able to make join between tables using Date column. Column in Oracle table has DATE datatype, column in SQL server tables has datetimeoffset(7) datatype (example: 2011-07-19 13:14:22.2032605 +02:00). So I tried to cast datetimeoffset(7) to date datatype using "convert(DATE,HappenedOn,120)" - this returns me 2011-07-19 . In this format, BI can show converted date column, I can make filter using this date column, but I am not able to make physical join with Oracle table using this column
    Answer using data from both joined tables gives me this error:
    [nQSError: 46008] Internal error: File .\DataType\SUKeyCompare.cpp, line 875. (HY000)
    Do you have some tips, how to solve this "bug"?

    Parse the command column to get the SSIS package file name may be your only option here.

  • IFNULL Equivalent for Date Columns

    Hello experts,
    is it possible to have an ifunull like function for dates that aren't there in the DB on 10g. For example I get the date format in 00/00/00 and I want it to show 'N/A' instead.
    Best Regards

    Hi zaid,
    Write a case function on the date column f(x) like this,this will work
    case when date='00/00/00' then 'N/A' else date end;
    UPDATE POST
    check your date column data type....if its date or varchar.....change according to your requirment by using it in RPD
    like cast(date as varchar) then at answers end you apply this case function in f(x)
    Hope answers your question.
    Cheers,
    KK
    Edited by: Kranthi on Feb 8, 2011 2:41 AM

Maybe you are looking for

  • Find the place where a object  is stored ?

    hi all, can someone tell me how to find out a object ,e.g : a index , object_id is 1000 then ,how to find where it is placed or which datafile ? thanks you!

  • Empty Photo Folders in Explorer

    Iphone 3gs shows up in explorer but when i go to the DIM folders no pictures apear to transfer, also having same problem on XP system, have tried uninstalling iphone software from device manager but still no luck, any ideas?

  • How to use HR application with Remote Database ?

    Hi, I tested the HR application but it working on local database. How can I create same application which will communicate with Remote Database. Any guideline ? Regards, Ajay Sharma

  • Table Declaration in Smartfoms

    Is it possible to create two table in a single page . if any another alter native is there . i have one table populating data correctly .similar way we need create table with events its goes to short dump. can u suggest me .it's urgent . thanks sures

  • Establish Database connection to connect to OEM Repository from Agents

    I have a requirement to establish Database connection from Agent through Plug-in. Ex: My plug-in metadata will have a perl script which gets executed in each individual agents and it should connect to the OEM Repository database to execute a package.