首页 > 代码库 > plaql高级查询命令

plaql高级查询命令

一.DDL数据定义语言:表操作
    1.新建表
        SQL> create table good(id number,name varchar2(10));
        
        添加注释
        SQL> comment on table good is ‘商品数据‘;
        SQL> comment on table good.id is ‘商品id‘;
    
    2.删除表
        SQL> drop table students;

    3.改动表
        a.改表结构
            SQL> alter table student drop column gender;
        b.改表名字
            SQL> alter table  student rename to students;
        c.添加约束
            SQL> alter table good add primary key(id);
            SQL> alter table student modify age not null;

    4.查看表
        SQL> select table_name from user_tables;
        SQL> desc student;

二.DML数据操纵语言:表数据操作
    1.增数据
        SQL> insert into good values(1,‘aaa‘,2.0);
        
        如果是从其他表添加,追加select

    2.删数据
        SQL> delete from good where id=1;

    3.改数据
        SQL> update good set price=5.0 where id=2;

    4.查数据
        SQL> select * from good;

        a.排序查找
            SQL> select * from good order by price;

        b.输出显示优化
            SQL> select ‘0‘||id as "编号",name as "名字",price as "价格" from good ;

        c.指定查找
            SQL> select * from good where price in(2);

        d.范围查找
            SQL> select * from good  where price between 1 and 3;

        e.模糊查找
            SQL> select * from good where name like ‘%b‘;

 

plaql高级查询命令