ssm 项目mysql 数据库迁移oracle

1.用<!--注释内容 -->在xml文件中,避免出现不必要的错误

2.mysql 用format(n1,2),函数返回类型是字符串,满三位会加一个逗号.在这里保留两位, 会四舍五入

   针对数字类型转换建议使用 convert或者cast函数,用法如下:

      format(param, 2) (不建议)

      convert(param, decimal(12,2))(建议)

      cast(param as decimal(12,2))(建议)

 

oracle 中 使用to_char(number,'FM999,999,999,999,990.99')代替  会四舍五入

3.mysql date_format(变量,‘yyyy-MM-dd’)

  oracle  to_char(变量,‘yyyy-MM-dd’)转换成字符串,一般用于从数据库读取时间时,转换成字符串,

    或者转换成日期类型比较to_date(变量,‘yyyy-MM-dd’),一般用于存储到数据库,将字符串转换成时间类型

4分页

mysql 用limit #{offset},#{limit}

oracle  列子:下面标红的是一个分页模板,不管有没有order by 语句 通用

select * from(
        SELECT ROWNUM AS rowno,r.* FROM (
        select
        id                  ,
        invoice_type      invoiceType,
        invoice_code      invoiceCode,
        invoice_no          invoiceNo,
        invoice_date     invoiceDate,
        gf_name          gfName,
        xf_name          xfName,
        invoice_amount   invoiceAmount,
        tax_amount          taxAmount,
        (select  n.dictname  from t_ac_dictdeta n  where n.dicttype=1569 and n.dictcode=t.qs_status) qsStatus,
        qs_date          qsDate,
        (select  m.dictname  from t_ac_dictdeta m  where m.dicttype=1130 and m.dictcode=t.qs_type) qsType
        from t_dx_record_invoice t
         where 1=1
        AND (SELECT c.current_tax_period FROM t_dx_tax_current c WHERE c.taxno=t.gf_tax_no)>=to_char(invoice_date,'%Y%m')
        and invoice_type IN (1, 3, 14)
        AND gf_tax_no in (SELECT taxno FROM t_ac_org where orgid in(SELECT orgid FROM t_ac_user_taxno where userid=#{map.userId}))
        <if test="map.invoiceNo != null and map.invoiceNo != ''">
            and invoice_no like concat('%',concat(#{map.invoiceNo},'%'))
        </if>
        <if test="map.qsStatus !=null and map.qsStatus != '-1'">
            and qs_status = #{map.qsStatus}
        </if>
        <if test="map.qsType !=null and map.qsType != '-1'">
            and qs_type = #{map.qsType}
        </if>
        <if test="map.qsDate1 != null and map.qsDate1 != ''">
            <![CDATA[ AND to_char(qs_date,'yyyy-MM-dd') >= #{map.qsDate1} ]]>
        </if>
        <if test="map.qsDate2 != null and map.qsDate2 != ''">
            <![CDATA[ AND to_char(qs_date,'yyyy-MM-dd')  <= #{map.qsDate2} ]]>
        </if>
        <if test="map.invoiceType !=null and map.invoiceType != '-1'">
            and invoice_type = #{map.invoiceType}
        </if>
        <if test="map.gfName != null and map.gfName != '-1'and  map.gfName != ''">
            and gf_tax_no = #{map.gfName}
        </if>
        <if test="map.xfName != null and map.xfName != ''">
            and xf_name like concat('%',concat(#{map.xfName},'%'))
        </if>
        <if test="map.invoiceDate1 != null and map.invoiceDate1 != ''">
            <![CDATA[ AND to_char(invoice_date,'yyyy-MM-dd') >= #{map.invoiceDate1} ]]>
        </if>
        <if test="map.invoiceDate2 != null and map.invoiceDate2 != ''">
            <![CDATA[ AND to_char(invoice_date,'yyyy-MM-dd')  <= #{map.invoiceDate2} ]]>
        </if>
        and rzh_yesorno=0
        and invoice_status=0
        and invoice_amount>0
        and CASE WHEN
        <![CDATA[to_char(invoice_date,'yyyy-mm-dd hh24:mi:ss') >= '2017-07-01 00:00:00'
        THEN
        invoice_date+359
        ELSE
        invoice_date+179
        END >= sysdate ]]>
        and tax_amount>=0
        and auth_status in (0,5)
        order by invoice_date desc, id
        ) r
        <if test="map.offset != null and map.limit != null">
            <![CDATA[ where ROWNUM <= ${map.offset}+${map.limit} ]]>
        </if>
        ) table_alias
        <if test="map.offset != null and map.limit != null">
            <![CDATA[  WHERE table_alias.rowno >= #{map.offset} ]]>
        </if>

5: 注意字段是date类型的时间可以直接加减,加减的是天数;

6: mysql 的now()函数在oracle 可以直接使用sysdate 直接赋值;

7:在mysql  和oracle 中通用的模糊查询 :like concat( '%', concat(#{map.name} , '%'))  这样写主要是因为在oracle中concat函数只有两个参数;

8: mysql 的ifnull(expr1 ,expr2)如果 expr1 不是 NULL,IFNULL() 返回 expr1,否则它返回 expr2  

     oracle nvl(expr1 ,expr2)  代替, 效果一样

9:mysql  TRUNCATE(X,Y)       TRUNCATE(x,y)返回数值x保留到小数点后y位的值(与ROUND最大的区别是不会进行四舍五入)

    oracle   truc(X,Y)  代替

 

 

 

 

posted @ 2018-07-26 15:36  花落知到啥  阅读(504)  评论(1编辑  收藏  举报