select 语法使用案例SELECT * from emp; --每个人的部门编号,姓名,薪水 select empno, ename, sal from emp; --每个人的年薪 select ename, sal*12 from emp; SELECT 2*3 from emp; --得到当前时间 SELECT sysdate ; --可以给列起别名,比如求每个人的年薪 SELECT ename,sal*12 annn FROM emp; --如果别名中有空格,需要用双引号 select ename, sal*12 "an nn" from emp; --如果没有内容,则为空 SELECT ename,sal,empno FROM emp; SELECT ename,empno,sal * 12 + comm FROM emp; --可以将多个字符串拼在一起。比如:求每个人的薪水,格式为smith-sal-123 select ename || ‘-‘ || sal || ‘-‘ || comm from emp; SELECT ename || ‘+‘ || sal || ‘+‘ ||comm from emp; --如果字符串中有单引号,需要用另外一个单引号转义,比如:这样一个字符串: he‘s friend select ename || ‘he‘‘s friend‘ from emp;
--DML--Data Manipulation Language--数据操作语言 query information (SELECT), add new rows (INSERT), modify existing rows (UPDATE), delete existing rows (DELETE), 融合 perform a conditional update or insert operation (MERGE), see an execution plan of SQL (EXPLAIN PLAN), and lock a table to restrict access (LOCK TABLE). --DDL--Data Definition Language--数据定义语言 create, modify,drop, or rename objects (CREATE,ALTER,DROP,RENAME), 删除数据而不改变结构 remove all rows from a database object without dropping the structure (TRUNCATE), manage access privileges (GRANT,REVOKE), 审计 audit database use (AUDIT,NOAUDIT) and add a description about an object to the dictionary (COMMENT). --Transaction Control事务控制语句 save the changes(COMMIT) or discard the changes (ROLLBACK) made by DML statements. 事务回滚点 Also included in the transaction-control statements are statements to set a point or marker in the transaction for possible rollback (SAVEPOINT) 开启事务 and to define the properties for the transaction (SET TRANSACTION). Used to manage the properties of the database. 这个类别中只有一条语句(ALTER SYSTEM)。 There isonly one statement in this category (ALTER SYSTEM). --DCL--Data Contro Language--与开发关系不是很密切,用于权限的分配与回收 grant,revoke,data control --Session Control control the session properties (ALTER SESSION) and to enable/disable roles (SET ROLE). --System Control