oracle_day5_程序包
---1创建一个程序包,完成如下要求:
--1:根据输入的商品编号,查找该商品价格和库存。
--2:根据输入的用户名称,获取该用户的订单信息
--3:获取当前时间的三天前时间
--4:查询当前时间的一周前时间
select sYSDATE-7 from DUAL;
create or replace package package01
is
procedure select_pro(vid number,info out sys_refcursor);
procedure select_orderinfo(vrelname VARCHAR2,oinfo out sys_refcursor);
function seltime1() return date;
function seltime2() return date;
end package01;
create or replace package body package01
is
procedure select_pro(vid number,info out sys_refcursor)
is
begin
open info for select price,stockcount from es_product where id=vid;
end;
procedure select_orderinfo(vrelname VARCHAR2,oinfo out sys_refcursor)
is
begin
open oinfo for
select es_order.* from
es_user,es_order
where es_user.id=es_order.user_id
and es_user.realname=vrelname;
end;
function seltime1 return date
is
dat1 date;
begin
select sysdate-3 into dat1 from DUAL;
return dat1 ;
end;
function seltime2 return date
is
dat2 date;
begin
select sYSDATE-7 into dat2 from DUAL;
return dat2;
end;
end package01;
----------------------------
declare
info sys_refcursor;
oinfo sys_refcursor;
vprice es_product.price%type;
vso es_product.stockcount%type;
vrelname es_user.realname%type;
orderinfo es_order%rowtype;
times1 date;
times2 date;
begin
package01.select_pro(1,info);
package01.select_orderinfo('张管',oinfo);
times1:=package01.seltime1();
times2:=package01.seltime2();
loop
fetch info into vprice,vso;
exit when info%notfound ;
dbms_output.put_line(vprice);
end loop;
loop
fetch oinfo into orderinfo;
exit when oinfo%notfound ;
dbms_output.put_line('订单编号:'||orderinfo.id||',下单人'||orderinfo.realname);
end loop;
dbms_output.put_line(to_char(times1,'yyyy-mm-dd hh24:mi.ss'));
dbms_output.put_line(to_char(times2,'yyyy-mm-dd hh24:mi.ss'));
end;
------------------------------------
-2 监控用户表的增删改操作,如果增加的
用户usertype为2要在监控表中做一个记录
如果删除usertype为2记录的用户,扔出系统异常不允许删除
如果修改usertype为2记录的用户,修改成普通用户,也需要在监控表中记录
create table jiank(
dec varchar2(100),
time date
)
create or replace trigger tri_userinfo
before update or delete or insert on es_user for each row
begin
if inserting then
insert into jiank values('记录添加',sysdate);
elsif deleting then
insert into jiank values('记录删除',sysdate);
elsif updating then
insert into jiank values('记录修改了',sysdate);
else
insert into jiank values('xxxx',sysdate);
end if;
end;
--------------------------------------
create table userlog
(
event varchar2(20),
descx varchar2(30),
dotime date
)
create trigger user_add_trig
after insert on es_user
for each row
begin
if :new.usertype=2 then
insert into userlog values ('insert','增加了一个管理员',sysdate);
end if;
end;
create trigger user_del_trig
after delete on es_user
for each row
begin
if :old.usertype=2 then
raise_application_error(-20010,'管理员不允许删');
end if;
end;
create trigger user_mod_trig
after update on es_user
for each row
begin
if :old.usertype=2 then
insert into userlog values ('update','修改管理员为其他用户',sysdate);
end if;
end;
------------------------------------------
insert into ES_USER (id, username, password, realname, tel, address, zip, email, usertype)
values (10, 'vipuser', 'vipuser', '陈红xxxx', '13801000104', '北京市中关村4号', '100100', 'hong_chen@aptech.com', 2);
update ES_USER set realname='ssss' where id=10;
delete from es_user where id=10
select * from es_user;
select * from jiank;
--3 创建一个学员表,并且为学员表创建一个序列,插入5条数据,主键值用序列的值
drop table stui;
create table stui(
id number(4) primary key,
name varchar2(100)
)
drop sequence st_seqss;
create sequence st_seqss
start with 1
increment by 1
;
declare
begin
for ind in 1..5 loop
insert into stui values(st_seqss.nextval,'sutdent');
end loop;
end;
truncate table stui;
select * from stui;
--4 在商品表的价格列上创建索引,在商品表的类型列上添加位图索引
drop index product_price_index;
create index index_product_price on es_product(price);
create bitmap index index_product_sort_id on ES_PRODUCT(sort_id);
select * from es_product;
--5 创建一个视图,显示商品名,价格,类型名,库存等
--5创建视图
create view product_viewx as
select t.name,t.stockcount,t.price,s.sortname from es_product t ,es_sort s
where t.sort_id= s.id
create trigger product_viewx_insert
instead of insert on product_viewx
declare
v_sortid number;
begin
--根据类别名查类别id
select id into v_sortid from es_sort t
where t.sortname=:new.sortname;
--插入商品表数据
insert into es_product(id,name,price,stockcount,sort_id)
values(product_seq.nextval,:new.name,:new.price,:new.stockcount,v_sortid);
end;
--------------------
create sequence product_seq start with 16
insert into product_viewx values('xx',55,5,'类别8')
oracle_day5_程序包相关推荐
- 【Golang源码分析】Go Web常用程序包gorilla/mux的使用与源码简析
目录[阅读时间:约10分钟] 一.概述 二.对比: gorilla/mux与net/http DefaultServeMux 三.简单使用 四.源码简析 1.NewRouter函数 2.HandleF ...
- 【ReactiveX】基于Golang pmlpml/RxGo程序包的二次开发
基于Golang pmlpml/RxGo程序包的二次开发[阅读时间:约20分钟] 一.ReactiveX & RxGo介绍 1.ReactiveX 2.RxGo 二.系统环境&项目介绍 ...
- 【golang程序包推荐分享】分享亿点点golang json操作及myJsonMarshal程序包开发的踩坑经历 :)
目录[阅读时间:约5分钟] 一.概述 1.Json的作用 2.Go官方 encoding/json 包 3. golang json的主要操作 二.Json Marshal:将数据编码成json字符串 ...
- 基于Golang的对象序列化的程序包开发——myJsonMarshal
基于Golang的对象序列化的程序包开发--myJsonMarshal[阅读时间:约10分钟] 一.对象序列化概述 二.系统环境&项目介绍 1.系统环境 2.项目的任务要求 三.具体程序设计及 ...
- 【golang程序包推荐分享】go-ini、viper、godoc
[golang程序包推荐&分享]go-ini.viper.godoc 一.go-ini 1.程序包简介 2.下载安装 3.简单使用[截取自官网] 二.viper 1.程序包简介 2.下载安装 ...
- 基于Golang的监听读取配置文件的程序包开发——simpleConfig_v1
基于Golang的监听&读取配置文件的程序包开发--simpleConfig_v1 [阅读时间:约10分钟] 一.配置文件概述 二.系统环境&项目介绍 1.系统环境 2.项目的任务要求 ...
- infopath java包_InfoPath 2013 修补程序包 (Ipeditor x none.msp) 的描述︰ 2014 年 4 月 8,...
修补程序信息 可以从 Microsoft 获得受支持的修复程序.然而,此修补程序仅用于解决本文中描述的问题.此修复程序仅适用于遇到本文中描述的问题的系统.此修补程序可能会接受进一步的测试.因此,如果这 ...
- C# 批处理制作静默安装程序包
使用批处理+WinRAR制作静默安装程序包 @echo 安装完窗口会自动关闭!!! @echo off start /wait Lync.exe /Install /Silent start /wai ...
- 用命令行工具创建 NuGet 程序包
NuGet.exe 下载地址 本文翻译自: https://docs.nuget.org/Create/Creating-and-Publishing-a-Package https://docs.n ...
最新文章
- HTML做frame跳转设置响应头,X-Frame-Options header响应头如何配置
- 用 Flask 来写个轻博客 (6) — (M)VC_models 的关系(one to many)
- 再见,xShell,自己用Java撸一个Web版的,网友直呼:666
- 从千团大战到网贷战国,烧钱千亿背后的底层用户增长逻辑
- 使用fullPage做的大图片全屏滚动
- oracle订单,银科软件:Oracle ERP订单管理模块详细介绍
- 图形学大神纯FPGA实现Doom游戏芯片,无CPU、无操作码、无指令计数器
- 大学计算机软件基础心得体会,学习计算机应用基础心得体会.doc
- 什么是Java中的原子操作( atomic operations)
- css3中transform-style的用法
- 斐讯路由器宽带运营商服务器,斐讯K2路由器的连接及上网设置教程
- 学位房如何查询学位真实性和户口是否被占用
- 优雅的git commit
- 计算机网络路由器和网关设置路由器,【计算机网络】网关和路由器功能的有哪些不同...
- 分享几个关于UG装配的小问题,干货满满!!!
- 移动APP持续交付系列之云构建价值分析
- android bitmap回收,android BitMap回收
- freetype的安装与使用
- python爬虫模拟有道翻译
- 学习node.js前所需储备知识