项目实战应用——根据父资源库分类属性修改子资源库分类的属性

整体要求:
1、先查询出父资源库分类的所有资源库属性元数据
2、然后再查询出父资源库分类的所有子资源库分类
3、最后将子分类中没有而父分类中有的资源库属性元数据插入到子资源库分类中

declare

--定义可以利用的资源库分类属性元数据值主键id
var_com_meta_value_id communitymetavalue.com_meta_value_id%type;--(最小值:17,最大值:521)
--定义临时最大place
var_max_place number;
--定义查询数量,用于判断是否存在
var_exists_count number;
--定义临时的资源库分类属性元数据field的id
var_com_meta_field_id communitymetavalue.community_mete_field_id%type;
--定义临时的资源库分类属性的值
var_com_meta_field_value communitymetavalue.text_value%type;
--定义临时community_id
var_community_id community.community_id%type;

var_number number;



--定义游标

--查询资源库分类的所有属性
cursor com_meta_cursor is
select comval.* from communitymetavalue comval
join communitymetadesc comdes on comdes.community_mete_field_id = comval.community_mete_field_id
where comval.object_id = 'sjk' and comval.object_type = 'community';
com_all_meta_record com_meta_cursor%rowtype;

--查询资源库分类的直接子资源库分类
cursor child_community_cursor is
select com.community_id from community com
join community2community c2c on c2c.parent_community_id = 'sjk' and c2c.community_id = com.community_id
where com.withdrawn = 'N';


type temp_table_type is table of com_all_meta_record%type   
index by binary_integer;   
temp_table temp_table_type; 


begin
var_number:=1;
--初始化var_com_meta_value_id
var_com_meta_value_id:='17';

open com_meta_cursor;
loop
fetch com_meta_cursor into com_all_meta_record;
  exit when com_meta_cursor%notfound;
  temp_table(var_number):=com_all_meta_record;
  var_number:=var_number+1; 
end loop;
close com_meta_cursor;



--循环资源库子分类
open child_community_cursor;
loop
fetch child_community_cursor into var_community_id;
      --查询数据库分类最大的place
      select max(comval.place) into var_max_place from communitymetavalue comval
      where comval.object_id = var_community_id and comval.object_type = 'community';
      for i in 1..temp_table.count loop                
          --var_max_place加1,var_com_meta_value_id加1
          var_max_place:=var_max_place+1;
          var_com_meta_value_id:=to_char(to_number(var_com_meta_value_id)+1);
          --查询该属性是否存在
          select count(1) into var_exists_count
          from communitymetavalue 
          where communitymetavalue.object_id = var_community_id and communitymetavalue.object_type = 'community'
          and communitymetavalue.community_mete_field_id = var_com_meta_field_id;
          if var_exists_count <= 0
          then
          --给数据库分类增加属性
          dbms_output.put_line('insert into communitymetavalue (com_meta_value_id, community_id, community_mete_field_id, text_value, text_lang, place, is_set, community_type_id, object_id, object_type) values('''||var_com_meta_value_id||''', '''||var_community_id||''', '''||temp_table(i).community_mete_field_id||''', '''||temp_table(i).text_value||''', '''', '||var_max_place||', ''0'', ''rwsk'', '''||var_community_id||''', ''community'');');
          end if;
      end loop;
--当游标找不到数据时,退出
exit when child_community_cursor%notfound;
end loop;

--关闭游标
close child_community_cursor;
end;

初学Oracle,还请大虾们多多指教!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值