1)insert :用于插入数据,操作对象表或者视图
INSERT INTO table [(column [, column...])]
VALUES(value [, value...]);
向表中插入时间,需要使用函数to_date()进行转换,当前时间sysdate:
insert into tab_dd values (1,to_date('2012-1-1','yyyy-mm-dd')) ;
insert into tab_dd values (1,sysdate) ;
向表中插入空值: insert into tab_dd values (1,null);
当数据源来自另一张表:insert into tab_dd(id) select id from tab_cc where id = 1;
2)update:用于更新数据,操作对象表或者视图
UPDATE table
SET column = value [, column = value, ...]
[WHERE condition];
当更新表的外键时,如果参照表中不含有该数据,向会报错
update emp set deptno=60;
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.FK_DEPTNO) violated - parent key not
found
3)delete:删除数据,与drop的区别:drop用于删除数据库对象(表,视图,触发器等)
DELETE [FROM] table
[WHERE condition];
最好加上where,防止删掉整表数据;
4)select :查询数据,操作对象是视图或表
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table;
SQL语句的关键词,需要查询列名不区分大小写,但where 条件的列对应的数据区分大小写,时间对格式敏感;
An arithmetic expression can contain column names, constant numeric values, and the arithmetic operators.
SQL语句可以包含算数表达式
select ename , sal , 12 * (sal + 100) from emp;
一个NULL值表示未知,不可用,不同于零或空格;
判断值是否为空值:select ename from emp where comm is null;
使用别名:select ename ,sal,12*sal*comm as "Annual Salary" from emp;
||:连接查询值,select ename ||' is a' || job as "Employees" from emp;
Rules of Precedence
:
1 Arithmetic operators
2 Concatenation operator
3 Comparison conditions
4 IS [NOT] NULL, LIKE, [NOT] IN
5 [NOT] BETWEEN
6 NOT logical condition
7 AND logical condition
8 OR logical condition
5)内置函数
单行函数:操作数据项,接受的参数可以是列或者表达式;作用用于每一列,都返回一个值;
拷贝一张表的副本
1)只拷贝结构:create table tab_cc as select * from tab_dd where 1=2;(最后两个数字只要不想等即可)
2)结构和数据全拷贝:create table tab_cc as select * from tab_dd where 1=1;(最后两个数字相等即可)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27009266/viewspace-743641/
,如需转载,请注明出处,否则将追究法律责任。