摘要:--实例1--------------------------创建触发器,当用户对test表执行DML语句时,将相关信息记录到日志表--创建测试表CREATE TABLE test(t_id NUMBER(4),t_name VARCHAR2(20),t_age NUMBER(2),t_sex CHAR);--创建记录测试表CREATE TABLE test_log(l_user VARCHAR2...
阅读全文
文章分类 - 从实践中学习 Oracle/SQL
摘要:Chapter 16 Procedurecreate or replace procedure proc_helloworldisbegin DBMS_OUTPUT.Put_Line('Hello World');end;/Procedure createdSQL> show serveroutputSQL> set serveroutput onSQL> show server...
阅读全文
摘要:Chapter 15 序列号(Sequence)和同义词(Synonym)SQL> desc supplier;Name Type Nullable Default Comments ------- ------------ -------- ------- -------- S_CODE NUMBER(6) Y SNAME VARCHAR2(25) Y CONTACT VARCHAR2(1...
阅读全文
摘要:Chapter 14 View 最基本的表也就是实体是不会发生变化的,变化的应该是视图。create view averageas select d.dname "部门", avg(e.sal) "平均工资", avg(nvl(comm,0)) "平均佣金", count(*) "员工数"from emp e, dept dwhere e.deptno = d.deptnogroup by d.d...
阅读全文
摘要:Chapter 13 索引与约束(Indexes and Constraints)create table empconas select * from emp;select * from empcon;SQL> desc empcon;Name Type Nullable Default Comments -------- ------------ -------- ------- ---...
阅读全文
摘要:Chapter 12 数据的维护数据维护包括了DML (Data Manipulating Language) 数据操作语言和事务控制(Transaction Control).create table emp_dmlasselect * from emp;select *from emp_dml;create table dept_dmlas select * from dept;select ...
阅读全文
摘要:Chapter 11 替代变量select empno, ename, salfrom empwhere sal >= 1500select empno, ename, salfrom empwhere sal >= &v_salarySQL> SQL> select empno, ename, sal 2 from emp 3 where sal >= &a...
阅读全文
摘要:Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 Chapter 9 控制Sql * PLUS 的环境和数据字典简介SQL> show echoecho OFFSQL> select * from dept; DEPTNO DNAME LOC---------- -------------- --------...
阅读全文
摘要:Chapter 7 多表查询减少冗余,方便管理主键(Primary Key):它是关系数据库表中的一列或几列的组合;能够唯一表示一条记录。实体完整性(Entity Integrity): 主键(Primary Key)不能为空(NULL)。表的设计者负责定义主键,数据库管理系统负责维护实体完整性。订单表(Order)订单号|.......商品号|商品名|商品描述|单价|... 供应商号|供应商名1...
阅读全文
摘要:Chapter 6 : 综合数据和分组函数COUNTAVESUMMAXMIN分组函数必须要在group by 的情况下才可以使用奥select count(*)from emp e;select count(e.mgr)from emp e;//return 不为空(NULL)的员工select avg(e.sal) "Average Salary", sum(e.sal) "Summary", ...
阅读全文
摘要:Chapter 5 : NULL 值的处理、逻辑操作和函数嵌套 select e.ename, e.job, e.sal, e.comm from emp e where e.job in ('CLERK','SALESMAN') order by e.job NULL:"unavailable,unassigned,undefined,unknow,immeasurable,inapplica...
阅读全文
摘要:SELECT LOWER('SQL: Structural Query Language')from dual;//dual 是一个虚表(伪表)。UPPER(列名|表达式)SELECT UPPER('sql is used exclusively in rdbmses')from dual;SELECT INITCAP('sql is an ENGLISH LIKE language')from ...
阅读全文
摘要:Chapter 3: 常用SQL * PLUS命令当前语句存储在SQL缓冲区中,我们可以操作这条记录。desc emp;SQL> desc emp;Name Type Nullable Default Comments -------- ------------ -------- ------- -------- EMPNO NUMBER(4) ENAME VARCHAR2(10) Y JO...
阅读全文
摘要:Chapter 2: 限制性查询和数据的排询select e.empno, e.ename, e.sal from emp ewhere e.sal > 1500;select e.empno, e.ename, e.sal from emp ewhere e.sal between 1500 and 2900;alter session set NLS_DATE_LANGUAGE = AM...
阅读全文
摘要:Chapter 1: Simple Query Sentenceselect * from emp;select e.empno, e.ename, e.sal from emp e;//查询语句中选择指定的列就是关系数据库中所称的投影(Project).一个完整的SQL命令叫语句(statement),比如 select * from emp;"select * "和"from emp"叫子句,...
阅读全文

浙公网安备 33010602011771号