美文网首页
常用数据库操作命令

常用数据库操作命令

作者: wyymaomi | 来源:发表于2019-11-09 10:13 被阅读0次

    1.创建库表

    CREATE TABLE <表名>
    (
    ID_ VARCHAR2(64) NOT NULL PRIMARY KEY,
    TASK_ VARCHAR2(64),
    START_DATE_ DATE,
    END_DATE_ DATE,
    BJYWWT_ INTEGER,
    .........
    );
    
    --添加注释
    COMMENT ON TABLE ABD_INT_CON  IS '国际学术会议信息';
    COMMENT ON COLUMN ABD_INT_CON.ID_ IS 'id';
    COMMENT ON COLUMN ABD_INT_CON.TASK_ IS '出访任务';
    COMMENT ON COLUMN ABD_INT_CON.CH_NAME_ IS '会议名称(中文)';
    COMMENT ON COLUMN ABD_INT_CON.EN_NAME_ IS '会议名称(外文)';
    

    2.增加字段

    alter table ath_teacher_info add xnbz_ integer;
    comment on column ath_teacher_info.xnbz_ is '校内编制(人事档案是否归属校内)';
    

    3.更改字段长度

    --更改会议地点长度
    alter table ABD_INT_CON modify HYDD_ varchar2(200);
    

    4.修改字段名

    alter table Student rename name to StuName;
    

    5.修改数据类型

    alter table tableName modify (cloumnName 数据类型);
    --例如
    alter table Student modify (id varchar2(64));
    

    6.更新数据

    --修改最近一次出访记录为最近三年出访记录
    UPDATE ABD_TASK_STEP SET NAME_='最近三年出访记录', page_title_='最近三年出访记录' WHERE CODE_='zjyccfjl' and category_='teacher' and type_=4;
    

    7.新增数据

    insert into sys_sys_config_param (CODE_, NAME_, VALUE_, BUSI_CODE_, STATUS_, REMARK_)
    values ('INTXnpwMaxCode', '出国校内批文号开始使用位数', '20190000', 'IHMTaskApply', '1', '');
    

    8.查询条件为null的数据

    <if test="c_apply.whereCondition.scholarshipComplete != null and 'true'.toString() == c_apply.whereCondition.scholarshipComplete.toString() ">
          and T_ESA.SCHOLAR_COMPLETE_ = #{c_apply.whereCondition.scholarshipComplete}
    </if>   
    <if test="c_apply.whereCondition.scholarshipComplete != null and 'false'.toString() == c_apply.whereCondition.scholarshipComplete.toString() ">
          and T_ESA.SCHOLAR_COMPLETE_ is null or T_ESA.SCHOLAR_COMPLETE_ = #{c_apply.whereCondition.scholarshipComplete}
    </if> 
    
    1. [mybatis中<[图片上传失败...(image-d719ab-1576217405298)]

    在使用mybatis 时我们sql是写在xml 映射文件中,如果写的sql中有一些特殊的字符的话,在解析xml文件的时候会被转义,但我们不希望他被转义,所以我们要使用<![CDATA[ ]]>来解决。
    <![CDATA[ ]]> 是什么,这是XML语法。在CDATA内部的所有内容都会被解析器忽略。
    如果文本包含了很多的"<"字符 <=和"&"字符——就象程序代码一样,那么最好把他们都放到CDATA部件中。

    10.Mybaits中like的用法

        <select id="getAbroadUltRecordList" resultMap="abroadUltRecordResultMap">
            select
            t_record.id_ t_id_,
            t_record.task_ t_task_,
            t_record.country_ t_country_,
            t_record.startdate_ t_start_date_,
            t_record.enddate_ t_end_date_,
            t_record.ult_remark_ t_ult_remark_,
            t_record.opinion_ t_opinion_,
            t_record.operator_ t_operator_,
            t_record.deal_time_ t_deal_time_,
            t_user.name_ t_applicant
            from abd_ult_record t_record
            left join abd_task t_task on t_task.id_=t_record.task_
            left join ath_user t_user on t_user.id_=t_task.creater_
            <where>
                <if test="c_searchview.whereCondition.countryName != null and c_searchview.whereCondition.countryName != '' ">
                <![CDATA[
                    and t_record.country_ like '%'||#{c_searchview.whereCondition.countryName,jdbcType=VARCHAR}||'%'
                ]]>
                </if>
                <if test="c_searchview.whereCondition.memberName !=null and c_searchview.whereCondition.memberName !=''">
                    <![CDATA[
                    and exists(select 1 from abd_member t_member
                        left join ath_user u on t_member.user_=u.id_
                        where t_member.task_=t_record.task_
                        and (t_member.name_ like '%'||#{c_searchview.whereCondition.memberName,jdbcType=VARCHAR}||'%'
                                or u.account_=#{c_searchview.whereCondition.memberName,jdbcType=VARCHAR})
                    )
                    ]]>
                </if>           
                <if test="c_searchview.whereCondition.applicant != null and c_searchview.whereCondition.applicant != ''">
                    <![CDATA[
                    and t_user.name_ like '%'||#{c_searchview.whereCondition.applicant,jdbcType=VARCHAR}||'%'
                    ]]> 
                </if>                       
            </where>
            order by t_record.id_ desc
        </select>
    

    相关文章

      网友评论

          本文标题:常用数据库操作命令

          本文链接:https://www.haomeiwen.com/subject/brigbctx.html