mysql语句转为oracle语句

为什么80%的码农都做不了架构师?>>>   hot3.png

mysql建表语句转为oracle建表语句


单引号'变双引号"

comment内容去掉

varchar变varchar2

double/int之类的数字变number

PRIMARY KEY  ("kc_no")语句变 CONSTRAINT "kc_no" PRIMARY KEY  ("kc_no")


select jihua_no from zhou.px_kecheng_jihua 

where status<>-1 

and input_date between "0001-01-01" and "9999-12-31" 

order by input_date desc

mysql语句转为oracle语句日期不再是字符串需要to_date

select jihua_no from px_kecheng_jihua 

where status<>-1 

and input_date between to_date('0001-01-01','yyyy-mm-dd') and to_date('9999-12-31','yyyy-mm-dd')

order by input_date desc



用java设置日期

            pStmt.setDate(13,new java.sql.Date(Calendar.getInstance().getTimeInMillis()));

            pStmt.setDate(14,new java.sql.Date(order.getPxDate().getTime()));


驱动程序名称

MySQL-AB JDBC Driver

Oracle JDBC driver

可以通过

conn.getMetaData().getDriverName().contains("MySQL")判断是何数据库

例如:

 if(conn.getMetaData().getDriverName().contains("MySQL")==true)

                sqlStr="select jihua_no from px_kecheng_jihua where status<>-1 and "+column+" like ? and input_date between ? and ? order by input_date desc";

            if(conn.getMetaData().getDriverName().contains("Oracle")==true)

                sqlStr="select jihua_no from px_kecheng_jihua where status<>-1 and "+column+" like ? and input_date between to_date(?,'yyyy-mm-dd') and to_date(?,'yyyy-mm-dd') order by input_date desc";

            


转载于:https://my.oschina.net/0312/blog/393051

你可能感兴趣的:(mysql语句转为oracle语句)