Inserting date type to Oracle

Questions and answers regarding general SQL and backend databases

Inserting date type to Oracle

Postby jd2p » Tue Jan 03, 2012 3:59 am

Hello everyone!

I'm trying to insert a date value in Oracle to no avail, here's an example of what I do:

* fsDoc is a foundset of table Document. Column dateDoc is type dateTime and is part of the primary key of table Document.
* pDate is a string variable containing a value in format "yyyyMMdd".

Code: Select all
var record = fsDoc.newRecord();
record.idDoc = 6;
record.dateDoc = utils.dateFormat(pDate, "yyyyMMdd");
record.totalvalue =  100.22;
databaseManager.saveData(record);


On saveData I'm getting the following: ORA-01400 Cannot insert null into (myDatabase.Document.dateDoc)

I also tried using string data type with the following:

Code: Select all
utils.dateFormat(utils.dateFormat(pDate, "yyyyMMdd"), "dd/MM/yyyy");

utils.dateFormat(utils.dateFormat(pDate, "yyyyMMdd"), "MM/dd/yyyy");


And get the same error. I also tried not programatically setting a value for dateDoc and setting an Auto Enter system value for the column withing Servoy... but still get the same thing.

First I thought it was an issue of date format and Ive extensively browsed online documentation and the forum looking for something similiar... but now I just don't know. Any thoughts?

Regards,
jd2p
jd2p
 
Posts: 95
Joined: Thu Dec 08, 2011 1:08 am

Re: Inserting date type to Oracle

Postby rgansevles » Tue Jan 03, 2012 11:40 am

jd2p,

I just tried a small test and it worked as expected.

Are you sure the pDate variable is a string and formatted correctly?

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Inserting date type to Oracle

Postby jd2p » Tue Jan 03, 2012 5:50 pm

Hi Rob,

Thanks for the answer. I reviewed the code and found my childish mistake since variable record wasn't referencing the newly created record, I changed:

Code: Select all
var record = fsDoc.newRecord();


to:

Code: Select all
var record = fsDoc.getRecord(fsDoc.newRecord());


that did it.

Regards,
JD
jd2p
 
Posts: 95
Joined: Thu Dec 08, 2011 1:08 am


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 30 guests