oracle 创建简单的函数

本文介绍了一个用于在数据库中实现目录上下移动的功能函数。该函数通过更新多个表中的对象ID来完成目录位置的更改,并包含了异常处理机制。
CREATE OR REPLACE FUNCTION hello
/**********************************************************
Author : fuqiang WX155924
Version : v1.00
Date : 2013-01-06
Description : 目录上下移动
******************************************************/
(i_source_objid IN VARCHAR2, -- 原目录objectid
i_tag_objid IN VARCHAR2 -- 要移动到得目标objectid
-- o_resulet out number
) RETURN INT AS -- 迁移是否成功 1:失败 0:成功

v_sourcePid VARCHAR2(30); -- 源目录的Pid
v_tagpid VARCHAR2(30); --目标目录的Pid
BEGIN
-- 入口参数判断
IF i_source_objid IS NULL OR i_tag_objid IS NULL THEN
RETURN 1;
END IF;
-- 存储他们各自的pid

select category.parentid
into v_sourcePid
from T_CMP_TYPE_CATEGORY category
where category.objectid = i_source_objid;

select category.parentid
into v_tagpid
from T_CMP_TYPE_CATEGORY category
where category.objectid = i_tag_objid;

if v_sourcePid = v_tagpid then
RETURN (1);
end if;

--上移的时候 i_source_objid > i_tag_objid

if i_source_objid > i_tag_objid then
------------------------ 更新 T_CMP_TYPE_CATEGORY ----------------------
--(源目录)
update T_CMP_TYPE_CATEGORY t
set t.objectid = i_tag_objid
where t.parentid = v_sourcePid
and t.objectid = i_source_objid;
--(目标目录)
update T_CMP_TYPE_CATEGORY t
set t.objectid = i_source_objid
where t.parentid = v_sourcePid
and t.objectid = i_tag_objid;

------------------------ 更新 T_CMP_EXT_MEDIACATEGORY ----------------------
--(源目录)
update T_CMP_EXT_MEDIACATEGORY t
set t.objectid = i_tag_objid
where t.objectid = i_source_objid;
--更新(目标目录)
update T_CMP_EXT_MEDIACATEGORY t
set t.objectid = i_source_objid
where t.objectid = i_tag_objid;

------------------------ 更新 T_CMP_TYPE_MEDIACATEGORY ----------------------
-- (源目录)
update T_CMP_TYPE_MEDIACATEGORY t
set t.objectid = i_tag_objid
where t.objectid = i_source_objid;
--(目标目录)
update T_CMP_TYPE_MEDIACATEGORY t
set t.objectid = i_source_objid
where t.objectid = i_tag_objid;

------------------------ 更新 mdsp_t_categoryinfo ------------------------
-- (源目录)
update mdsp_t_categoryinfo t
set t.objectid = i_tag_objid
where t.objectid = i_source_objid;
--(目标目录)
update mdsp_t_categoryinfo t
set t.objectid = i_source_objid
where t.objectid = i_tag_objid;

RETURN 0;

end if;

EXCEPTION
WHEN OTHERS THEN
RETURN 2;


END hello;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值