加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

Oracle 基本SQL语句

发布时间:2021-03-12 12:05:22 所属栏目:站长百科 来源:网络整理
导读:建设表 create table A( aid number(2) not null,aname varchar2(4),asal number(7,2) ); 增进数据(插入) insert into a(aid,aname,asal) values(1,‘张三‘,1000.5); insert into a values(1,‘张三‘,1000.5); 修改数据(更新) update 表名 set 列名=更新

  • 建设表

    create table A( aid number(2) not null,aname varchar2(4),asal number(7,2) );

  • 增进数据(插入)

    insert into a(aid,aname,asal) values(1,‘张三‘,1000.5); insert into a values(1,‘张三‘,1000.5);

  • 修改数据(更新)

    update <表名> set <列名=更新值> [where <更新前提>]
    例:update tongxunlu set 年数=18 where 姓名=‘蓝色奶名‘

  • 删除数据

    【删除<满意前提的>行数据】delete from <表名> [where <删除前提>]

    例:delete from a where name=‘开心朋朋‘(删除表a中列值为开心朋朋的行) 

    【删除整个表数据】truncate table <表名>

    例:truncate table tongxunlu
    留意:删除表的全部行,但表的布局、列、束缚、索引等不会被删除;不能用语有外建束缚引用的表

    【删除整个表】drop table 表名称

    例:drop table? a;

  • 查询数据

    select *? from a;

    select 字段? from 表名? where 前提

  • 增进字段语法

    alter table tablename add (column datatype [default value][null/not null],….);

    声名:alter table 表名 add (字段名 字段范例 默认值 是否为空);

    例:alter table sf_users add (HeadPIC blob);

    例:alter table sf_users add (userName varchar2(30) default ‘空‘ not null);

  • 修改字段的语法

    alter table tablename modify (column datatype [default value][null/not null],….);

    声名:alter table 表名 modify (字段名 字段范例 默认值 是否为空);

    例:alter table sf_InvoiceApply modify (BILLCODE number(4));

  • 删除字段的语法

    alter table tablename drop (column);

    声名:alter table 表名 drop column 字段名;

    ?例:alter table sf_users drop column HeadPIC;

  • 字段的重定名

  声名:alter table 表名 rename column 列名 to 新列名 (个中:column是要害字)

  例:alter table sf_InvoiceApply rename column PIC to NEWPIC;

  • 表的重定名

    声名:alter table 表名 rename to 新表名

    例:alter table sf_InvoiceApply rename to sf_New_InvoiceApply;

  • 实现将一个表的数据插入到其它一个表

    1.第一种环境

    1》假如2张表的字段同等,而且但愿插入所稀有据,可以用这种要领:

      INSERT INTO 方针表 SELECT * FROM 来历表;

    2》好比要将 articles 表插入到 newArticles 表中,则是:

      INSERT INTO newArticles SELECT * FROM articles;

    3》假如只但愿导入指定字段,可以用这种要领:

      INSERT INTO 方针表 (字段1,字段2,...) SELECT 字段1,... FROM 来历表;

    2.第二种环境

    1》假如将一个表的数据放在其它一个不存在的表:
      select * into ?方针不存在的表 from 来历表

    2》假如只但愿导入指定字段,可以用这种要领:

      select 字段1,字段2,... into 方针不存在的表 from 来历表

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读