怎樣判斷畫布中有重復(fù)紀(jì)錄
2024-07-21 02:38:42
供稿:網(wǎng)友
由于when-validate-item 不能使用go_item(),first_record等,而when-new-item-instance卻答應(yīng),所以,可以這樣處理: 以基本表(id主鍵,name ,remark,20行每頁界面)
在id(主鍵)的下一導(dǎo)航項(xiàng),設(shè)置為check_uniqueness_button.
check_uniqueness_button為這個(gè)塊內(nèi)的一個(gè)按鈕,它的when-new-item-instance擔(dān)任檢查該行的重復(fù)情況的功能,代碼見本貼附錄。
另外,手工按check_uniqueness_button,也會(huì)執(zhí)行這段代碼,產(chǎn)生手工檢查重復(fù)情況的功能。
附錄代碼:
declare
temPRecord number;
tempval varchar2(20);
temp_count number :=0;
BEGIN
go_item('base_table.id');
temprecord := :system.cursor_record;
tempval := :base_table.id;
first_record;
if :system.current_value is not null then ---假如有記錄,開始運(yùn)算
loop
if :base_table.id = tempval and :system.cursor_record <> temprecord then
temp_count := temp_count + 1;
message('代碼有重復(fù),請(qǐng)檢查第:' :system.cursor_record
'行,代碼:' :base_table.id ',名稱:' :base_table.name);
message('代碼有重復(fù),請(qǐng)檢查第:' :system.cursor_record
'行,代碼:' :base_table.id ',名稱:' :base_table.name);
end if;
next_record;
if :system.current_value is null then
exit;
end if;
end loop;
if temp_count = 0 then
message('該行代碼沒有重復(fù)');
end if;
go_record(temprecord);
go_item('base_table.name');
else
message('光標(biāo)所有行沒有代碼為空,請(qǐng)先將光標(biāo)放在有數(shù)值的地方');
message('光標(biāo)所有行沒有代碼為空,請(qǐng)先將光標(biāo)放在有數(shù)值的地方');
end if;
END;
附錄
check_record_uniqueness 可以檢查一個(gè)數(shù)據(jù)塊(Data Block)內(nèi),主鍵有無重復(fù)的記錄。
使用方法舉例:
1.Block 上,先設(shè)定一個(gè)item是主鍵。
2。在主鍵字段的 when-validate-item trigger 上,加入如下代碼:
check_record_uniqueness;
if not form_sUCess then
clear message;
message(數(shù)據(jù)有重復(fù)!");
end if;
以上代碼,可以使用戶每輸入一條記錄時(shí),系統(tǒng)自動(dòng)檢查主鍵有無重復(fù)。
優(yōu)點(diǎn):速度快,代碼簡(jiǎn)單。
缺點(diǎn):只能應(yīng)用于主鍵。
最致命的缺點(diǎn):經(jīng)測(cè)試后我發(fā)現(xiàn),它只能檢查新輸入的數(shù)據(jù),與已存盤的數(shù)據(jù)有無重復(fù)。假如新輸入的記錄與未存盤的記錄重復(fù),它不會(huì)報(bào)警!
使用建議:
1。只可用于比較簡(jiǎn)單的場(chǎng)合,及用戶每次輸入的資料數(shù)目比較少的情況。假如用戶大批量輸入:如每次輸入幾十條,甚至上百條,使用check_record_uniqueness便會(huì)心驚膽跳了,因?yàn)檎l也不能保證 ,新輸入的數(shù)據(jù)內(nèi)會(huì)否有重復(fù)。
2。假如不是應(yīng)用于主鍵,假如每次用戶輸入量可能比較大,建議自行編寫查重復(fù)的代碼。