重複搜索
這可以通過幾種方式來完成。這裏有一個例子:在搜索名稱的一部分
DEFINE TEMP-TABLE customer NO-UNDO
FIELD cusname AS CHARACTER
FIELD num AS INTEGER.
DEFINE VARIABLE compnum AS INTEGER NO-UNDO.
DEFINE VARIABLE compname AS CHARACTER NO-UNDO.
DEFINE QUERY qSearch FOR customer.
FORM compname compnum WITH FRAME f1.
/* Create some bogus data */
CREATE customer.
ASSIGN customer.cusname = "john doe"
customer.num = 1.
CREATE customer.
ASSIGN customer.cusname = "jane doe"
customer.num = 2.
CREATE customer.
ASSIGN customer.cusname = "name name"
customer.num = 3.
loop:
REPEAT:
CLEAR FRAME f2 ALL.
UPDATE compname compnum WITH FRAME f1.
/* Quit if neither name or number is entered */
IF compname = "" AND compnum = 0 THEN
LEAVE loop.
/* If num is entered - search by it, otherwise by name */
IF compnum <> 0 THEN DO:
OPEN QUERY qSearch FOR EACH customer NO-LOCK WHERE customer.num = compnum.
END.
ELSE DO:
OPEN QUERY qSearch FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*" + compname + "*".
END.
GET NEXT qSearch.
DO WHILE AVAILABLE customer:
IF AVAILABLE customer THEN DO:
DISPLAY customer WITH FRAME f2 10 DOWN.
DOWN WITH FRAME f2.
END.
GET NEXT qSearch.
END.
/* If we have results - leave the loop otherwise try again */
IF QUERY qSearch:NUM-RESULTS = 0 THEN
LEAVE loop.
END.
MESSAGE "Quitting" VIEW-AS ALERT-BOX.
有匹配的字符串一對夫婦經營的:
BEGINS
測試字符表情看如果該表達式以第二個字符表達式開頭。
語法:
expression1 BEGINS expression2
實施例:
FOR EACH customer WHERE NO-LOCK customer.cusname BEGINS "john":
MATCHES
比較的字符表達式的圖案,如果表達式滿足模式標準評估爲TRUE值。
模式可以包含通配符:特定位置的句號(。)表示任何單個字符在該位置都可以接受;星號(*)表示任何字符組都可以接受,包括空字符組。
語法:
expression1 MATCHES expression2
例子:
FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*doe*":
火柴聽起來像是你追求的,但被勸:比賽將不使用的數據庫索引使整個表將被掃描。這可能會影響性能,並可能使您的查詢花費很長時間。
WHERE子句用火柴上述替代將是這個樣子:
FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*" + compname + "*":
CONTAINS
還有一個被稱爲第三操作包含使用一種叫做字索引。這將要求您或您的DBA首先在數據庫中創建這些類型的索引。閱讀聯機幫助或在這裏找到的PDF文件,瞭解更多關於詞索引和CONTAINS的信息:Progress ABL Reference(第1004頁)。
CONTAINS可能比MATCHES更好,但也會要求您更改數據庫。
匹配和開始將查找值的結尾和開始部分。但我想檢索結果「John Smith Doe」,所以輸入可能是「John」,「Doe」,「Smith」,但我應該得到結果「John Smith Doe」。這是哪個操作符? – user3427690
BEGINS將尋找開始,MATCHES會尋找任何部分,如果你這樣做的話:field MATCHES「* doe *」 - 在開頭和結尾看到星號。如果你這樣做:字段匹配「約翰*」它將像BEGINS一樣工作(只匹配開頭) - 但仍然沒有索引。就像這樣:匹配只匹配結尾的「* smith」字段。我在上面的答案中增加了一個例子。 – Jensd
嘿,它有很大的幫助。它的工作原理:-) – user3427690