• oracle SQL


    Oracle中的any、some、all用法

    any

    select * from admin where  password>any(123,234,345)

    select * from admin where password > any(select * from admin where password=123)

    输出password中任意大于123、234、345其中一个值得数据

    some

    some与any的效果都是一样的,大于其中一个值就可以

    select * from admin where  password>some(123,234,345)

    all

    大于其中所有的值

    select * from admin where  password>all(123,234,345)

    Mysql中的any、some、all

    any

    select * from bjb where xh> any(select xh from bjb where xh=2)

     select * from bjb where xh> some(select xh from bjb where xh=5 union select xh from bjb where xh=12);

    select * from bjb where xh> all(select xh from bjb where xh=5 union select xh from bjb where xh=2)

    数据库中is null、is not null

    我们只能用select * from bjb where xm is null来查找空的位置,不能使用where xm =null

    数据库中between  x  and  y

    select * from bjb where xh between  2 and 12;        包含x和y的值

     select  * from bjb where  2<=xh and xh<=12;

     数据库中的in和not in

    需要进行某些值得等值判断的时候可以使用in和not in

    in(list)        not in(list)

    select * from bjb where xh in (2,5,12);

    select * from bjb where xh  not in (2,5,12);

     select * from bjb where xh=2 or xh=5 or xh=12;

    and和or可能出现在同一个sql语句中,此时需要注意and和or的优先级

    and的优先级高于or,所以一定要将or的相关操作用()括起来 ,提高优先级

    数据库中的exists

    exists(子查询)        相当一个for循环

    select * from bjb e where exists(select xh from bjb d where (d.xh=2  or d.xh=5) and e.xh=d.xh);

     模糊查询

    like

    在like的语法中需要使用占位符或通配符

    _        某个字符或数字仅出现一次

    %        任意字符出现任意次数

    select  *  from bjb  where xh  like("p%")

     倒数第二位为h        倒数第二位为o的

     escape,使用转义字符,可以自己规定转义字符

    使用like的时候需要注意,like的效率极低

    使用like可以参考使用索引,但是要求不能以%开头

    到大文本的检索的时候,可以使用某些框架luence、solr、elastic、search

    数据库中的order by 

    select * from bjb order by 1 asc;        默认情况相下升序(可写可不写)

    select * from bjb order by 1 desc;        倒叙

    order by 做的是全排序,会比较消耗系统资源,因此选择在业务不太繁忙的时候进行

     数据库中的union、union all、intersect、minus

    1.union  all        全集

    2.union        并集(去重)

    3.intersect        交集

    4.minus        差集

    Oracle函数

    SQL函数

    函数一般是在数据上执行的,它给数据的转换和处理提供了方便。只是将取出的数据进行处理,不会改变数据库中的值

    sum        求和

     count(*)        求多少条记录

     having语句

    单行函数的分类

    字符函数:

            concat:字符的连接,等同于||                可用于区分数据库

            initcap:将字符串首字母大写

            upper:将字符串全部转换为大写

            lower:将字符串装换为小写

            lpad:左边填充字符串        lapd(字段,占的长度,用什么占位)

            rpad:右边填充字符串

            trim:去除左右两边空格        ltrim去除左边        rtrim去除右边

            instr:查找指定字符串的位置        instr(字符串,需要查找的内容)

            length:返回长度

            substr:截取字符串的操作

            replace:替换操作

    数字函数:

            round:给小数进行四舍五入,可以指定小数部分的位数

            trunc:截断数据,按照位数去进行截断,但是不会进行四舍五入的操作

            mod:取模操作

            ceil:向上取整

            floor:向下取整

            abs:取绝对值

            sign:取正负值

            pow(x,y):x的y次幂

    日期函数:

            mysql

            select  current_time();

            select  current_date();

            select  current_timestamp();

             Oracle数据库中

            select  sysdate  from  dual;

            select   current_date  from dual;

            select   localtimestamp  from  dual;        返回当前的时间戳

    转换函数:

            标量数据可以有类型的转换,转换分为两种,隐式类型转换和显示类型转换

            隐式类型转换可用于:

                    字符和数字相互转换&字符和日期相互转换

                    varchar2  or   char   -- number

                    varchar2  or   char   --  data

                    number -- varchar2

                    date -- varchar2

            尽管数据类型之间可以进行隐式转换,仍建议使用显示转换函数,以保持良好的设计风格

                    to_char        转化为字符串

                    to_number        转化为数字

                    to_date        转化为日期

                    number和date之间不可以相互转化

    (14条消息) 对于输出点是时间戳的渗透测试方法(以Oracle数据库为例)_不习惯有你的博客-CSDN博客_oracle渗透测试https://blog.csdn.net/qq_58000413/article/details/125662269date :  to_char

    select  to_char(sysdate,'YYYY-MM-dd  HH24:MI:SS') from dual

     number : to_char 

    单行函数嵌套

    单行函数可以被嵌入到任何层

    嵌套函数从最深层到最底层求值

    其他函数

    decode

    decode(选中参数,值的匹配,匹配到执行什么条件)

    case  when

    case  when  条件  then  执行操作1  when  条件  then 执行操作2  end

    case  when  条件  then  执行操作1   else  执行操作2  end

    组函数

    常用的组函数

    avg()        返回某列的平均值

    min()        返回某列的最小值

    max()        返回某列的最大值

    sum()        返回某列值得和

    count()        返回某列的行数,处理的时候会跳过空值处理非空值

                    count一般用来获取表中的记录条数,获取条数的时候可以使用*或者某一个具体的列,甚至可以使用纯数字来代替,但是从运行效率的角度来考虑的话,建议使用数字或者某一个具体的列而不要会用*

    group by        按照某些相同的值去进行分组操作

                          group进行分组操作的时候,可以指定一个列或者或多个列,但是当使用了group  by 之后,选择列表中只能包含组函数的值或者group by的普通字段

    例子:select  sum(薪水)  from  emp  group by  部门

    数据分组

    出现在select列表中的字段,如果出现的位置不是在组函数中,那么必须出现在GROUP BY子句中

    不能在WHERE子句中使用组函数,不能在WHERE子句中限制组,使用Having对分组进行限制

    select子句顺序

     关联查询

    select  table1.column1 , table1.column2...

    from  table2.column1 , table2.column2...

    where  table1.column1=table2.column2

    在进行连接的时候可以进行等值连接也可进行非等值(between  and )连接

    外连接

    没有关联的数据不会显示,此时需要外连接

    分类:左外连接(把左表的全部数据显示),右外连接(把右表的全部数据显示)

    select  *  from table1  t1,table2  t2  where  t1.column=t2.column        等值连接

    select  *  from table1  t1,table2  t2  where  t1.column=t2.column(+)        左外连接

    select  *  from table1  t1,table2  t2  where  t1.column(+)=t2.column        右外连接

    自连接

    将一张表当成不同的表来看待,自己关联自己

    select   e.ename,m.ename  from  emp e,emp  m where  e.mgr=m.empno

    笛卡尔积

    当关联多张表,但是不指定连接条件的时候,会进行笛卡尔积

    关联后的总记录条数为m*n,一般不要使用

    select  * from  emp e,dept d

    92的表连接语法有什么问题???

    在92语法中,多张表的连接条件在where子句中,同时where需要对表进行过滤

    因此,相当于将过滤条件和连接条件揉到一起,太乱了,因此出现了99语法

  • 相关阅读:
    udp多播
    VSCode安装Go环境(详细教程)
    ICLR‘23 UnderReview | LightGCL: 简单而有效的图对比学习推荐系统
    阿里云国际站如何助力餐饮行业出海?
    为啥这么人选择iPhone
    Mvvm中的Lifecycle
    asp毕业设计——基于asp+sqlserver的电子论坛系统设计与实现(毕业论文+程序源码)——电子论坛系统
    java面试——JVM(内存结构、垃圾回收、内存溢出)
    Linux进程常见通信方式
    prosody相关概念了解。xmpp,jabber,bosh等
  • 原文地址:https://blog.csdn.net/qq_58000413/article/details/126953309