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. macOS & USB stick

    macOS & USB stick why macOS can only read USB stick, can not write files to USB stick macos 无法写文 ...

  2. 老男孩python学习自修第九天【yield生成器】

    1.如果在一个方法中有yield关键字则该方法返回的是一个生成器对象 2.对生成器对象进行操作必须进行迭代或循环处理 例如: yield_test.py #!/usr/bin/env python # ...

  3. WampServer的安装和配置

    1.安装WampServer 启动时发现WampServer的图标是红色的,状态为put offline状态:发现无法put online,并报错could not found the menu it ...

  4. yii2的下载安装

    1.直接使用归档文件安装yii2的高级模板: 从 yiiframework.com 下载归档文件. 下载yii2的高级模板的压缩文件, 将yii-advanced-app-2.0.12文件夹复制到项目 ...

  5. 使用javaWeb的二大(Listener、Filter)组件实现分IP统计访问次数

    分析: 统计工作需要在所有资源之前都执行,那么就可以放到Filter中. 我们这个过滤器不打算做拦截操作!因为我们只是用来做统计 用什么东西来装载统计的数据.Map<String,Integer ...

  6. PCIE

    ---恢复内容开始--- 高速差分总线.串行总线 每一条PCIe链路中只能连接两个设备这两个设备互为是数据发送端和数据接收端.PCIe链路可以由多条Lane组成,目前PCIe链路×1.×2.×4.×8 ...

  7. .net core 2.0 数据访问-迁移

    将用于进行迁移的 Entity Framework Core NuGet包 添加到`.csproj`文件 <ItemGroup> <DotNetCliToolReference In ...

  8. chrome实用快捷键速记

    标签页和窗口快捷键 操作 快捷键 打开新窗口 Ctrl + n 无痕模式下打开新窗口 Ctrl + Shift + n 打开新的标签页,并跳转到该标签页 Ctrl + t 重新打开最后关闭的标签页,并 ...

  9. thymeleaf中js跳转到另外一个页面

    <script type="text/javascript"> setTimeout("location.href='index'", 3000); ...

  10. SQL中使用循环结构

    解答 FOR,LOOP,WHILE,REPEAT是UDB/400的一种内部循环控制,用于遍历表中符合条件的每一行记录. 例如:目的:更新employee库,把所有北京籍员工的工资提高10% 例一:使用 ...