zoukankan      html  css  js  c++  java
  • Oracl使用总结二

    1、ORA-00972: 标识符过长 错误排除 可能原因:

    1、如果是拼接成的sql语句,请查找传递参数时字符型字段是否两边少了引号。
    2、数据库表名太长了,附各种类型的数据库表名长度:
      SQLSERVER 128个字符,临时表116个字符。
      Oracle 30个字符。
      MySQL 64个字符。
      Access 64个字符。
      DB2 128个字符。

    2、The content of elements must consist of well-formed character data or markup解决方法: 

    XML 元素必须遵循以下命名规则:  
    1、名称可以含字母、数字以及其他的字符 
    2、名称不能以数字或者标点符号开始  
    3、名称不能以字符 “xml”(或者 XML、Xml)开始  
    4、名称不能包含空格
    5、有可能末尾多了一个; 

    3、oracle 主键自增 办法: 

    1、通过序列方式:
    将表t_uaer的字段ID设置为自增:(用序列sequence的方法来实现)
    ----创建表 Create table t_user( Id number(6), userid varchar2(20), loginpassword varchar2(20), isdisable number(6) ); ----创建序列 create sequence user_seq increment by 1 start with 1 nomaxvalue nominvalue nocache ----创建触发器 create or replace trigger tr_user before insert on t_user for each row begin select user_seq.nextval into :new.id from dual; end; ----测试 insert into t_user(userid,loginpassword, isdisable) values('ffll','liudddyujj', 0); insert into t_user(userid,loginpassword, isdisable) values('dddd','zhang', 0) ; select * from t_user; 就可以看出结果。
    2、结合mybatis方式进行修改:
    ----创建序列
    create sequence TRIGGER_INFO_SEQ
    increment by 1
    start with 1
    nomaxvalue
    nominvalue
    nocache
    
    

    <insert id="save" parameterType="com.bosssoft.platform.jobcenter.admin.core.model.JobInfo" useGeneratedKeys="true" keyProperty="id" databaseId="Oracle">
        <selectKey resultType="java.lang.Integer" order="BEFORE" keyProperty="id">
          SELECT TRIGGER_INFO_SEQ.NEXTVAL FROM dual
        </selectKey>
        INSERT INTO BOS_QRTZ_TRIGGER_INFO (
              id,
              job_group,
              job_cron,
              job_desc,
              add_time,
              update_time,
              author,
              alarm_email,
              executor_route_strategy,
              executor_handler,
              executor_param,
              executor_block_strategy,
              executor_fail_strategy,
              glue_type,
              glue_source,
              glue_remark,
              glue_updatetime,
              child_jobkey
      ) VALUES (
              #{id},
              #{jobGroup},
              #{jobCron},
              #{jobDesc},
              to_date(to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss'),
              to_date(to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss'),
              #{author},
              #{alarmEmail},
              #{executorRouteStrategy},
              #{executorHandler},
              #{executorParam},
              #{executorBlockStrategy},
              #{executorFailStrategy},
              #{glueType},
              #{glueSource},
              #{glueRemark},
              to_date(to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'yyyy-MM-dd HH24:mi:ss'),
              #{childJobKey}
     )
    </insert> 

    4、xml里头不支持<=等不等符号,解决方法:

    <![CDATA[ <= ]]>

    标记避免Sql中与xml规范相冲突的字符对xml映射文件的合法性造成影响,ibatis中应该经常见到"<![CDATA["这样的东西吧,它的用处应该是转义一些特殊关键字字符,不合法的XML字符必须被替换为相应的实体。
    下面是五个在XML文档中预定义好的实体:
        < &gt; 小于号
        > &lt; 大于号
        & & 和
        &apos; ' 单引号
        " " 双引号
    应该留意,在"<![CDATA["转义符中间不要用标签
    比如就可以这么用
        <message><![CDATA[if salary < 1000 then]]</message>
    例如:
        <select id="isExistsCode" parameterType="String" resultType="Boolean">
          <![CDATA[
            select count(*) from afa_sample_agency where code = #{code} and id<>#{id}
          ]]>
        </select>
    或者可以用转义字符进行书写。
        <select id="queryOverDueFileInfos" resultType="com.bosssoft.platform.domain.filemgr.FileInfo">
            SELECT * FROM AFA_ATTACH_FILEINFO WHERE bizType=#{bizType} and createtime&lt;#{overDueDate}
        </select>

    5、#和$的区别:

      1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号。
        如:order by #user_id#,如果传入的值是111,那么解析成sql时的值为order by "111",
        如果传入的值是id,则解析成的sql为order by "id".
      2. $将传入的数据直接显示生成在sql中。
        如:order by $user_id$,如果传入的值是111,那么解析成sql时的值为order by user_id,
        如果传入的值是id,则解析成的sql为order by id.
      3. #方式能够很大程度防止sql注入。$方式无法防止Sql注入。$方式一般用于传入数据库对象,例如传入表名.一般能用#的就别用$.

    6、Cause: java.sql.SQLSyntaxErrorException: ORA-01745: 无效的主机/绑定变量名 
      原因,sql语句中,两个填充变量间没有写逗号

    7、Oracle修改时间报:ORA-01830: 日期格式图片在转换整个输入字符串之前结束的解决办法 

      1、错误原因:
        date类型不能包含秒以后的精度。
        如日期:2010-01-01 20:02:20.0
        解决方法:将日期秒以后的精度去除
        如日期:2010-01-01 20:02:20
      2、INSERT INTO TEST2 (C1, C2,c3) VALUES (${v1},${v2},to_date(${v3},'yyyy-mm-dd'));
        oracle里面不需要以“;”结尾。

    8、Java.sql.SQLException: ORA-01810: 格式代码出现两次
      在sql语句中也就to_date只有格式,所以错就在这里。总结发现:Oracle格式是不区分大小写的,所以MM和mm是一样的 可能会以月份的形式显示。所以oracle中用了mi来代替MM。

    9、Oracle里头不区分大小写:

      Oracle里头不区分大小写,所以要求有大小写区分的地方,可以用别名进行转换。    

        <select id="triggerCountByDay" resultType="java.util.Map" databaseId="Oracle">    
          select triggerDay "triggerDay", COUNT(id) "triggerCount" from(
              SELECT to_char(trigger_time, 'yyyy-MM-dd') triggerDay,id        
            FROM BOS_QRTZ_TRIGGER_LOG
           WHERE trigger_time BETWEEN #{from} and #{to}
              <if test="handleCode gt 0">
                AND handle_code = #{handleCode}
            </if>)  
           GROUP BY triggerDay
        </select

      

  • 相关阅读:
    从URL输入到页面展现,过程中发生了什么?
    Android ADB被占用 重启 ADB方法
    Android消息处理:EventBus、BroadCast和Handler-优缺点比较
    Android EventBus 的使用
    浅谈Java/Android下的注解
    如何理解Android中的xmlns
    【LeetCode】165
    【leetcode】155
    【LeetCode】12 & 13
    【LeetCode】66 & 67- Plus One & Add Binary
  • 原文地址:https://www.cnblogs.com/shawWey/p/7081448.html
Copyright © 2011-2022 走看看