次の例では、問合せprofilesの表にCTXRULE索引が関連付けられていることが前提となります。また、表newsfeedに分類対象の記事のセットが含まれていることも前提となります。
この例では、newsfeed表内をループし、MATCHES演算子を使用して各記事を分類します。結果は、results表に格納されます。
PROMPT Populate the category table based on newsfeed articles
PROMPT
set serveroutput on;
declare
mypk number;
mytitle varchar2(1000);
myarticles clob;
mycategory varchar2(100);
cursor doccur is select pk,title,articles from newsfeed;
cursor mycur is select category from profiles where matches(rule, myarticles)>0;
cursor rescur is select category, pk, title from results order by category,pk;
begin
dbms_output.enable(1000000);
open doccur;
loop
fetch doccur into mypk, mytitle, myarticles;
exit when doccur%notfound;
open mycur;
loop
fetch mycur into mycategory;
exit when mycur%notfound;
insert into results values(mycategory, mypk, mytitle);
end loop;
close mycur;
commit;
end loop;
close doccur;
commit;
end;
次の例では、分類された記事をカテゴリ別に表示します。
PROMPT display the list of articles for every category
PROMPT
set serveroutput on;
declare
mypk number;
mytitle varchar2(1000);
mycategory varchar2(100);
cursor catcur is select category from profiles order by category;
cursor rescur is select pk, title from results where category=mycategory order by pk;
begin
dbms_output.enable(1000000);
open catcur;
loop
fetch catcur into mycategory;
exit when catcur%notfound;
dbms_output.put_line('********** CATEGORY: '||mycategory||' *************');
open rescur;
loop
fetch rescur into mypk, mytitle;
exit when rescur%notfound;
dbms_output.put_line('** ('||mypk||'). '||mytitle);
end loop;
close rescur;
dbms_output.put_line('**');
dbms_output.put_line('*******************************************************');
end loop;
close catcur;
end;