ODP.Net OracleBulkCopy 'not a valid month' with a date field - oracle

First it is important to note that this error is occuring while importing a set of data using the OracleBulkCopy object in a WPF application with the data stored in a DataTable object.
In this table there is one column which is of type "Date" (oracle) and the corresponding type is DateTime? (nullable) in the WPF application. However when setting up the DataTable for the OracleBulkCopy object I'm setting the data type of that column to DateTime (non-nullable) as nullable types are not permitted in the DataTable's DataColumn objects.
What is happeneing is that the data import works fine when all date values are null but as soon as I try an import with any actual dates I'm getting the error "Not a valid month" from the Oracle server. Normally when something like this happens you can use "to_date" to specify how the date is supposed to be interpreted.
Using OracleBulkCopy this is not possible and should also not be necessary as the dates aren't strings but actual DateTime objects.
I have also tried using the data type Oracle.DataAccess.Types.OracleDate but this had the same result.
I have not been able to find any solution to this so any help would be appreciated.

Related

Type mismatch when using DateValue() with a datetime2

Please see the simple code below:
DateValue(rs(0))
rs is a recordset and rs(0) is sometimes a datetime and sometimes a datetime2 from an SQL database depending on which database the app is connected to at the time. If a datetime2 is passed to DateValue then I see a type mismatch error. I could resolve the issue by ensuring that a datetime2 is always casted to a datetime in SQL like this: select cast (created as datetime) from employee. However, I wandered if there was some way of getting round this in the VB6 code.

Import CSV File into Oracle using SQL Developer

I am trying to import data from a CSV file into a Oracle GroupSpace table using SQL Developer tool. I am getting errors for Date column. My Date column has Date in the below format.
5/6/2016
4/11/2018
11/6/2017...
I get error that the date column has Invalid or Null Date Formats.
Any pointers on what format date format to use when importing Date column would be greatly appreciated.
Thank you so much!
JH
If you aren't sure that dates are valid (for example, nothing prevents you from entering 5/55/2016 into a CSV file, and that certainly isn't a valid DATE value), you can create a staging table whose columns are of VARCHAR2 datatype - it accepts everything, even garbage like 5/55/2016.
Then, after you load data, write some SQL to find errors, fix them, and then move data into the target table.
Check the CSV data in a text editor and look for which part represents the month (the month value will be in the range 1..12). If you are using US dates then use MM/DD/YYYY, otherwise you should probably use DD/MM/YYYY as the date format. If the data has a mixture of both, then you must separate those files and use a different format for each, or you are likely to get invalid date values in your database.
SQL Developer can help you.
You can try the date format masks in the drop-down. If we can guess it, we'll default to one. For some reason your data...fools us, but you can type your own.
If you get something that 'works' the warnings go away.
If you get it wrong, we'll let you know before you even get to the next step.
You can find all the data format masks here.

I can't add a data date value to firebird when the day portion is greater than 12

I have an odd problem about VB6.0 programming when I add a value to database firebird from DtPicker or Calendar. When I add a date where the day is 1 to 12 it can add it into the database, but when I try to add a date where the day is the 13th or above it shows error message
Run-time error '-2147467259'(80004005)':
[ODBC Firebird Driver][Firebird]conversion error from string "13/08/2017"
The type in database is "DATE", but when I turn the type in database into "VARCHAR" everything is fine, but "VARCHAR" cannot do the function Date.
If you pass date value as a string or in context of a concatenated statement, make sure you set the value in 'YYYY-MM-DD' format (ISO_8601).
If you have prepared statements with parameters, then driver itself will handle safely data type conversions automagically. At least it should.
Last option is recommended.

VB.NET OLEDBDataReader - Null value in resultset (DATETIME)

I'm new to VB.NET programming, so pointing to examples is greatly appreciated.
I've got a OleDB connection to an Oracle 11g database. I'm reading a single row from a table and trying to populate a row object (mClockInOutInfo). The problem I'm running into is that there is a null DateTime (timestamp) column in the returned row.
Of course, I started with the mClockInOutInfo.RowDate = dr.GetDateTime(0) (assume the RowDate column is the first column in the query).
I quickly found out that nulls should be checked, so I added the = If(IsDBNull(dr.GetDateTime(0)), DBNull.value, dr.getDateTime(0)) to the code. (I now use the NullSafeString functions found around here somewhere. But there was nothing for DateTime types. I tried to make one, no success. So I'm still with the If(IsDbNull(...)) code for my datetime columns.
The problem I'm having is that I get the error: "Specified cast is not valid." when evaluating that statement. I've verified the column type with the .GetDataTypeName(0) method. It returns DBTYPE_DBTIMESTAMP. I've reviewed the schema information to verify that the column is actually the information I'm looking for. From what I can tell, the error is being generated while evaluating the IsDBNull(drRecent.GetDateTime(0)) portion of the if() statement. I've confirmed this by breaking the statement into a multi-line if statement:
if IsDBNull(dr.GetDateTime(0)) Then
...
Else
...
End If
I get the same cast error thrown by the if IsDBNull(...) line.
So, I went back to the SQL string and did a Coalesce on the column with the empty data in it. I received the same cast error. Finally, frustrated, I changed the sql query to use the TO_DATE function and fed in a date string with the appropriate format parameter. I STILL receive this same cast error.
The property in the mClockInOutInfo is defined as DateTime. There are other columns defined exactly the same way and those that have data in the table are not giving any errors.
Any ideas of what I should be doing when the database allows nulls in a DateTime (Timestamp) column? All ideas welcomed. Thank you in advance.

comparing timestamp and date in Derby

I need to compare a date and a timestamp in a SELECT query. Normally, this is supported by most other DB platforms(MySQL, MSSQL, Oracle, etc.) but in Derby it throws this error:
Caused by: java.sql.SQLSyntaxErrorException: Comparisons between
'DATE' and 'TIMESTAMP' are not supported. Types must be comparable.
String types must also have matching collation. If collation does not
match, a possible solution is to cast operands to force them to the
default collation (e.g. SELECT tablename FROM sys.systables WHERE
CAST(tablename AS VARCHAR(128)) = 'T1')
I don't want to use CASTs because I cannot change the SQL query. Is this a bug from Derby that will get fixed sometime? I'm currently using Derby 10.8.2.2.
Thanks!
If you are connecting from a java program you can get specific parts of a Timestamp using various getxxx() methods (these are actually inherited from Java.util.date)
See the docs http://docs.oracle.com/javase/7/docs/api/java/util/Date.html
and check the getDate(), getDay() getHour().... methods
Perhaps you can define a VIEW on one of the tables, and include the CAST in the VIEW. That way, you don't have to change the actual query; it will go against the view, and thus include the cast in that way.

Resources