两个Oracle存储过程程序分享(2)
2015-08-28来源:易贤网

--分解v_strpv

last_pvs := v_strpv;

loop

fenhao_address := instr(last_pvs,';');

if fenhao_address=0 then

--没有找到分号,则为最后一组属性名:属性值;取出属性对

temp_pv := last_pvs;

v_pvs.extend;

v_pvs(v_pvs.last) := temp_pv;

--跳出循环

exit;

else

--取出属性对

temp_pv := substr(last_pvs,1,instr(last_pvs,';')-1);

--写入数组

v_pvs.extend;

v_pvs(v_pvs.last) := temp_pv;

--得到剩余的属性对

last_pvs := substr(last_pvs,instr(last_pvs,';')+1);

end if;

end loop;

--分解v_pv

last_pvs := v_pv;

loop

fenhao_address := instr(last_pvs,';');

if fenhao_address=0 then

--没有找到分号,则为最后一组属性名:属性值;取出属性对

temp_pv := last_pvs;

s_pvs.extend;

s_pvs(s_pvs.last) := temp_pv;

--跳出循环

exit;

else

--取出属性对

temp_pv := substr(last_pvs,1,instr(last_pvs,';')-1);

--写入数组

s_pvs.extend;

s_pvs(s_pvs.last) := temp_pv;

--得到剩余的属性对

last_pvs := substr(last_pvs,instr(last_pvs,';')+1);

end if;

end loop;

--检查是否存在

for i in 1..s_pvs.count loop

v_check := 0;

for j in 1..v_pvs.count loop

if v_pvs(j)=s_pvs(i) then

v_check := 1;

exit;

end if;

end loop;

--如果在本轮循环中,没有一次为真,则返回,不用再继续比较

if v_check=0 then

v_result := 0;

exit;

end if;

end loop;

--如果循环执行完

if v_check=1 then

v_result := 1;

end if;

--返回结果

return v_result;

end sp_exist_property;

第二个存储过程使用示例:

SQL> select sp_exist_property('33392:118167;33393:107054;33391:118167','1:118167') from dual;

SP_EXIST_PROPERTY('33392:118167;33393:107054;33391:118167','1:118167')

----------------------------------------------------------------------

0

SQL> select sp_exist_property('33392:118167;33393:107054;33391:118167','33393:107054') from dual;

SP_EXIST_PROPERTY('33392:118167;33393:107054;33391:118167','33393:107054')

--------------------------------------------------------------------------

1

SQL> select sp_exist_property('33392:118167;33393:107054;33391:118167','33392:118167;33393:107054') from dual;

SP_EXIST_PROPERTY('33392:118167;33393:107054;33391:118167','33392:118167;33393:1

--------------------------------------------------------------------------------

1

SQL> select sp_exist_property('33392:118167;33393:107054;33391:118167','33392:118167;33393:10705') from dual;

SP_EXIST_PROPERTY('33392:118167;33393:107054;33391:118167','33392:118167;33393:1

--------------------------------------------------------------------------------

0

SQL> select sp_exist_property('33392:118167;33393:107054;33391:118167','33392:118167;33391:118167') from dual;

SP_EXIST_PROPERTY('33392:118167;33393:107054;33391:118167','33392:118167;33391:1

--------------------------------------------------------------------------------

1

写程序是一种乐趣,平时应该多练练...

更多信息请查看IT技术专栏

推荐信息