• oracle的SQl语句


    1.将表中的两个字段合并成一个显示

    SQL>   select id||stu_name as test from student;

    TEST
    ----------------------
    2007112810郭晓梅
    2007112812张大彪
    2007112813aaa
    2007112814王大志
    2007112815易建联
    2007112513teacher

    已选择7行。

    2.截取某一字段的查询:

    SQL> select address,substr(address,1,2) from student;

    ADDRESS              SUBS
    -------------------- ----
    北京市朝阳区         北京
    成都市金牛区         成都
    成都市青羊区         成都
    成都市青羊区         成都
    电子高专             电子
    chengdu              ch

    3.删除表的所有行:

    SQL> truncate table login;

    表已截掉。

    SQL> select * from login;

    未选定行

    4.将一个表字段内容复制到另一个表的相同字段 :                                            
    SQL> insert into login(id)(select id from student);
    已创建7行。

    5.alter命令的使用:
    SQL> alter table login modify pwd null; --更改可空约束
    表已更改。
    SQL> alter table login add(id char(16)); --添加字段

    表已更改。
    SQL> alter table login modify(pwd char(16)); --更改数据类型
    表已更改。
    6.函数的使用:
    SQL> select concat('028-',phone) as 电话 from student;
    --concat函数用于连接字符窜

    电话
    ---------------
    028-15980324635
    028-13645481541
    028-13654515131
    028-15964250213
    028-15964364512
    028-87992352

    SQL> select initcap(stu_name) from student; --initcap函数用于将首字母大写

    INITCAP(ST
    ----------
    Aa
    Aaa
    Teacher

    SQL> select instr(stu_name,'a') from student; --相当于c#中的indexOf函数

    INSTR(STU_NAME,'A') --查询stu_name字段中第一次A的位置,而且还可以指定查找范围
    -------------------
                      0
                      1
                      0
                      1
                      0
                      0

    7.oracle五大类型:
    DML(Data Mainpulation Language)数据操纵语言:select、insert、update、delete。
    DDL(Data Definition Language)数据定义语言:create、alter、drop、rename、truncate(截断表)
    TC(Transaction Control)事务控制:commit、rollback、savepoint
    DCL(Data Control Language)数据控制语言:grant、revoke
    Data Retrieval数据检索:select

    8.oracle用户的锁定和解锁:
    SQL> alter user spring account lock;

    用户已更改。

    SQL> connect spring
    请输入口令: ******
    ERROR:
    ORA-28000: the account is locked
    SQL> alter user spring account unlock;

    用户已更改。

    SQL> connect spring/754201;
    已连接。

    9.连接查询:
    SQL> select a.stu_name,a.class,b.pwd from student a,login b
    2 where a.id=b.id;

    STU_NAME   CLASS      PWD
    ---------- ---------- ----------------
    郭晓梅     07522      123456
    张大彪     07512      123456
    aaa        07521      123456
    王大志     07511      123456
    易建联     07532      123456
    teacher    7531       123456

  • 相关阅读:
    MySQL数据透视功能
    MySQL 姓名两个字中间加两个空格
    Back To Basics: Clustered vs NonClustered Indexes; what’s the difference?
    炉石传说 佣兵战纪 贫瘠之地
    When to Use Clustered or NonClustered Indexes in SQL Server
    Stairway to SQL Server Indexes
    Why use the INCLUDE clause when creating an index?
    Clustered vs Nonclustered Index: Key Differences with Example
    SQL Server: Order of Rows
    Being Agile vs. doing Agile: What's the difference?
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1773741.html
Copyright © 2020-2023  润新知