zoukankan      html  css  js  c++  java
  • oracle语句使用总结

    例子,SQL表(表名为armyInfo):


    1、查找语句
    语法:select 列名 from 表名 where 条件从句
    例如:
    1)查找表显示
    select * from armyInfo
    2)查找表里的name,age显示
    select a.Name,a.Age from armyInfo a
    3)查找countryId为1的列表显示
    select * from armyInfo a where a.CountryId = "1"
    4)查找countryId为1或者2的列表显示
    select * from armyInfo a where a.CountryId in ("1","2")
    5)查找countryId 为1且state为True的列表显示
    select * from armyInfo a where a.CountryId = "1" and a.State = 'True'
    5)查找countryId 为1或者state为True的列表显示
    select * from armyInfo a where a.CountryId = "1" or a.State = 'True'

    2、更新列表字段语句
    语法: update 表名 set 列名 = 新值 where 条件从句
    1)更新某一行中的一个列
    update armyInfo a set a.Age = "32"  where a.Name = "刘备"
    p.s:这里注意各个字段的数据类型,若是为整数类型,则去掉双引号
    2)更新某一行中的若干列
    update armyInfo a set a.Age = "32" ,a.State = "False" where a.Name = "刘备"

    3、插入新的行
    语法:insert into 表名 values(值1,值2……)
    1)插入新的行
    insert into armyInfo values('3','大乔','32','True','3')
    2)插入新的行,在指定的列中插入数据
    insert into armyInfo a (a.Name,a.CountryId) values('小乔','3')

    4、like 和 通配符
    语法:…………where 列名 like 模式,用于搜索特定模式
    通配符     描述
    %     替代一个或多个字符
    _                                    仅替代一个字符
    [charlist]     字符列中的任何单一字符

    [^charlist] 或者 [!charlist]
        不在字符列中的任何单一字符
    1)年龄以3开头的条件语句(%用法)
    ……where a.Age like '3%'
    2)名字里含有“诸”和“亮”的条件语句(_用法)
    ……where a.Name like '诸_亮'
    3)名字表里姓“刘”或“关”或“周”的条件语句([charlist])用法)
    ……where a.Name like '[刘关周]%'
    4)名字表里不姓“刘”或“关”或“周”的条件语句([charlist])用法)
    ……where a.Name like '[^刘关周]%'

    5、group by 语句
    group by 常与sum函数合用进行统计,也可用它进行过滤一些重复的结果
    1)统计相同的countryId的年龄总和
    select a.CountryId , sum(a.Age) from armyInfo a group by a.CountryId
    2)统计state为True的各国家的年龄总和
    select a.CountryId , sum(a.Age) from armyInfo  a where a.State = 'True' group by a.CountryId
    3)过滤重复结果
    select a.CountryId from armyInfo a where a.State = 'True' group by a.CountryId

  • 相关阅读:
    repadmin example.
    在 Windows 2000 和 Windows XP 中重置计算机帐户
    管理活动目录
    使用AdsiEdit工具查看GC数据
    mms链接media player 9.0无法打开
    活动目录的复制之细节
    使用Repadmin.exe 对活动目录复制排错
    Difference among Domain Local Group and Global Group and Universal Group
    使用 ADSI Edit 编辑 Active Directory 属性
    xp的密码工具
  • 原文地址:https://www.cnblogs.com/tanliyu/p/4207773.html
Copyright © 2011-2022 走看看