一.数据库本身
mysql为中小型数据库,比起oracle更加方便,一般不做商用。oracle数据库一般用于偏大型项目,具有良好的兼容性、可移植性、可连接性和高生产率,oracle是不开源的,一般稍大型公司都有自己优化过的oracle。
二.连接方面(jdbc连接方法)
oracle:
driverClassName=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:服务器地址(localhost时前面加@):端口号:数据库名
mysql:
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://服务器地址(localhost时前面加@):端口号/数据库名
三.数据类型
自增长类型:mysql有,通过增加auto_increment实现字段自增长;oracle没有,通过序列sequence实现自增长
时间类型:mysql(date,time,datetime,timestamp,year等,每个类型时间格式不一样),oracle(date),长度自动设置
int类型:mysql(表示整数可以自定义长度),oracle(一般使用number,使用int时数据库会自动保存为number,我的oracle版本是11.2.0.1.0)
字符类型:oracle有char,nchar,varchar,varchar(char 定长字符,不能手动指定字符或者字节,nchar 定长字符,可以手动指定字符或者字节,varchar2 变长字符,varchar 目前跟varchar2功能一样,估计后期会赋予新功能 ),mysql有char,varchar(cha, 固定长度,varchar 可变长度)
其他类型:mysql有枚举类型enum和集合类型set以及json数据类型,oracle没有
四.sql语句
分页查询:
mysql select * from a limit a,b(从a+1开始,查询a表中的b条数据)
oracle select aa.* from (select rownum r,a.* from a) aa where r between c and d(查询a表中的c-d的数据)
日期转换:
mysql 一般使用dateformat()函数
oracle 一般使用to_date()
删除语句(*)
mysql delete from a where ...
oracle delete a where ...
UUID的生成
mysql 直接用select uuid()函数可以生成uuid
oracle 一般需要运行语句
CREATE OR REPLACE
FUNCTION get_uuid
RETURN VARCHAR
IS
guid VARCHAR (50);
BEGIN
guid := lower(RAWTOHEX(sys_guid()));
RETURN
substr(guid,1,8)||'-'||substr(guid,9,4)||'-'||substr(guid,13,4)||'-'||substr(guid,17,4)||'-'||substr(guid,21,12);
END get_uuid;
之后使用select get_uuid from dual生成uuid
创建数据库
oracle create tablespace tbs datafile '路径' size 文件大小 ...
mysql create database [数据库名称] default character set utf8 collate utf8_general_ci;
创建用户
oracle create user usera identified by 密码
mysql CREATE USER 'fzj@localhost' IDENTIFIED BY '123456'
查询所有表名
oracle select table_name from user_tables
mysql select table_name from information_schema.tables where table_schema='dbname'
后续待补...