table:(表)
  创建表

create table test3 (tid number,tname varchar2(),hiredate date default sysdate);
create table emp20 as select * from emp where deptno=;
create table empinfo as select e.empno,e.ename,e.sal,e.sal* annsal,d.dname
      from emp e, dept d where e.deptno=d.deptno

  修改表

alter table test3 add photo blob;
alter table test3 modify tname varchar2();
alter table test3 drop column photo;
alter table test3 rename column tname to username;
rename test3 to test5;

  删除表

drop table test5;(没有正真的删除,只是放入了oracle的回收站中)
    show recyclebin(查看回收站)
    purge recyclebin;(清空回收站)
            (管理员没有回收站)
    flashback table TESTSAVEPOINT to before drop;(闪回回收站中的表) drop table TESTSAVEPOINT purge;

  表/列约束:

     check : 检查约束 gender varchar2() check (gender in ('男','女')),
create table student
(
sid number constraint student_pk primary key, //主键(索引)
sname varchar2() constraint student_name_notnull not null, //非空
gender varchar2() constraint student_gender check (gender in ('男','女')), //检查
email varchar2() constraint student_email_unique unique //唯一
constraint student_email_notnull not null, //非空
deptno number constraint student_fk references dept(deptno) on delete set null //外键(级联置空)
); (on delete cascade :级联删除)

view(视图) 虚表
  创建视图(要有视图权限):

        create view empinfoview
as
select e.empno,e.ename,e.sal,e.sal* annsal,d.dname
from emp e, dept d
where e.deptno=d.deptno; //可以进行DML操作,但是不建议该操作. create or replace view empinfoview
as
select e.empno,e.ename,e.sal,e.sal* annsal,d.dname
from emp e, dept d
where e.deptno=d.deptno
with read only; //屏蔽了 DML操作.

  删除视图:

drop view empinfoview;

sequence(序列) :维护表的主键,但是回滚等操作可能会出现裂缝.
  创建序列:

        create sequence myseq; //创建序列
select myseq.nextval from dual; //下移指针,返回序列值
select myseq.currval from dual; //返回当前指针序列值. create table testseq (tid number,tname varchar2());
insert into testseq values(myseq.nextval,'aaa'); //使用序列维护主键(类似自动增长列).

  删除序列

drop sequence myseq;

index(索引) :类似目录,增加查询效率
  自动创建:
    当定义了  PRIMARY   KEY   和   UNIQUE   之后,自动在相应的列上创建唯一性索引.

  创建索引:

        create index myindex on emp(deptno); //B树索引
create bitmap index myindex on emp(deptno); //位图索引索引(适合查询)

  删除索引:

drop index myindex;

synonym(同义词) :表的别名 (为了安全)
  创建同义词:

        create synonym myemp for emp; //私有同义词
create public synonym myemp for emp; //公有同义词

procedure(存储过程)
  创建存储过程
  (不带参数的)

        create or replace procedure sayHelloWorld  //不带参数
as
--说明部分
begin
dbms_output.put_line('Hello World'); end;
/

  (带参数)

        --给指定的员工涨100,(带参数)
create or replace procedure raisesalary(eno in number) //带一个输入参数参数的
as
--定义变量保存涨前的薪水
psal emp.sal%type;
begin
--得到涨前的薪水
select sal into psal from emp where empno=eno; --涨100
update emp set sal=sal+ where empno=eno; --要不要commit(不要,调用者提交回滚) dbms_output.put_line('涨前:'||psal||' 涨后:'||(psal+)); end;
/

  //带有out参数的存储过程(可以有返回值(OUT))

        create or replace procedure queryempinfo(eno in number,
pename out varchar2,
psal out number,
pjob out varchar2)
as
begin
select ename,sal,empjob into pename,psal,pjob from emp where empno=eno;
end;
/

  调用存储过程(sql中):

        . exec sayHelloWorld();
. begin
sayHelloWorld();
sayHelloWorld();
end;
/

function(存储函数)
  创建一个存储函数

        create or replace function queryempincome(eno in number)
return number
as
--定义变量保存月薪和奖金
psal emp.sal%type;
pcomm emp.comm%type;
begin
select sal,comm into psal,pcomm from emp where empno=eno; --返回年收入
return psal*+nvl(pcomm,);
end;
/

//原则,只有一个返回值使用存储函数,否则使用存储过程.

package(程序包)
  包头

        CREATE OR REPLACE PACKAGE MYPAKCAGE AS 

          type empcursor is ref cursor;
procedure queryEmpList(dno in number, empList out empcursor); END MYPAKCAGE;

  包体

        CREATE OR REPLACE PACKAGE BODY MYPAKCAGE AS

          procedure queryEmpList(dno in number, empList out empcursor) AS
BEGIN open empList for select * from emp where deptno=dno; END queryEmpList; END MYPAKCAGE;

trigger(触发器): 类似对insert,update,delete的监听器
  创建触发器:
    语句级触发器(每条语句操作一次,无论改变多少行)

        create trigger abcd
after/before insert/delete/update[of 列名]
on emp
declare
begin
dbms_output.put_line('成功操作了表格');
end;
/

    /*
    触发器应用一:实施复杂的安全性检查
    禁止在非工作时间插入新员工

    周末:to_char(sysdate,'day') in ('星期六','星期日')
    上班前 下班后:to_number(to_char(sysdate,'hh24')) not between 9 and 17
    */

        create or replace trigger securityemp
before insert
on emp
begin
if to_char(sysdate,'day') in ('星期六','星期日','星期三') or
to_number(to_char(sysdate,'hh24')) not between and then
--禁止insert
raise_application_error(-,'禁止在非工作时间插入新员工');
end if; end;
/

    行级触发器(每改变一行操作一次)

        create or replace trigger checksalary
before update
on emp
for each row //有此行就是行级触发器
begin
--if 涨后的薪水 < 涨前的薪水 then
if :new.sal < :old.sal then
raise_application_error(-,'涨后的工资不能少于涨前的工资。
涨前:'||:old.sal||' 涨后:'||:new.sal);
end if;
end;
/

Oracle 常用的十大 DDL 对象的更多相关文章

  1. 常用的十大Python开发工具

    据权威机构统计,Python人才需求量每日高达5000+,但目前市场上会 Python 的程序员少之又少, 竞争小,很容易快速高薪就业.可能你并不太了解常用的十大Python开发工具都有哪些,现在告诉 ...

  2. Charles常用的十大功能

    转载:http://www.jianshu.com/p/2745dbb97cc2 简介 Charles是在 Mac 下常用的网络封包截取工具,在做移动开发时,我们为了调试与服务器端的网络通讯协议,常常 ...

  3. 排序算法——(2)Python实现十大常用排序算法

    上期为大家讲解了排序算法常见的几个概念: 相关性:排序时是否需要比较元素 稳定性:相同元素排序后是否可能打乱 时间空间复杂度:随着元素增加时间和空间随之变化的函数 如果有遗忘的同学可以看排序算法——( ...

  4. Oracle 常用的SQL语法和数据对象

    一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……);  INSE ...

  5. Oracle 十大SQL语句

    oracle数据库十大SQL语句             操作对象(object) /*创建对象 table,view,procedure,trigger*/ create object object ...

  6. oracle使用dbms_metadata包取得所有对象DDL语句

    当我们想要查看某个表或者是表空间的DDL的时候,可以利用dbms_metadata.get_ddl这个包来查看. dbms_metadata包中的get_ddl函数详细参数 GET_DDL函数返回创建 ...

  7. SEO站长必备的十大常用搜索引擎高级指令

    作为一个seo人员,不懂得必要的搜索引擎高级指令,不是一个合格的seo.网站优化技术配合一些搜索引擎高级指令将使得优化工作变得简单.今日就和大家聊聊SEO站长必备的十大常用搜索引擎高级指令的那些事儿. ...

  8. PowerDesigner生成的ORACLE 建表脚本中去掉对象的双引号,设置大、小写

    原文:PowerDesigner生成的ORACLE 建表脚本中去掉对象的双引号,设置大.小写 若要将 CDM 中将 Entity的标识符都设为指定的大小写,则可以这么设定: 打开cdm的情况下,进入T ...

  9. Oracle常用命令大全(很有用,做笔记)

    一.ORACLE的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgrl ...

随机推荐

  1. Linux基础学习(10)--Shell基础

    第十章——Shell基础 一.Shell概述 1.Shell是什么: (1)Shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来 ...

  2. LR运行负载测试场景-笔记

    控制虚拟用户的行为:通用如图方式 查看用户的运行信息 在控制器释放前释放集合点用户 记录运行时注释---scenario-execution notes Vuser 对话框:初始化.运行.停止运行用户 ...

  3. 扩展运算符(spread)是三个点(…)

    扩展运算符(spread)是三个点(…),将一个数组||类数组||字符串转为用逗号分隔的序列. js中用来对数组进行操作,把数组里面的东西统统拿出来 一.展开数组 //展开数组 let a = [1, ...

  4. Oracle中保留两位小数

    在最近的项目开发中,有个业务需求是界面显示的数字需要保留两位小数,目前我想到的解决方法有两种: (1)在写SQL的时候,直接保留两位小数 (2)在java代码里面将查询出来的数进行格式化处理,保留两位 ...

  5. Data Science With R In Visual Studio

    R Projects Similar to Python, when we installed the data science tools we get an “R” section in our ...

  6. JSON 解析 (一)—— FastJSON的使用

    FastJSON是一个高性能.功能完善的json序列化和解析工具库,可使用Maven添加依赖 <dependency> <groupId>com.alibaba</gro ...

  7. HTML5-Audio-基础篇

    播放音频文件 //control属性添加播放.暂停和音量控件<audio controls> <source src="horse.ogg" type=" ...

  8. Typecho——简介及安装

    Typecho Typecho是由type和echo两个词合成的,来自于开发团队的头脑风暴.Typecho基于PHP5开发,支持多种数据库,是一款内核强健﹑扩展方便﹑体验友好﹑运行流畅的轻量级开源博客 ...

  9. .net MVC 访问404

    MVC 项目访问总是404 有几种情况: 1 地址打错了. 2 controller/action  但是action方法含有[ActionName("Index")] 重命名了. ...

  10. Vijos P1459 车展 (treap 任意区间中位数)

    题面: 描述 遥控车是在是太漂亮了,韵韵的好朋友都想来参观,所以游乐园决定举办m次车展.车库里共有n辆车,从左到右依次编号为1,2,…,n,每辆车都有一个展台.刚开始每个展台都有一个唯一的高度h[i] ...