• Oracle数据库的SQL语句编写


    一、

      --:两个减号表示单行注释

        /*多行注释*/

      /*sql脚本:是数据库的sql语句文件,扩展名为.sql

        sql:结构化查询语言

      */

    二、SQL脚本语句学习

      ---- DDL语言

        1)create关键字,用来创建表结构

          create table tname (表名)(

            colName1 dataType(类型),

            colName2 dataType,

            colName3 dataType,

            ....

            colName dataType

          );

          eg:创建一个表,名字是temp_1,字段有tid 数字类型,

          create table temp_1(

            tid number(4),

            tname varcahr2(20),

            tgender char,

            tbirth date

          );

        2)alter和drop关键字,用来修改和删除表的结构

          --1:增加表的字段

            格式:alter table tname add(colName dataType);

            eg:为表temp_1添加一个字段tage长度为2

              alter table temp_1 add(tage number(2));

          --2:删除表的字段

            格式:alter table tname drop column colName

            eg:为表temp_1删除tage这个字段

              alter table temp_1 drop column tage;

          --3:修改字段名称

            格式:alter table tname rename column to newName

            eg:将表temp_1中的tname改成name

              alter table temp_1 rename column tname to name;

          --4:修改字段的数据类型

            格式:alter table tname modify column dataType

            eg:修改temp_1表中的name为varchar2(30)

              alter table temp_1 modify name varcahr2(30);

          --5:修改表名

            格式:rename oldTname to newName

            eg:修改temp_1为temp_2

              rename temp_1 to temp_2;

          --6:删除表结构

            格式:drop table tname

            eg:删除temp_2

              drop table temp_2;

          --7:查看表结构

            格式:desc tname

            eg:查看表temp_1的结构

              desc temp_1;

        3)truncate:清空表中所有的数据

          格式:truncate table tname

          eg:清空表temp_1所有的数据

            truncate table temp_1;

      ----DML语言

        1)insert:向表中插入记录

          --格式1:insert into tname(colName1,colName2,.......) values(val1,val2....)

          --格式2:insert into tname values(val1,val2.....) 要求:赋值顺序与建表的字段顺序一样,个数也不能少。

          eg:向temp_1插入数据:1001,'张三','f','2010-12-12'

            insert into temp_1 values(1001,'张三','f',to_date('2010-12-12','yyyy-mm-dd')); 

        2) delete:删除记录

          --格式1:delete [from] tname;删除表中所有记录(可回滚)

          --格式2:delete [from] tname where 条件

          eg:删除temp_1中tid为1001的数据

            delete from temp_1 where tid = 1001;

        3)update:用来修改字段

          --格式1:update tname set colName = val [,colName2 = val2,.....]

          --格式2:update tname set colName = value where 条件

          eg:修改表temp_1中所有的性别为'm'

            update temp_1 set tage = 'm';

      --DQL语言

       select:查询数据(必须基于一张表)

        格式:select colName,....from tname;

           还可以给字段起别名:

            select colName as nickname,.....from tname;(as可省)

          eg:查询表temp_1中所有的数据

            select * from temp_1;

    今天更新的东西是我们常用的数据库查询语句,有点多了哈哈哈,慢慢看大家,如果喜欢请给小编一个赞,如果那里不明白的可以留言,我会为大家解答的,如果小编写的有错误,也请指出互相学习,下节为大家更新字符串操作函数的用法,希望大家喜欢。

          

  • 相关阅读:
    IB(InterBase Server) 的完整连接格式
    jna
    编写基于Prototype的Javascript动画类
    Go——使用 go mod ——有依赖的Go工程
    pkgconfig—— PKG_CONFIG_PATH——Makefile——pkgconfig的作用与使用
    Go——Goland Debug报错Version of Delve is too old for this version of Go
    NATS——NATS Streaming 是什么 (转)
    Go——Go语言调用C语言
    go get安装包超时处理
    NATS—基础介绍 (转自 https://www.cnblogs.com/yorkyang/p/8392172.html)
  • 原文地址:https://www.cnblogs.com/lyr999736/p/8809968.html
Copyright © 2020-2023  润新知