得顺天意 發表於 2023-9-1 00:00:00

MySQL与Oracle数据类型对应关系(表格形式)

<p>&nbsp; &nbsp;
        MySQL与Oracle两种数据库在工作中,都是用的比较多的数据库,由于MySQL与Oracle在数据类型上有部分差异,在我们迁移数据库时,会遇上一定的麻烦,下面介绍MySQL与Oracle数据库数据类型的对应关系。</p><p><strong>一、常见数据类型在MySQL与Oracle数据库中的表现形式</strong></p><p>&nbsp; &nbsp;
        &nbsp;</p><table border="1" cellpadding="0" cellspacing="0"><tbody><tr class="firstRow"><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        说明</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        mysql</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        变长字符串</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        VARCHAR</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        定义长度默认按字符长度计算,如果是GBK编码的汉字将占用2个字节</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        VARCHAR2<br/>
                                        VARCHAR是VARCHAR2的同义词</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        定义默认按字节长度计算</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        整数</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        TINYINT(-128-127)</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        SMALLINT(-32768-32767)</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        MEDIUMINT(-8388608-8388607)</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        INT(-2147483648-2147483647)<br/>
                                        BIGINT(-9223372036854775808-9223372036854775807)&nbsp;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        无专用类型,</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        TINYINT可以用NUMBER(3,0)代替</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        SMALLINT可以用NUMBER(5,0)代替</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        MEDUIMINT可以用NUMBER(7,0)代替<br/>
                                        &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        INT可以用NUMBER(10,0)代替<br/>
                                        &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        BIGINT可以用NUMBER(20,0)代替</p><p><br/>
                                        &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        ORACLE中有SMALLINT,INT,INTEGER类型,不过这是NUMBER(38,0)的同义词</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        数值类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        DECIMAL]<br/>
                                        NUMERIC是DECIMAL的同义词</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        NUMBER&nbsp;可表示数范围:&nbsp;1*10^-130至1*10^126</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        NUMBER([,-84-127])</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        DECIMAL、NUMERIC、DEC是NUMBER的同义词</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        浮点型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        FLOAT(D,M)</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle10g开始增加BINARY_FLOAT类型</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        10g以前无专用类型,可以用NUMBER代替</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        ORACLE中有FLOAT和REAL类型,不过这是NUMBER的同义词</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        双精度浮点型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        DOUBLE(D,M)</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle10g开始增加BINARY_DOUBLE类型</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        10g以前无专用类型,可以用NUMBER代替</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        ORACLE中有DOUBLE PRECISION类型,不过这是NUMBER的同义词</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        位类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        BIT(1-64)</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        无</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        日期类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        DATE,3字节存储,只存储日期,没有时间,支持范围是至<br/>
                                        TIME,3字节存储,只存储时间,没有日期,支持范围是[-838:59:59]至<br/>
                                        DATETIME,占8字节存储,可表示日期和时间,支持范围是至<br/>
                                        TIMESTAMP,占4字节存储,可表示日期和时间,范围是至</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        DATE类型<br/>
                                        7字节存储,可表示日期和时间,支持范围是[-4712-01-01 00:00:00]至</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        高精度日期</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        5.6.4以前不支持小数秒精度<br/>
                                        5.6.4开始TIME,DATETIME,TIMESTAMP支持,最多可以6位小数秒,也就是微秒级别</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        TIMESTAMP<br/>
                                        占用空间7-11个字节,当小数秒精度为0时与DATE类型相同,小数秒最高精度可达9位,也就是纳精度</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        年份</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        YEAR,1字节存储,只存储年份,支持范围是至</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        无对应类型,可以用NUMBER(3,0)代替</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        定长字符串</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        CHAR,定义长度默认按字符长度计算,最大保存255字符</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        CHAR</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        定义默认按字节长度计算</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        无符号说明</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持,用于数值类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        大字符串,一般用于存储文本文件或超大描述及备注类信息</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        TINYTEXT&nbsp;最大支持255个字节<br/>
                                        TEXT最大支持65535个字节<br/>
                                        MEDIUMTEXT最大支持16MB个字节<br/>
                                        LONGTEXT最大支持4GB字节<br/><br/>
                                        字段不支持默认值</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持(CLOB)<br/>
                                        oracle10g以前最大支持4GB个字节</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle10g开始最大支持4GB个数据块,数据块大小为2KB-32KB</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle还有一个LONG类型,是早期的存储大字符串类型,最大支持2GB字节,现已不推荐使用</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        二进制对象,一般用于存储文件或图片数据</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        TINYBLOB&nbsp;最大支持255个字节<br/>
                                        BLOB最大支持65535个字节<br/>
                                        MEDIUMBLOB最大支持16MB个字节</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        LONGBLOB最大支持4GB字节</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        字段不支持默认值</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持(BLOB)</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle10g以前最大支持4GB个字节<br/>
                                        &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle10g开始最大支持4G个数据块,数据块大小为2KB-32KB</p><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        oracle还有一个LONG RAW类型,是早期的存储二进制类型,最大支持2GB字节,现已不推荐使用</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        二进制信息</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        BINARY(0-255),定长<br/>
                                        VARBINARY(0-65535),变长</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        RAW(1-2000)</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        枚举类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        ENUM(v1,v2,v3,...),最多65535个元素</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        集合类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        SET(v1,v2,v3,...),最多64个元素</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        国际化字符集类型,较少使用</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        无,MYSQL可以对每个字段指定字符编码</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持<br/>
                                        NCHAR(1-2000)<br/>
                                        NVARCHAR(1-4000)<br/>
                                        NCLOB</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        外部文件指针类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持<br/>
                                        文件大小最大4GB<br/>
                                        文件名称最长255字符</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        自动增长类型</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持<br/>
                                        使用简单</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持<br/>
                                        一般使用SEQUENCE解决,用法与自增类型差别较大,使用较复杂,但能实现非常灵活的应用,包括字符自增主键、全局主键等等</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持函数和表达式<br/>
                                        TEXT和BLOB字段类型不支持默认值</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持函数和表达式</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        支持,例如,把emp表的id字段顺序放在name字段后面:<br/>
                                        alter table emp modify column id varchar(20) after name;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持,只能重建表或字段</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        虚拟字段是一个逻辑字段定义,其结果值通常是一个表达式,并在表中存储物理值,不占用空间,主要用于简化查询逻辑。比如有一个商品销售表有单价和数量两个字段,那可以建一个虚拟字段金额,其表达式=单价*数量</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        不支持</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        11g支持,例:<br/>
                                        create table sales<br/>
                                        (<br/>
                                        &nbsp; id number,<br/>
                                        &nbsp; quantity number,<br/>
                                        &nbsp; price&nbsp; number,<br/>
                                        &nbsp; amount GENERATED always as (quantity*price) virtual<br/>
                                        );</p></td></tr><tr><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        &nbsp;</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        INNODB&nbsp;最大1000个字段<br/>
                                        所有字段总定义长度不能超过65535字节<br/>
                                        所有固定长度字段的总长度不超过半个数据块大小(数据块大小一般为16K)</p></td><td><p>&nbsp; &nbsp; &nbsp; &nbsp;
                                        最大1000个字段</p></td></tr></tbody></table><p>&nbsp; &nbsp;
        &nbsp;</p><p><strong>二、MySQL与Oracle数据库常见数据类型对应关系</strong></p><p>&nbsp; &nbsp;
        &nbsp;</p><table border="1" cellpadding="0" cellspacing="0"><tbody><tr class="firstRow"><td>编号</td><td>ORACLE</td><td>MYSQL</td><td>注释</td></tr><tr><td>1</td><td>NUMBER</td><td>int / DECIMAL</td><td>DECIMAL就是NUMBER(10,2)这样的结构INT就是是NUMBER(10),表示整型;<br/>
                                MYSQL有很多类int型,tinyint mediumint bigint等,不同的int宽度不一样</td></tr><tr><td>2</td><td>Varchar2(n)</td><td>varchar(n)</td><td> </td></tr><tr><td>3</td><td>Date</td><td>DATATIME</td><td>日期字段的处理<br/>
                                MYSQL日期字段分DATE和TIME两种,ORACLE日期字段只有DATE,包含年月日时分秒信息,用当前数据库的系统时间为&nbsp;SYSDATE,&nbsp;精确到秒,或者用字符串转换成日期型函数TO_DATE(‘2001-08-01&#39;,&#39;YYYY-MM-DD&#39;)年-月-日&nbsp;24小时:分钟:秒的格式YYYY-MM-DD HH24:MI:SS TO_DATE()还有很多种日期格式,&nbsp;可以参看ORACLE DOC.日期型字段转换成字符串函数TO_CHAR(‘2001-08-01&#39;,&#39;YYYY-MM-DD HH24:MI:SS&#39;)<br/><br/>
                                日期字段的数学运算公式有很大的不同。MYSQL找到离当前时间7天用&nbsp;DATE_FIELD_NAME&nbsp;>&nbsp;SUBDATE(NOW(),INTERVAL 7 DAY)ORACLE找到离当前时间7天用&nbsp;DATE_FIELD_NAME&nbsp;>SYSDATE - 7;<br/><br/>
                                MYSQL中插入当前时间的几个函数是:NOW()函数以`&#39;YYYY-MM-DD HH:MM:SS&#39;返回当前的日期时间,可以直接存到DATETIME字段中。CURDATE()以&#39;YYYY-MM-DD&#39;的格式返回今天的日期,可以直接存到DATE字段中。CURTIME()以&#39;HH:MM:SS&#39;的格式返回当前的时间,可以直接存到TIME字段中。例:insert into tablename (fieldname) values (now())<br/><br/>
                                而oracle中当前时间是sysdate</td></tr><tr><td>4</td><td>INTEGER</td><td>int / INTEGER</td><td>Mysql中INTEGER等价于int</td></tr><tr><td>5</td><td>EXCEPTION</td><td>SQLEXCEPTION&nbsp;</td><td>详见&lt;&lt;2009001-eservice-o2mg.doc&gt;&gt;中2.5 Mysql异常处理<!--2009001-eservice-o2mg.doc--></td></tr><tr><td>6</td><td>CONSTANT VARCHAR2(1)</td><td>mysql中没有CONSTANT关键字</td><td>从ORACLE迁移到MYSQL,所有CONSTANT常量只能定义成变量</td></tr><tr><td>7</td><td>TYPE g_grp_cur IS REF CURSOR;</td><td>光标 : mysql中有替代方案</td><td>详见&lt;&lt;2009001-eservice-o2mg.doc&gt;&gt;中2.2 光标处理<!--2009001-eservice-o2mg.doc--></td></tr><tr><td>8</td><td>TYPE unpacklist_type IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;</td><td>数组: mysql中借助临时表处理<br/>
                                或者直接写逻辑到相应的代码中,<br/>
                                直接对集合中每个值进行相应的处理</td><td>详见&lt;&lt;2009001-eservice-o2mg.doc&gt;&gt;中2.4 数组处理<!--2009001-eservice-o2mg.doc--></td></tr><tr><td>9</td><td>自动增长的序列</td><td>自动增长的数据类型</td><td>MYSQL有自动增长的数据类型,插入记录时不用操作此字段,会自动获得数据值。ORACLE没有自动增长的数据类型,需要建立一个自动增长的序列号,插入记录时要把序列号的下一个值赋于此字段。</td></tr><tr><td>10</td><td>NULL</td><td>NULL</td><td>空字符的处理<br/>
                                MYSQL的非空字段也有空的内容,ORACLE里定义了非空字段就不容许有空的内容。按MYSQL的NOT NULL来定义ORACLE表结构,&nbsp;导数据的时候会产生错误。因此导数据时要对空字符进行判断,如果为NULL或空字符,需要把它改成一个空格的字符串。</td></tr></tbody></table><p>&nbsp; &nbsp;
        &nbsp;</p><p><strong>MySQL与Oracle 差异比较之基本语法</strong></p><p>&nbsp; &nbsp;
        &nbsp;</p><table border="1" cellpadding="0" cellspacing="0"><tbody><tr class="firstRow"><td>编号</td><td>类别</td><td>ORACLE</td><td>MYSQL</td><td>注释</td></tr><tr><td>1</td><td>变量的声明方式不同</td><td>li_index NUMBER := 0</td><td>DECLARE&nbsp;li_index INTEGER DEFAULT 0</td><td>1. mysql 使用DECLARE定义局部变量.&nbsp;<br/>
                               定义变量语法为:&nbsp; DECLARE var_name[,...] type 要给变量提供一个默认值,需要包含一个DEFAULT子句。值可以被指定为一个表达式,不需要为一个常数。如果没有DEFAULT子句,初始值为NULL。&nbsp;</td></tr><tr><td>2</td><td>变量的赋值方式不同</td><td>lv_inputstr&nbsp;:=&nbsp;iv_inputstr</td><td>SET&nbsp;lv_inputstr&nbsp;=&nbsp;iv_inputstr</td><td>1. oracle变量赋值使用:=<br/>
                               mysql 使用赋值使用set关键字. 将一个值赋给一个变量时使用&quot;=&quot;.&nbsp;</td></tr><tr><td rowspan="2">3</td><td rowspan="2">跳出(退出)语句不同</td><td>EXIT;</td><td>LEAVE procedure name;</td><td rowspan="2">1. oracle: 如果exit语句在循环中就退出当前循环.如果exit语句不再循环中,就退出当前过程或方法.&nbsp;<br/>
                               Mysql: 如果leave语句后面跟的是存储过程名,则退出当前存储过程. 如果leave语句后面跟的是lable名. 则退出当前lable.&nbsp;<br/>
                                &nbsp;</td></tr><tr><td>while&nbsp;条件&nbsp;loop<br/>
                                exit;<br/>
                                end loop;</td><td>label_name:while&nbsp;条件&nbsp;do<br/>
                                &nbsp; leave label_name;<br/>
                                end while label_name;</td></tr><tr><td>4</td><td>定义游标</td><td>TYPE g_grp_cur IS&nbsp;REF CURSOR;<br/>
                                &nbsp;</td><td>DECLARE cursor_name CURSOR FOR&nbsp;SELECT_statement;</td><td>oracle可以先定义游标,然后给游标赋值.&nbsp;<br/>
                                mysql定义游标时就需要给游标赋值. Mysql定义游标出自 Mysql 5.1 参考手册20.2.11.1.声明光标.</td></tr><tr><td>5</td><td>定义数组</td><td>TYPE unpacklist_type IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;</td><td>可以使用临时表代替oracle数组,&nbsp;也可以循环拆分字符来替代oracle数组.</td><td>目前可以使用临时表来代替oracle数组.&nbsp;<br/>
                                详见&lt;&lt;2009002-otmpps-difficult questions-0001.doc=&quot;&quot;&gt;&gt;中2.4 Mysql数组处理部分<!--2009002-otmpps-difficult--></td></tr><tr><td>6</td><td>注释方式不同</td><td>&nbsp;&quot;-- message&quot;或&nbsp;&quot;/** ….&nbsp; */&quot;&nbsp;或&quot;/* ….&nbsp; */&quot;</td><td>&quot;-- message&quot;或&nbsp;&quot;/* ….&nbsp; */&quot;&nbsp;或&nbsp;&quot;#&quot;</td><td>mysql注释来自&nbsp; MySQL 5.1参考手册 9.5. 注释语法, 建议同oracle一样, 单行用--, 多行/* */</td></tr><tr><td>7</td><td>自带日期时间函数格式不同</td><td>Oracle时间格式:yyyy-MM-dd hh:mi:ss</td><td>Mysql时间格式:%Y-%m-%d %H:%i:%s</td><td>1. MYSQL日期字段分DATE和TIME两种.&nbsp;<br/>
                               ORACLE日期字段只有DATE,包含年月日时分秒信息.&nbsp;<br/>
                                2. mysql中取当前系统时间为now()函数,精确到秒.&nbsp;<br/>
                               oracle中取当前数据库的系统时间为SYSDATE, 精确到秒.</td></tr><tr><td>8</td><td>日期加减</td><td>当前时间加N天: sysdate+N<br/>
                                当前时间减N天: sysdate-N</td><td>日期相加: date_add(now(), INTERVAL 180 DAY)<br/>
                                日期相减: date_sub(&#39;1998-01-01 00:00:00&#39;, interval &#39;1 1:1:1&#39; day_second)</td><td> </td></tr><tr><td>9</td><td>字符串连接符不同</td><td>result&nbsp; := v_int1||v_int2;</td><td>set result =concat(v_int1,v_int2);</td><td><br/>
                                1. oracle使用||连接字符串,也可以使用concat函数. 但Oracle的concat函数只能连接两个字符串.<br/>
                                &nbsp;Mysql使用concat方法连接字符串. MySQL的concat函数可以连接一个或者多个字符串,如<br/>
                               mysql&gt; select concat(&#39;10&#39;); 结果为: 10.<br/>
                               mysql&gt; select concat(&#39;11&#39;,&#39;22&#39;,&#39;33&#39;,&#39;aa&#39;); 结果为: 112233aa<br/>
                                2. &quot;||&quot;在Mysql是与运算</td></tr><tr><td>10</td><td>定义游标不同</td><td>CURSOR l_bk_cur IS<br/>
                               SELECT B.BK_HDR_INT_KEY, B.BK_NUM<br/>
                               FROM ES_SR_DTL_VRB A, ES_BK_HDR B<br/>
                               WHERE A.BK_HDR_INT_KEY = B.BK_HDR_INT_KEY<br/>
                               AND b.BK_STATUS != ES_BK_PKG.g_status_can<br/>
                               AND A.SR_HDR_INT_KEY = ii_sr_hdr_int_key;</td><td>DECLARE l_bk_cur CURSOR<br/>
                                &nbsp; FOR&nbsp;SELECT B.BK_HDR_INT_KEY, B.BK_NUM<br/>
                               FROM ES_SR_DTL_VRB A, ES_BK_HDR B<br/>
                               WHERE A.BK_HDR_INT_KEY = B.BK_HDR_INT_KEY<br/>
                               AND b.BK_STATUS != ES_BK_PKG.g_status_can<br/>
                               AND A.SR_HDR_INT_KEY = ii_sr_hdr_int_key;</td><td>详见&lt;&lt;2009002-otmpps-difficult questions-0001.doc=&quot;&quot;&gt;&gt;中2.2 Mysql游标处理部分<!--2009002-otmpps-difficult--></td></tr><tr><td>11</td><td>事务回滚</td><td>ROLLBACK;</td><td>ROLLBACK;</td><td>oracle和mysql中使用方法相同</td></tr><tr><td>12</td><td>GOTO语句</td><td>GOTO check_date;</td><td>GOTO check_date;</td><td>oracle和mysql中使用方法相同</td></tr></tbody></table><p>&nbsp; &nbsp;
        &nbsp;</p><p>&nbsp; &nbsp;
        以上就是MySQL与Oracle数据类型对应关系的全部内容了</p>
頁: [1]
查看完整版本: MySQL与Oracle数据类型对应关系(表格形式)