Compatibility Query for inserting null values in datefield - mysql

I'm using Oracle and MySQL database in our project. So we are trying to write common queries for both databases.
I'm trying to insert a date in a date field into both database tables. Both databases support this date format only: 2013-07-19. In the course of our DML operations we are facing a problem when inserting dates as Empty or Null.
Both databases have their own syntax to store an "empty field" in a Date field/column.
MySQL allows dates as 0000-00-00 or NULL (specifically written at an appropriate position). But Oracle does not support this format. Oracle only allows date fields as Empty.
How to write common queries in this type of situation?

INSERT INTO TABLENAME(DATEFIELD) VALUES(NULL);
...works both in MySQL and Oracle, so you could use that.

Related

Convert select statement using trunc() and sysdate from Oracle SQL to MySQL

This below Oracle query returns dates between last day of previous month till today. I need same results in MySQL. Can anybody help me to write the query in MySQL?
Please note that I have drive this query on 'DUAL'. There is no physical/actual table.
SELECT TRUNC(TRUNC(TRUNC(sysdate,'MM')-1)+level)-1 attendance_date
FROM dual
CONNECT BY level<= (TRUNC(sysdate)-TRUNC(sysdate,'mm'))+2;
MySQL simply doesn't have the nonstandard Oracle CONNECT BY feature. It doesn't yet have the standard recursive common table expression feature. Your present approach to your problem isn't the right one to get a sequence of dates.
There are other ways to to get a sequence of dates.
MySQL how to fill missing dates in range?
http://www.plumislandmedia.net/mysql/filling-missing-data-sequences-cardinal-integers/

Displays the date in MySQL Workbench

How to change the display of dates in MySQL Workbench
Recorded as 16-01-2014 now
But is necessary to do so: 16-01-2014
You'll need to change your SELECT statements to get your dates rendered differently.
Change
SELECT datestamp
to
SELECT DATE_FORMAT(datestamp,'%d-%m-%Y')
MySQL Workbench is a client program that accesses MySQL database servers. You use the workbench to write queries to send to a MySQL server to get back data.
If you want your dates presented in a particular way, that's part of the queries you write. If you use the queries built in to the workbench, you can't change the date format it displays.
Don't give in to the temptation to change the data type of your date and time columns in your table to VARCHAR(), and then fill them with values in the format you prefer. If you do that, you'll lose the ability to search your table on date ranges.

How to update incorrect dates across multiple tables in a MySQL database

I have a MySQL database with 1700+ tables that we received from a vendor. The problem is that many of the dates in the tables are in an incorrect format. What I want to do is come up with a script that will check all fields of type date, datetime, and timestamp and updating any fields that don't have a valid value. Is such a thing possible?
Edit:Just for clarification, I'd like an script that would trawl a database and swap any dates less than 1900-01-01 with 1900-01-01.

Using a 'date' data type in SQL Server Management Studio 2008

I have a database with existing data that uses the datetime field which is a timestamp that uses date and time.
I want to just store the date, not the time, as the time is never used anyway but due to the way the app works it is causing inconsistencies when reporting on the data.
I believe there is a 'date' data type using the Design view on my table but when I tried to use that it said invalid data type. I also can't do this using the ALTER TABLE syntax in SQL.
Because it's live data, I don't want to make too many changes that might cause problems. We have a demo system that I can play around with though.
SQL server 2008 has a date datatype, which only stores date
the easiest way to do is to alter the table like this:
alter table your_table alter column <dt_col> date
Since you cannot alter the table , I think the only way left is convert while selecting
select convert(date,<dt_col>) from your_table
Or you can create a view with this select statement and use that view in all your queries
SQL fiddle demo

Problem with Date field after migration from mysql to oracle

I have lately migrate my JIRA database from mysql to oracle,
my problem is the field "created" exists in the jiraissue and changegroup tables,on this field I effectuate many calculation but I was surprised by the difference of the format of the fields.
in mysql database the field creation has the type timeStamp so it has the follwing format:
and in Oracle database it has the type date and the format like the following:
How can I resolve this problem?
The format of your displayed Oracle DATE column is due to your IDE that you are viewing it through.
Oracle stores all portions of a date, to display the full date stored use this:
SELECT TO_CHAR(created, 'DD-MON-YYYY HH24:MI:SS')
FROM jiraissue;
This will show you the full date that has been stored including the time portion. To store timestamps you need the column to be designated as a timestamp datatype column.
Ollie.
EDIT: You could change the NLS Date Format of your IDE to always show the full date format in it's settings somewhere.
Dates are not held as formatted text in Oracle. What you are seeing is a tool's (Toad's?) default formatting of the date to display it to you. This can be changed via a preference somewhere. It could be that the time component has been lost in migration, but that is unlikely. Try running this SQL to see:
select to_char (created, 'YYYY-MM-DD HH24:MI:SS') from jiraissue;
That should show the dates just as they appeared in MySQL.