zoukankan      html  css  js  c++  java
  • oracle 重要函数

    1)instr()函数的格式 (俗称:字符查找函数)

    格式一:instr( string1, string2 ) / instr(源字符串, 目标字符串)

    格式二:instr( string1, string2 [, start_position [, nth_appearance ] ] ) / instr(源字符串, 目标字符串, 起始位置, 匹配序号)

    解析:string2 的值要在string1中查找,是从start_position给出的数值(即:位置)开始在string1检索,检索第nth_appearance(几)次出现string2。

    注:在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。只检索一次,也就是说从字符的开始到字符的结尾就结束。

    链接

    2)decode函数

    decode函数嵌套

    【例】表中A,B,C三列,实现当A列大于B列时,选择A列,否则选择B列,当B列大于C列时,选择B列,否者选择C列

     select decode(sign(A-B),1,A,decode(sign(B-C),1,B,C)) from table;

    【例】A、B两表,找出ID字段中,存在A表,但是不存在B表的数据。A表总共13w数据,去重后大约3W条数据,B表有2W条数据,且B表的ID字段有索引。

    方法一

      使用 not in ,容易理解,效率低  ~执行时间为:1.395秒~

    select distinct a.id from a where a.id not in(select id from b)

    方法二

      使用 left join...on... , "B.ID isnull" 表示左连接之后在B.ID 字段为 null的记录  ~执行时间:0.739秒~

    select a.id from a left join b on a.id=b.id where b.id is null

    方法三

      逻辑相对复杂,但是速度最快

    select * from a where (select count(1) as num from b where a.id=b.id)=0
  • 相关阅读:
    快速切题 sgu102.Coprimes 欧拉函数 模板程度 难度:0
    快速切题 sgu104. Little shop of flowers DP 难度:0
    poj 1163 The Triangle 搜索 难度:0
    sgu101 欧拉路径 难度:1
    快速切题 poj3414 Pots
    xml学习
    linux
    常用排序算法
    C++面试题目
    软件工程的一些问题
  • 原文地址:https://www.cnblogs.com/liuyitan/p/8433209.html
Copyright © 2011-2022 走看看