码迷,mamicode.com
首页 > 数据库 > 详细

SQL_DML简单操作

时间:2014-10-09 02:43:07      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:sql   oracle   

***********************************************声明*********************************************************************** 

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。

深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39903951

****************************************************************************************************************************

SQL基础之简单的DML语句

--查看实验表原始数据
SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME       OLDDNAME       NEWLOC        OLDLOC
--------- --------- -------------- -------------- ------------- -------------
                 10                ACCOUNTING                   NEW YORK
                 20                RESEARCH                     DALLAS
                 30                SALES                        CHICAGO
                 40                OPERATIONS                   BOSTON

查看某一列的数据量
SQL> select count(*) from newdept where oldloc is not null;
  COUNT(*)
----------
         4

(1)、update

update 表名 set列名=值 [,列名=值,...] [where 条件]

例:
SQL> update newdept set newdeptno=08,newdname=‘BUSINESS‘,newloc=‘BEIJING‘ where olddeptno=30;
--更新一条数据操作
1 row updated

SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME       OLDDNAME       NEWLOC        OLDLOC
--------- --------- -------------- -------------- ------------- -------------
                 10                ACCOUNTING                   NEW YORK
                 20                RESEARCH                     DALLAS
        8        30 BUSINESS       SALES          BEIJING       CHICAGO
                 40                OPERATIONS                   BOSTON

(2)、delete

delete [from] 表名 [where 条件]

SQL> delete from newdept where olddeptno=10;
--删除一条数据操作
1 row deleted

SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME       OLDDNAME       NEWLOC        OLDLOC
--------- --------- -------------- -------------- ------------- -------------
                 20                RESEARCH                     DALLAS
        8        30 BUSINESS       SALES          BEIJING       CHICAGO
                 40                OPERATIONS                   BOSTON

(3)、insert

insert into 表名 [(列名 [,列名...])] values (数值 [,数值...]);
SQL> insert into newdept values (1,‘‘,‘BDA‘,‘‘,‘BEIJING‘,‘‘);
--插入一条数据操作
1 row inserted

SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME       OLDDNAME       NEWLOC        OLDLOC
--------- --------- -------------- -------------- ------------- -------------
                 20                RESEARCH                     DALLAS
        8        30 BUSINESS       SALES          BEIJING       CHICAGO
                 40                OPERATIONS                   BOSTON
        1           BDA                           BEIJING      

把一个列插入到新的表中
--把scott用户的emp表的SAL列插入到hyl用户的newdept表中

***********************************************声明*********************************************************************** 

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。

深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39903951

**************************************************************************************************************************** 

SQL_DML简单操作

标签:sql   oracle   

原文地址:http://blog.csdn.net/huangyanlong/article/details/39903951

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!