[DB-SIG] Oracle to Mysql (dates) Help please
Lloyd Kvam
pythontutor at venix.com
Mon Jan 12 09:41:55 EST 2004
To pass the date as a string, use 'yyyy-mm-dd'. Today would be:
'2004-01-12'
If you actually need date and time, the string format is:
'yyyy-mm-dd hh:mm:ss'
arjen.dijkstra at hccnet.nl wrote:
> Hi all,
>
>
>
> I'm posting to this sig for the first time, i hope I'm doing this right.
>
>
>
>
>
> I'm trying to export a view tables from a Oracle database to a Mysql
>
> database. I create insert statements (they look alright), but it all goes
>
> wrong when I try to execute them in Mysql, because the dates must have
>
> quotes on each side.
>
> I just don't know how make the dates right.
>
> Well I'll just show you the code and some insert statements it generates.
>
> Could anyone please help me?
>
>
>
> Thanks,
>
>
>
> Arjen
>
>
>
> ####Code####
>
>
>
> import cx_Oracle
>
> tabellen=["machine"]
>
> con_oracle=cx_Oracle.connect("bla/bla")
>
> c_oracle=con_oracle.cursor()
>
>
>
> import MySQLdb
>
> my=MySQLdb.Connect("localhost", db="bla")
>
> my_mysql=my.cursor()
>
> for tabel in tabellen:
>
> print tabel
>
> c_oracle.execute("select * from %s" % tabel)
>
> a_oracle=c_oracle.fetchone()
>
> #file=open("%s.sql" % tabel, 'w')
>
> while a_oracle != None:
>
> b=str(a_oracle)
>
> ins="insert into %s values %s;\n" % (tabel, b)
>
> #file.write(ins)
>
> my_mysql.execute(ins)
>
> #print ins
>
>
>
> a_oracle=c_oracle.fetchone()
>
> file.close()
>
>
>
> con_oracle.close()
>
>
>
> my.close()
>
>
>
>
>
> ##insert statement###
>
>
>
> insert into machine values ('230KM', ' ', '230KM', 1980-01-01 00:00:00,
>
> 2035-01-01 00:00:00, 1, 100, 'asap', 'NO', 0, 0, 'corrugator', 2003-12-04
>
> 06:00:00, 1970-01-01 01:00:00, ' ', 'normal', 0.0, 0.0, 7, ' ', ' ',
>
> 'normal', ' ', ' ', 'A', 2003-12-04 09:42:14, 82766);
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> DB-SIG maillist - DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 801-459-9582
More information about the DB-SIG
mailing list