首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 平面设计 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Oracle频道
中国IT教育
Google
首页 入门基础 安装配置 体系架构 PLSQL 备份恢复 性能调优 开发技术 资讯动态 考试认证 下载 专题 讨论
您现在的位置: 中国IT实验室 >> Oracle >> 开发技术 >> 正文

两个Oracle存储过程程序分享

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

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

  SP_REPLACE_PROPERTY_VALUE('33392:118167;33393:107054;33391:118167','33393:107054

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

  33392:118167;33391:118167

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

  SP_REPLACE_PROPERTY_VALUE('33392:118167;33393:107054;33391:118167','33393:107054

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

  33392:118167;33393:100;33391:118167

第二个存储过程,检查相关属性对在目标属性串是否存在,常用于select查询语句(使用oracle提供的like查询会不准确)

create or replace function sp_exist_property(v_strpv varchar2,v_pv varchar2) return number
/*
creator:danchen
create_time:2008-4-20
function:检查v_pv在属性串v_strpv中是否全部存在
*/
as
type t_pvs is table of varchar2(50);
--保存分解后v_strpv
v_pvs t_pvs:=t_pvs();
--保存分解后v_pv
s_pvs t_pvs:=t_pvs();


--定义剩余属性字符串变量
last_pvs varchar2(200):='';
--临时属性变量
temp_pv varchar2(50);
--定义分号位置
fenhao_address number;


--定义比较结果,0不存在;1存在
v_check number;
v_result number;

begin
    if (v_strpv is null) or (v_pv is null) then
        return -1;
     end if;
    
     if instr(v_strpv,':')=0 or instr(v_pv,':')=0 then
         return -2;
     end if;
    
    
     --分解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;

  

上一页  [1] [2] [3] 下一页

【责编:Ken】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性…
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题…
 ·展现C#世界 C#程序设计专题…
 ·Java入门 Tomcat的配置技巧精华专题…
 ·Oracle RMAN物理备份技术详解…
 今日更新
 社区讨论
 博客论点
 频道精选
 Oracle频道相关导航