专业编程教程与实战项目分享平台

网站首页 > 技术文章 正文

Oracle有哪些常见的函数? oracle中常用的函数

ins518 2024-10-20 09:07:42 技术文章 367 ℃ 0 评论
  1. 恢复删除的数据
insert into '表名' select * from '表名' as of TIMESTAMP 
TO_TIMESTAMP("当前时间",'yyyy-MM-dd hh24:miss')

2.批量添加

<insert id="1" parameterType="map">
    insert into dual
    <foreach collection="list" item="i" separator="UNION ALL">
        select
        #{}
        from dual
    </foreach>
</insert>

3.添加更新用一个sql

//先判断id存在不存在 如果存在 就更新 不存在就添加

<update id="1" parameterType="map">
        MERGE INTO dual
        USING(SELECT #{id} as id from dual) t2
        ON(t2.id=dual.id)
        where MATCHED THEN
        UPDATE SET
        <if></if>
   where NOt MATCHED THEN
   INSERT()
   values
   ()
  </update>

4.创建临时表的用法

with 表名 as(临时表),
      表名1 as (临时表),
      select .....

5.行转列

pivot ( 字段 for 字段 in (值 as 别名 ))N

6.mybatis中的用法

//拼接insert
insert into 表名
<trim prefix="(" suffix=")" suffixOverrides=",">
</trim>

//拼接update
update 表名
    <set>
    <trim suffixOverrides=",">
    </trim>
    </set>

//拼接select语句
<include refid="selectHaoMan6Vo" />
        <where>
            <trim prefixOverrides="and">
            </trim>
            </where>

7.部分函数解释

1.row_number() over (partition by 分组的字段 order by 排序的字段 desc)

2.NVL(X,VALUE) 如果x为空 返回value 否则返回x
3.nvl2 (expr1,expr2,expr3)
  若第一个参数为NULL,则返回expr3;
  若第一个参数为非NULL,则返回expr2
4.nullif (expr1,expr2)
  若两个参数值相等,则返回 *NULL;
  若两个参数不等,则返回expr1
5.coalesce (expr1,expr2,…,exprn)
  返回表达式中第一个非空表达式,如果都为空则返回空值,
  也就是:从左往右数,遇到第一个非null值,则返回该非null值,
  所有表达式必须是相同类型,或者可以隐式转换为相同的类型,否则报错。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表