判斷畫布中有重複紀錄

2022-07-21 06:27:09 字數 2628 閱讀 8069

臨時表解決:

情景:輸入條碼,需要從一資料來源a表查詢資料,將查詢結果顯示在基於line表的block上面。

假設block是基於表line,然後新建臨時表line_tmp,並新建唯一索引。

item:barcode 和 indate,其中barcode是條碼,indate是條碼之後緊接的乙個item。

新增資料 :

barcode(post-change):

先將條碼匹配的資料查詢出來,insert於line_tmp;

indate(when-new-item-instance):

這個觸發器每刷一次條碼就會觸發一次,且緊接著barcode(post-change)。

從line_tmp查詢資料,然後一行一行copy到block上。

在block級的post-insert或update後,delete臨時表line_tmp資料。

更改資料:

首先查詢出block資料,在post-query將block資料裝入臨時表。

重複上面新增資料的步驟。

以下**

由於when-validate-item 不能使用go_item(),first_record等,而when-new-item-instance卻允許,所以,可以這樣處理: 以基本表(id主鍵,name ,remark,20行每頁介面)

在id(主鍵)的下一導航項,設定為check_uniqueness_button.

check_uniqueness_button為這個塊內的乙個按鈕,它的when-new-item-instance擔任檢查該行的重複情況的功能,**見本貼附錄。

另外,手工按check_uniqueness_button,也會執行這段**,產生手工檢查重複情況的功能。

附錄**:

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  then  ---如果有記錄,開始運算

loop

if :base_table.id = tempval and :system.cursor_record <> temprecord then

temp_count := temp_count + 1;

message('**有重複,請檢查第:' || :system.cursor_record 

|| '行,**:'|| :base_table.id ||',名稱:' ||:base_table.name);

message('**有重複,請檢查第:' || :system.cursor_record 

|| '行,**:'|| :base_table.id ||',名稱:' ||:base_table.name);

end if;

next_record;

if :system.current_value is then

exit;

end if;  

end loop;

if temp_count = 0 then

message('該行**沒有重複');

end if;   

go_record(temprecord);

go_item('base_table.name');  

else

message('游標所有行沒有**為空,請先將游標放在有數值的地方');     

message('游標所有行沒有**為空,請先將游標放在有數值的地方');         

end if;

end;

附錄 check_record_uniqueness 可以檢查乙個資料塊(data block)內,主鍵有無重複的記錄。 

使用方法舉例: 

1.block 上,先設定乙個item是主鍵。 

2。在主鍵欄位的 when-validate-item trigger 上,加入如下**: 

check_record_uniqueness; 

if not form_sucess then 

clear message; 

message(資料有重複!"); 

end if; 

以上**,可以使使用者每輸入一條記錄時,系統自動檢查主鍵有無重複。 

優點:速度快,**簡單。 

缺點:只能應用於主鍵。 

最致命的缺點:經測試後發現,它只能檢查新輸入的資料,與已存檔的資料有無重複。如果新輸入的記錄與未存檔的記錄重複,它不會報警! 

使用建議: 

1。只可用於比較簡單的場合,及使用者每次輸入的資料數目比較少的情況。如果使用者大批量輸入:如每次輸入幾十條,甚至上百條,使用check_record_uniqueness便會心驚膽跳了,因為誰也不能保證 ,新輸入的資料內會否有重複。 

2。如果不是應用於主鍵,如果每次使用者輸入量可能比較大,建議自行編寫查重複的**

MySql插入不重複紀錄 不依據主鍵判斷

語法格式 insert select where not exist 例如 insert into student name select 張三 from dual where not exists select name from student where name 張三 這種方法其實就是使用了...

原地重複值判斷

題目 請設計乙個高效演算法,判斷陣列中是否有重複值。必須保證額外空間複雜度為o 1 給定乙個int陣列a及它的大小n,請返回它是否有重複值。思路 先將陣列原地排序,然後檢視是否有相鄰元素值相同。那麼能夠實現原地排序且時間複雜度小的是 非遞迴的堆排序。時間複雜度o nlogn 空間複雜度o 1 pub...

python 判斷列表重複

一 判斷單個列表中的元素是否存在重複 使用set方法去重後,和原list進行對比,如果相等,那麼說明原列表無重複,如果存在重複,說明列表存在重複 1 defis repect all l 2 repeatlist 3 setlist set l 4 flag true 5if len l len s...