什么是SELECT IN语句的ABL等效项

时间:2014-10-28 12:00:42

标签: progress-4gl

任何人都可以帮助我获得SELECT IN语句的ABL等价物 例如,

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);

5 个答案:

答案 0 :(得分:2)

OR显然是最简单的,但由于这被认为是不可接受的,或许这可以满足需要?

define variable i as integer no-undo.
define variable n as integer no-undo.
define variable cityList as character no-undo.

cityList = "boston,new york,chicago,...".

n = num-entries( cityList ).
do for i = 1 to n:
  for each customer no-lock where city = entry( i, cityList ):
    display customer.name customer.city.
  end.
end.

这将避免表扫描并且与OR一样有效,因为字段比较是相等匹配。

答案 1 :(得分:1)

Progress 4GL / ABL中没有内置的IN运算符。您可以使用OR运算符来实现此目的。一个例子:

FOR EACH customer WHERE city = 'boston' OR city = 'salo' OR city = 'paris':
        DISP customer.NAME.
END.

答案 2 :(得分:1)

正如Austin所说:你可以使用OR。

我将尝试详细说明这一点:使用动态查询可以创建比简单的“FOR EACH”更灵活的方法 - 就像每次运行查询时都有不同数量的OR语句一样。

一个快速而又肮脏的例子:

/* Definitions */
DEFINE VARIABLE cQuery       AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cInString    AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cOrStatement AS CHARACTER   NO-UNDO.
DEFINE VARIABLE iEntry       AS INTEGER     NO-UNDO.

/* Defining a temp-table to query */
DEFINE TEMP-TABLE client
    FIELD clientId AS INTEGER
    FIELD city     AS CHARACTER.

/* And a query */
DEFINE QUERY qClient FOR client.

/* Create some bogus data */
CREATE client.
ASSIGN 
    client.clientId = 1
    client.city     = "Rome".

CREATE client.
ASSIGN 
    client.clientId = 2
    client.city     = "Barcelona".

CREATE client.
ASSIGN 
    client.clientId = 3
    client.city     = "Paris".

CREATE client.
ASSIGN 
    client.clientId = 4
    client.city     = "Prague".

/* These are the cities we are searching for */
cInString = "Rome,Stockholm,Prague".

/* Convert the comma-separated list of cities to an "OR-statement" */
DO iEntry = 1 TO NUM-ENTRIES(cInString):
    cOrStatement = cOrStatement + (IF cOrStatement = "" THEN "" ELSE " OR ") + "client.city = " + QUOTER(ENTRY(iEntry,cInString)).
END.

/* Add () around the or-statement just to be sure */
cOrStatement = "(" + cOrStatement + ")".

/* Put together the query */
cQuery = "FOR EACH client WHERE " + cOrStatement.

/* Attach the query-string to the query */
QUERY qClient:QUERY-PREPARE(cQuery).

/* Open the query ...*/
QUERY qClient:QUERY-OPEN().

/* And get the first result */
GET FIRST qClient.

/* Iterate through results as long as there are any... */
DO WHILE AVAILABLE client:
    DISP client WITH FRAME x1 10 DOWN.

    DOWN WITH FRAME x1.
    GET NEXT qClient.
END.

/* Close query */
QUERY qClient:QUERY-CLOSE().

答案 3 :(得分:1)

CAN-DO功能

* Returns TRUE if a character value exists in a comma-delimited list; otherwise returns FALSE
* Use the CAN-DO function instead of stringing many OR conditions together
* Example

      IF CAN-DO(“A,B,C,D",x) THEN MESSAGE “Value is in set”.

答案 4 :(得分:0)

您可以使用LOOKUP这样的功能:

DEFINE VARIABLE wc-liste AS CHARACTER  NO-UNDO.
DEFINE VARIABLE wc-sep   AS CHARACTER  NO-UNDO.

wc-sep = ",".

wc-liste = value1 + wc-sep + value2 + wc-sep + value3...

FOR EACH table_name
    WHERE LOOKUP(table_name.column_name, wc-liste, wc-sep) > 0
    NO-LOCK:
    ...
END.

但这对于性能不是一个好主意。

你也可以试试这个:

bcle:
FOR EACH table_name
    NO-LOCK:
    IF LOOKUP(table_name.column_name, wc-liste, wc-sep) = 0 
    THEN 
        NEXT bcle.
    ...
END.