一。存储过程的创建和使用
1.创建程序包,并在程序中创建存储过程
create or replace
PACKAGE NCS_ICP_TJ AS
/*
[email protected]*/
/* TODO 在此输入程序包声明 (类型, 异常错误, 方法等) */
/*根据备案主体ID拷贝通过表备案数据到备案临时表,拷贝5张*/
PROCEDURE ICP_PASS_TO_TEMP(
v_main_id IN icp_gn_temp_baxx_zt.ztid%TYPE,
v_lyd IN icp_gn_temp_baxx_zt.SJXT_ZTID%TYPE,
v_in_hmd IN icp_gn_temp_baxx_zt.in_hmd%TYPE,
v_czlb IN icp_gn_temp_baxx_zt.czlb%TYPE,
v_bajd IN icp_gn_temp_baxx_zt.bajd%TYPE
);
END NCS_ICP_TJ;
2.创建程序包包体,并在程序中创建存储过程实现
create or replace
PACKAGE BODY ncs_icp_tj AS
/*根据备案主体ID拷贝通过表备案数据到备案临时表,拷贝5张*/
PROCEDURE ICP_PASS_TO_TEMP(
v_main_id IN icp_gn_temp_baxx_zt.ztid%TYPE,
v_lyd IN icp_gn_temp_baxx_zt.SJXT_ZTID%TYPE,
v_in_hmd IN icp_gn_temp_baxx_zt.in_hmd%TYPE,
&nb
sp;v_czlb IN icp_gn_temp_baxx_zt.czlb%TYPE,
v_bajd IN icp_gn_temp_baxx_zt.bajd%TYPE
)
IS
v_lsh integer;
BEGIN
select SEQ_ICP_GN_TEMP_BAXX_ZT_ZTID.NEXTVAL into v_lsh from dual;
IF v_main_id IS NULL OR v_lyd IS NULL OR v_in_hmd IS NULL OR v_czlb IS NULL OR v_bajd IS NULL THEN
RAISE_APPLICATION_ERROR(-20000, 'Exsit null value in arguments.');
END IF;
/*所有插入的查询条件为主体ID*/
/* 插入主体*/
INSERT INTO ICP_GN_TEMP_BAXX_ZT
(LSH, BBDW,ZTID, SJXT_ZTID, YHM_ID, IN_HMD, CZLB, SCBBSJ, ZJXGSJ, DWMC, DWXZ, TZZ, ZJLX, ZJHM, SHENGID,
SHIID, XIANID, XXDZ, ZJZS,JYLX, WZFZR, WZFZR_ZJLX, WZFZR_ZJHM, WZFZR_DHHM, WZFZR_SJHM,
WZFZR_DZYJ, WZFZR_MSN, WZFZR_QQ, BAXH, BAJD, ZSYXQ, SHR_XM,
SHSJ, BZ, LRYHLX, LR_YHM_ID, BAMM)
SELECT
v_lsh, BBDW, v_main_id, SJXT_ZTID, YHM_ID, v_in_hmd/*是否在黑名单*/, v_czlb/*操作类别*/, SCBBSJ, ZJXGSJ, DWMC, DWXZ, TZZ, ZJLX, ZJHM, SHENGID,
SHIID, XIANID, XXDZ, ZJZS, JYLX,WZFZR, WZFZR_ZJLX, WZFZR_ZJHM, WZFZR_DHHM, WZFZR_SJHM,
WZFZR_DZYJ, WZFZR_MSN, WZFZR_QQ, BAXH,v_bajd/*备案阶段*/, ZSYXQ, SHR_XM,
SHSJ,BZ, LRYHLX, LR_YHM_ID, BAMM
FROM ICP_GN_BAXX_ZT WHERE ID = v_main_id;
/*插入网站*/
INSERT INTO ICP_GN_TEMP_BAXX_WZ
(LSH,BBDW,WZID, ZTID, SJXT_WZID, SCBBSJ, XGSJ, WZMC, SYURL, WZFZR, WZFZR_ZJLX, WZFZR_ZJHM, WZFZR_DHHM, WZFZR_SJHM, WZFZR_DZYJ, WZFZR_MSN, WZFZR_QQ, NRLX, FWNR, BAXH, LRYHLX, LR_YHM_ID, BAMM, BZ,BAJD)
SELECT
v_lsh,BBDW,id, v_main_id, SJXT_WZID, SCBBSJ, XGSJ, WZMC, SYURL, WZFZR, WZFZR_ZJLX, WZFZR_ZJHM, WZFZR_DHHM, WZFZR_SJHM, WZFZR_DZYJ, WZFZR_MSN, WZFZR_QQ, NRLX, FWNR, BAXH, LRYHLX, LR_YHM_ID, BAMM, BZ,1
FROM ICP_GN_BAXX_WZ
WHERE ZTID = v_main_id;
/*插入接入*/
INSERT INTO ICP_GN_TEMP_BAXX_JR
(lsh, bbdw,JRID, ZTID, WZID, SJXT_JRID, SSISP, WZFB, WZJRFS, LRYHLX, LR_YHM_ID, BAMM, bajd)
SELECT
v_lsh, bbdw,ID, v_main_id, WZID, SJXT_JRID, SSISP, WZFB, WZJRFS, LRYHLX, LR_YHM_ID, BAMM,v_bajd
FROM ICP_GN_BAXX_JR
WHERE ZTID =v_main_id;
/*插入IP*/
INSERT INTO ICP_GN_TEMP_BAXX_IPLB
(lsh,bbdw,IPID, ZTID, WZID, JRID, SJXT_IPID, QSIP, ZZIP)
SELECT v_lsh, bbdw,ID, v_main_id, WZID, JRID, SJXT_IPID, QSIP, ZZIP
FROM ICP_GN_BAXX_IPLB
WHERE ZTID= v_main_id;
/*插入域名*/
INSERT INTO ICP_GN_TEMP_BAXX_YMLB
(lsh, bbdw,YMID, ZTID, WZID, SJXT_YMID, YM)
SELECT
v_lsh, bbdw,ID, v_main_id, WZID, SJXT_YMID, YM
FROM ICP_GN_BAXX_YMLB
WHERE ZTID = v_main_id;
END ICP_PASS_TO_TEMP;
END ncs_icp_tj;
3. 调用存储过程,call ncs_icp_tj.icp_pass_to_temp(5,1,0,2,17)
本存储过程的调用,实现了从5张通过表复制数据到5张临时表
二,触发器的创建。
1.行级触发器,没插入一条数据执行一次, 向临时表中加入数据时,执行此触发器,把临时表插入到临时表的数据复制的日志表中
create or replace
TRIGGER TRIGGER_ICP_TEMP_ZT_INSERT
AFTER INSERT ON ICP_GN_TEMP_BAXX_ZT
FOR EACH ROW
BEGIN
insert into ICP_GN_BAXX_XGLS_ZT
(ID,LSH, BBDW,LS_ID,ZTID,SJXT_ZTID, DWMC, DWXZ, TZZ, ZJLX, ZJHM, SHENGID,
SHIID, XIANID, XXDZ, ZJZS,JYLX, WZFZR, WZFZR_ZJLX, WZFZR_ZJHM, WZFZR_DHHM, WZFZR_SJHM,
WZFZR_DZYJ, WZFZR_MSN, WZFZR_QQ, BAXH, SHR_XM,
SHSJ, BZ, LRYHLX, LR_YHM_ID, BAMM)
values(
SEQ_ICP_GN_BAXX_XGLS_ZT_ID.NEXTVAL,:new.LSH, :new.BBDW,:new.CZLB,:new.ZTID,:new.SJXT_ZTID, :new.DWMC, :new.DWXZ, :new.TZZ, :new.ZJLX, :new.ZJHM, :new.SHENGID,
:new.SHIID, :new.XIANID, :new.XXDZ, :new.ZJZS,:new.JYLX, :new.WZFZR, :new.WZFZR_ZJLX, :new.WZFZR_ZJHM, :new.WZFZR_DHHM, :new.WZFZR_SJHM,
:new.WZFZR_DZYJ, :new.WZFZR_MSN, :new.WZFZR_QQ, :new.BAXH, :new.SHR_XM,
:new.SHSJ, :new.BZ, :new.LRYHLX, :new.LR_YHM_ID, :new.BAMM);
END;
create or replace TRIGGER TRIGGER_ICP_TEMP_WZ_INSERT
AFTER INSERT ON ICP_GN_TEMP_BAXX_WZ
FOR EACH ROW
BEGIN
insert into ICP_GN_BAXX_XGLS_WZ
(ID,
LSH,BBDW,WZID, ZTID, SJXT_WZID, WZMC, SYURL,WZFZR, WZFZR_ZJLX, WZFZR_ZJHM, WZFZR_DHHM,
WZFZR_SJHM, WZFZR_DZYJ, WZFZR_MSN, WZFZR_QQ, NRLX, FWNR, BAXH, LRYHLX, LR_YHM_ID,BZ, ls_id)
values( SEQ_ICP_GN_BAXX_XGLS_WZ_ID.NEXTVAL,
:new.LSH,:new.BBDW,:new.WZID, :new.ZTID, :new.SJXT_WZID, :new.WZMC, :new.SYURL,:new.WZFZR, :new.WZFZR_ZJLX, :new.WZFZR_ZJHM, :new.WZFZR_DHHM,
:new.WZFZR_SJHM, :new.WZFZR_DZYJ, :new.WZFZR_MSN, :new.WZFZR_QQ, :new.NRLX, :new.FWNR, :new.BAXH, :new.LRYHLX, :new.LR_YHM_ID,:new.BZ,1);
END;
create or replace
TRIGGER TRIGGER_ICP_TEMP_JR_INSERT
AFTER INSERT ON ICP_GN_TEMP_BAXX_JR
FOR EACH ROW
BEGIN
insert into ICP_GN_BAXX_XGLS_JR
(ID,
lsh, bbdw,JRID, ZTID, WZID, SJXT_JRID, SSISP,
WZFB, WZJRFS, LRYHLX, LR_YHM_ID, ls_id
)
values (SEQ_ICP_GN_BAXX_XGLS_JR_ID.NEXTVAL,
:new.lsh, :new.bbdw,:new.JRID, :new.ZTID, :new.WZID, :new.SJXT_JRID, :new.SSISP,
:new.WZFB, :new.WZJRFS, :new.LRYHLX, :new.LR_YHM_ID,1);
END;
create or replace
TRIGGER TRIGGER_ICP_TEMP_IPLB_INSERT
AFTER INSERT ON ICP_GN_TEMP_BAXX_IPLB
FOR EACH ROW
BEGIN
insert into ICP_GN_BAXX_XGLS_IPLB
(ID,
lsh,bbdw,IPID, ZTID, WZID, JRID, SJXT_IPID, QSIP, ZZIP, ls_id
)
values( SEQ_ICP_GN_BAXX_XGLS_IPLB_ID.NEXTVAL,
:new.lsh,:new.bbdw,:new.IPID, :new.ZTID, :new.WZID, :new.JRID, :new.SJXT_IPID, :new.QSIP, :new.ZZIP,1);
END;
2.表级触发器 插入整个过程中,触发器只之行一次 ,当向AAA表中如入一条数据,将真个AAA表的数据复制BBB表
create or replace
TRIGGER TRIGGER_AAA_INSERT
AFTER INSERT ON AAA
BEGIN
insert into BBB(userid, username)
select id, username from AAA;
END;
ORACLE PL/SQL入门 (存储过程、触发器)转2009-08-10 13:27六、存储过程1.命令格式
存储过程是一个PL/SQL程序块,接受零个或多个参数作为输入(INPUT)或输出(OUTPUT)、或既作输入又作输出(INOUT),与函数不同,存储过程
没有返回值,存储过程不能由SQL语句直接使用,只能通过EXECUT命令或PL/SQL程序块内部调用,定义存储过程的语法如下:
PROCEDURE Name [(Parameter[,Parameter,])]
IS|AS
[Local Declarations]
BEGIN
Execute statements;
[EXCEPTION Exception Handlers]
END [Name];
2.调用
存储过程可以直接用EXECUT命令调用或PL/SQL程序块内部调用。用EXECUT命令调用存储过程的格式如下:
SQL>EXCUTE Proc_Name(par1, par2…);
存储过程也可以被另外的PL/SQL块调用,调用的语句是:
DECLARE par1, par2;
BEGIN
Proc_Name(par1, par2…);
END;
3.释放
当某个存储过程不再需要时,应将其从内存中删除,以释放它占用的内存资源。释放过程的语句格式如下:
SQL>DROP PROCEDURE Proc_Name;
4.实例:
编写存储过程,显示所指定雇员名所在的部门名和位置。
CREATE OR REPLACE PROCEDURE DeptMesg(pename emp.ename%TYPE,
pdname OUT dept.dname%TYPE,
ploc OUT dept.loc%TYPE) AS
BEGIN
SELECT dname, loc
INTO pdname, ploc
FROM emp, dept
WHERE emp.deptno = dept.deptno
AND emp.ename = pename;
END;
调用:
VARIABLE vdname VARCHAR2(14);
VARIABLE vloc VARCHAR2(13);
EXECUTE DeptMesg('SMITH', :vdname£? :vloc);
PRINT vdname vloc;
七、函数
1.命令格式
函数是命名了的、存储在数据库中的PL/SQL程序块。函数接受零个或多个输入参数,有一个返回值,返回值的数据类型在创建函数时定义。定
义函数的语法如下:
FUNCTION Name [{Parameter[,Parameter,])]
RETURN DataTypes
IS
[Local Declarations]
BEGIN
Execute Statements;
[EXCEPTION Exception Handlers]
END [Name];
2.调用
无论在命令行还是在程序语句中,函数都可以通过函数名称直接在表达式中调用。例如:将函数Count_Num(‘女’)的返回值赋予变量Man_Num
。
SQL>EXECUTE Man_Num := Count_Num('女');
3.释放
当函数不再使用时,要用DROP命令将其从内存中删除,例如:
SQL>DROP FUNCTION Count_Num;
4.实例
编写一个函数以显示该雇员在此组织中的工作天数。
CREATE OR REPLACE FUNCTION Hire_Day(no emp.empno%TYPE) RETURN NUMBER AS
vhiredate emp.hiredate%TYPE;
vday NUMBER;
BEGIN
SELECT hiredate INTO vhiredate FROM emp WHERE empno = no;
vday := CEIL(SYSDATE - vhiredate);
RETURN vday;
END;
八、触发器
1.触发器的创建规则:
①作用范围清晰;
②不要让触发器去完成Oracle后台已经能够完成的功能;
③限制触发器代码的行数;
④不要创建递归的触发器;
⑤触发器仅在被触发语句触发时进行集中的,全局的操作,同用户和数据库应用无关。
2.可以创建被如下语句所触发的触发器:
①DML语句(DELETE,INSERT,UPDATE);
②DDL语句(CREATE,ALTER, DROP);
③数据库操作(SERVERERROR,LOGON,LOGOFF,STARTUP,SHUTDOWN)。
3.注意事项
①触发器可以声明为在对记录进行操作之前,在之前(检查约束之前和 INSERT,UPDATE 或 DELETE 执行前)或之后(在检查约束之后和完成
INSERT, UPDATE 或 DELETE 操作)触发;
②一个 FOR EACH ROW 执行指定操作的触发器为操作修改的每一行都调用一次;
③SELECT 并不更改任何行,因此不能创建 SELECT 触发器.这种场合下规则和视图更适合;
④触发器和某一指定的表格有关,当该表格备删除时,任何与该表有关的触发器同样会被删除;
⑤在一个表上的每一个动作只能有一个触发器与之关联;
⑥在一个单独的表上,最多只能创建三个触发器与之关联,一个INSERT触发器,一个DELETE触发器和一个UPDATE触发器;
4.删除触发器的语句格式为:
DROP TRIGGER name ;
禁用触发器的语句格式为:
ALTER TRIGGER name DISABLE ;
启用触发器的语句格式为:
ALTER TRIGGER name ENABLE ;
一个触发器由三部分组成:触发事件或语句、触发限制和触发器动作。触发事件或语句是指引起激发触发器的SQL语句,可为对一指定表的
INSERT、UNPDATE或DELETE语句。触发限制是指定一个布尔表达式,当触发器激发时该布尔表达式是必须为真。触发器作为过程,是PL/SQL块,
当触发语句发出、触发限制计算为真时该过程被执行。
5.实例
编写一个数据库触发器,当任何时候某个部门从dept表中删除时,该触发器将从emp表中删除该部门的所有雇员。
CREATE OR REPLACE TRIGGER del_emp_deptno
BEFORE DELETE ON dept
FOR EACH ROW
BEGIN
DELETE FROM emp WHERE deptno = :OLD.deptno;
END;
九、包
1.包头
创建包头的语句格式如下:
CREATE PACKAGE<包名> IS
变量、常量及数据类型定义;
游标定义;
函数、过程定义和参数列表及返回类型;
END<包名>;
2.包体
创建包主体部分的语句格式如下:
CREATE PACKAGE BODY<包名>
AS
游标、函数、过程的具体定义;
END<包名>;
3.实例
包头代码:
--创建包头
CREATE PACKAGE test_package IS
--定义变量
man_num NUMBER;
woman_num NUMBER;
--定义游标
CURSOR学生;
--定义函数
CREATE FUNCTION f_count(in sex IN 学生.sex%TYPE)
--定义返回值类型
RETURN NUMBER;
--定义过程
CREATE PROCEDURE p_count(in_sex IN 学生.sex%TYPE, out_num OUT NUMBER);
--包头结束
END test_package;
包体代码:
--创建包体
CREATE PACKAGE BODY test_package AS
--游标具体定义
CURSOR 学生IS
SELECT 学号,姓名 FROM 学生 WHERE 学号 < 50;
--函数具体定义
FUNCTION f_count(in_sex IN学生.sex%TYPE)
--定义返回值类型
RETURN NUMBER IS
out_num NUMBER;
--函数体
BEGIN
IF in_sex = '男' THEN
SELECT count(sex) INTO out_num FROM 学生 WHERE性别='男';
ELSE
SELECT count(sex) INTO out_num FROM 学生 WHERE 性别='女';
END IF;
--返回函数值
RETURN(out_num);
--函数定义结束
END f_count;
--过程具体定义
PROCEDURE p_count(in_sex IN学生.sex%TYPE, out_num OUT NUMBER) AS
--过程体
BEGIN
IF in_sex = '男' THEN
SELECT count(sex) INTO out_num FROM 学生 WHERE性别 = '男';
ELSE
SELECT count(sex) INTO out_num FROM 学生 WHERE 性别= '女';
END IF;
--过程定义结束
END P_count;
--包体定义结束
END test_package;
ORACLE----触发器,存储过程及JOB
一、ORACLE中创建自增的ID字段
1、创建序列
create *sequence_name* increment by 1 start with 1 maxvalue 999999999;
2、创建触发器---(创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE)
create or replace trigger *triger_name*
before insert on *table_name*
referencing old as old new as new for each row
begin
select *sequence_name.nextval into :new.id from dual;
end;
/
二、ORACLE中JOB的应用
1、创建存储过程
create or replace procedure *pro_name
as
begin
insert into agri_exhibition_basecur (messid,title,type,pub_date) select id,title,sort,pub_date from agri_message where (trunc(sysdate-pub_date)=0 and rownum<6) and sort='供' ;
insert into agri_exhibition_basecur (messid,title,type,pub_date) select id,title,sort,pub_date from agri_message where (trunc(sysdate-pub_date)=0 and rownum<6) and sort='求' ;
end;
/
2、创建JOB
variable jobdxm number;
begin
dbms_job.submit(:jobdxm,'exhi_pro_dxm;',sysdate,'trunc(sysdate,''dd'')+32.5/24');
end;
三、收集的一个简单的JOB实列
1、创建测试表
SQL> create table a(a date);
表已创建。
2、创建一个自定义过程
SQL> create or replace procedure test as
2 begin
3 insert into a values(sysdate);
4 end;
5 /
过程已创建。
3、创建JOB
SQL> variable job1 number;
SQL>
SQL> begin
2 dbms_job.submit(:job1,'test;',sysdate,'sysdate+1/1440'); --每天1440分钟,即一分钟运行test过程一次
3 end;
4 /
PL/SQL 过程已成功完成。
4、运行JOB
SQL> begin
2 dbms_job.run(:job1);
3 end;
4 /
PL/SQL 过程已成功完成。
SQL> select to_char(a,'yyyy/mm/dd hh24:mi:ss') 时间 from a;
时间
-------------------
2001/01/07 23:51:21
2001/01/07 23:52:22
2001/01/07 23:53:24
5、删除JOB
SQL> begin
2 dbms_job.remove(:job1);
3 end;
4 /
PL/SQL 过程已成功完成。
6、一些必要的参数
修改initsid.ora参数
job_queue_processes = 4
job_queue_interval = 10
job_queue_keep_connections=true
修改可执行作业个数为20个
ALTER SYSTEM SET JOB_QUEUE_PROCESSES = 20
修改取消限制模式
ALTER SYSTEM DISABLE RESTRICTED SESSION;
7、两个必要的表
user_jobs及dba_jobs_running
8、相关的几个JOB操作
删除job:dbms_job.remove(jobno);
修改要执行的操作:job:dbms_job.what(jobno,what);
修改下次执行时间:dbms_job.next_date(job,next_date);
修改间隔时间:dbms_job.interval(job,interval);
停止job:dbms.broken(job,broken,nextdate);
启动job:dbms_job.run(jobno);
给你一个案例。。。看了你就懂了
CREATE OR REPLACE TRIGGER trg_dropdeny
BEFORE DROP OR TRUNCATE ON DATABASE
BEGIN
DECLARE
CURSOR tb_list IS
SELECT owner, name FROM not_drop_list;
BEGIN
FOR tb_rd IN tb_list LOOP
IF (lower(tb_rd.name) = 'alltables' or
lower(tb_rd.name) = lower(ora_dict_obj_name())) and
(lower(tb_rd.owner) = lower(ora_dict_obj_owner())) THEN
raise_application_error(num => -20000,
msg => '重要业务表,不允许drop和truncate');
END IF;
END LOOP;
END;
END;
收藏ORACLE中存储过程和触发器的两则实例(2008-07-19 12:49:38)标签:oracle trigger procedure 杂谈 分类:数据库技术
oracle中存储过程和触发器的写法和sql server中有很大的不同,这里阿堂就将公司同事在项目中用到一个存储过程和触发器拷贝过来,收藏起来,以后要用时,也好参考一下
存储过程
create or replace procedure CheckInventory
as
pPackType VARCHAR2(10);
pNumber NUMBER(9);
pExileNumber NUMBER(9); --缺少库存数量
pPackNumber NUMBER(9); --设置得数量箱/板
pPackageNum NUMBER(9); --需要补得箱/板数量
pTransNum NUMBER(9); --需要转仓得数量
InsertNum NUMBER(9); --插入转仓表得数量
Begin
--循环读出安全库存设置种设置得库位
Declare cursor LoadLocInventory is
select Storerkey,Sku,Qty from Locinventory;
pStorerKey VARCHAR2(50);
pSku VARCHAR2(50);
pSafeQty NUMBER(9); --安全库存的设置数量
realQty NUMBER(9);
begin
Open LoadLocInventory;
<<outer>>
LOOP
Fetch LoadLocInventory into pStorerKey,pSku,pSafeQty;
Exit WHEN LoadLocInventory%notfound;
--在实际库位中查找该库位(安全库位)上得数量
select sum(lotloc.qty) as realQty into realQty
from wh1.lotxlocxid lotloc--,wh1.lot lot,wh1.lotattribute lota
where lotloc.storerkey=pStorerKey
and lotloc.sku=pSku
and lotloc.loc like 'A%'
group by lotloc.storerkey,lotloc.sku;
if realQty<pSafeQty then
--读取包装设置信息里的包装数量
select PACKNUMBER into pPackNumber from packsetup
where SKU=pSku and STORERKEY=pStorerkey;
-------------------------------------------------------------------------------------------------------------------
pExileNumber:=pSafeQty-realQty; --pExileNumber缺少得数量
--求出需要转多少箱
--总数量 箱数 每箱得数量
pTransNum:=pExileNumber;--pPackageNum*pPackNumber;
--FIFO得游标,用来提取非安全库存中库位得数量 --还要按照lottable04的状态
Declare cursor FIFOLocInventory is
select lotloc.Loc,lotloc.storerkey,lotloc.sku,sum(lotloc.qty) as qty,
lotloc.id,lotattribute.lottable06,lotattribute.lottable02,
lotattribute.lottable03,lotattribute.lottable04,lotattribute.lottable05,
lotattribute.lottable10
FROM wh1.lotxlocxid lotloc,wh1.lotattribute
where lotloc.lot=lotattribute.lot
and lotloc.loc not like 'A%'
and lotattribute.lottable09 in ('VENDOR','OFF')
and lotattribute.lottable07 = 'LIPC'
and lotloc.sku=pSku
and to_char(lotattribute.lottable04,'yyyy-mm-dd')='2001-01-01'
and lotloc.storerkey=pStorerkey
and lotloc.qty<>0
group by lotloc.lot,lotloc.Loc,lotloc.storerkey,lotloc.sku,lotloc.ID,
lotattribute.lottable06,lotattribute.lottable02,lotattribute.lottable03,
lotattribute.lottable04,lotattribute.lottable05,lotattribute.lottable10
order by lotattribute.lottable05 ;
FIFOLoc wh1.lotxlocxid.loc%type;
FIFOStorerkey wh1.lotxlocxid.storerkey%type;
FIFOSku wh1.lotxlocxid.sku%type;
FIFOQty wh1.lotxlocxid.qty%type;
FIFOPickKey wh1.lotxlocxid.id%type;
FIFOLottable06 wh1.lotattribute.lottable06%type;
FIFOLottable02 wh1.lotattribute.lottable02%type;
FIFOLottable03 wh1.lotattribute.lottable03%type;
FIFOLottable04 wh1.lotattribute.lottable04%type;
FIFOLottable05 wh1.lotattribute.lottable05%type;
FIFOLottable10 wh1.lotattribute.lottable10%type;
begin
open FIFOLocInventory;
<<inter>>
LOOP
Fetch FIFOLocInventory into FIFOLoc,FIFOStorerkey,FIFOSku,FIFOQty,
FIFOPickKey,FIFOLottable06,FIFOLottable02,
FIFOLottable03,FIFOLottable04,FIFOLottable05,
FIFOLottable10;
Exit WHEN FIFOLocInventory%notfound;
if pSku='42W2776' then
DBMS_OUTPUT.PUT_LINE('fds');
end if ;
--如果需要转的数量大于游标没次提取出来的数量,则插入游标提取出来的数量
--单批计划也要满足板/箱得整数倍原则
if pTransNum>FIFOQty then
InsertNum:=FIFOQty;
end if ;
if pTransNum<FIFOQty then
pPackageNum:=trunc(pTransNum/pPackNumber);
if mod(pTransNum,pPackNumber)>0 then
pPackageNum:=pPackageNum+1;
end if;
InsertNum:=pPackageNum*pPackNumber;
end if;
if InsertNum>FIFOQty then
InsertNum:=FIFOQty;
end if;
if InsertNum=0 then exit inter; end if;
insert into transwhinventory(STORERKEY,SKU,Vendor,Loc,Qty,REALQTY,SAFEQTY,DIVERSITYQTY,Pickkey,Lottable02,
lottable03,lottable04,lottable05,lottable10,Create_Date)
values(FIFOStorerkey,FIFOSku,FIFOLottable06,FIFOLoc,InsertNum,realQty,pSafeQty,pExileNumber,FIFOPickKey,
FIFOLottable02,FIFOLottable03,to_char(FIFOLottable04,'yyyy-mm-dd'),to_char(FIFOLottable05,'yyyy-mm-dd'),
FIFOLottable10,to_date(to_char(sysdate, 'yyyy-mm-dd'),'yyyy-mm-dd'));
Commit;
pTransNum:=pTransNum-InsertNum;
if pTransNum<0 then exit inter; end if;
end LOOP inter;
Close FIFOLocInventory;
end;
end if;
END LOOP outer;
Close LoadLocInventory;
end;
end;
触发器
create or replace trigger tri_tynex_weight_info
before insert on tynex_weight_info
for each row
declare
new_id int;
begin
select SEQ_TYNEX_WEIGHT_INFO_ID.NEXTVAL into new_id from dual;
:New.inter_id := new_id;
:New.create_date := sysdate;
:New.create_by := 'SYSTEM';
end;