Oracle Apex的“选择列表”中的条件语句

时间:2019-06-13 17:48:55

标签: sql oracle plsql oracle-apex

我想在Oracle apex的选择列表中有一个条件语句。但是,我遇到各种错误。我尝试过同时使用IF和CASE。 请指导。 这是我目前正在尝试使用的代码:

IF :P126_CHECK_SALESPERSON_FLAG='Y' THEN 
 SELECT SALES_PERS_NAME d,SALES_PERS_ID r
 FROM
(SELECT SALES_PERS_ID,
DLR_ID,
SALES_PERS_EMP_ID,
SALES_PERS_NAME,
OEM_CODE,
ROW_NUMBER() OVER(PARTITION BY SALES_PERS_EMP_ID, SALES_PERS_NAME, 
OEM_CODE ORDER BY OEM_CODE) SR
FROM SALES_PERSON_DIM
WHERE (OEM_CODE = :P126_DEALERSHIP_CODE OR :P126_DEALERSHIP_CODE IS NULL 
  )
    AND SALES_PERSON_ACTIVE_FLG='Y')
 WHERE SR=1
  AND SALES_PERS_NAME  is not null
   ORDER BY 1;

ELSIF :P126_CHECK_SALESPERSON_FLAG='N' THEN
SELECT * from(SELECT SALES_PERS_NAME d,
SALES_PERS_ID r
FROM
(SELECT SALES_PERS_ID,
DLR_ID,
SALES_PERS_EMP_ID,
SALES_PERS_NAME,
OEM_CODE,
ROW_NUMBER() OVER(PARTITION BY SALES_PERS_EMP_ID, SALES_PERS_NAME, 
 OEM_CODE ORDER BY OEM_CODE) SR
FROM SALES_PERSON_DIM
WHERE (OEM_CODE = :P126_DEALERSHIP_CODE OR :P126_DEALERSHIP_CODE IS NULL 
   )
AND SALES_PERSON_ACTIVE_FLG='Y')
WHERE SR=1
AND SALES_PERS_NAME is not null
ORDER BY 1)
UNION
SELECT CFL_RESPONSIBLE_PERSON,
SALES_PERS_ID
FROM CUSTOMER_FOLLOWUPS
WHERE  CFL_ID= :P126_CFL_ID
AND CUST_ID = :P126_CUST_ID;
 END IF;

1 个答案:

答案 0 :(得分:0)

例如

SELECT SALES_PERS_NAME d,SALES_PERS_ID r
 FROM
(SELECT SALES_PERS_ID,
DLR_ID,
SALES_PERS_EMP_ID,
SALES_PERS_NAME,
OEM_CODE,
ROW_NUMBER() OVER(PARTITION BY SALES_PERS_EMP_ID, SALES_PERS_NAME, 
OEM_CODE ORDER BY OEM_CODE) SR
FROM SALES_PERSON_DIM
WHERE (OEM_CODE = :P126_DEALERSHIP_CODE OR :P126_DEALERSHIP_CODE IS NULL 
  )
    AND SALES_PERSON_ACTIVE_FLG='Y')
 WHERE SR=1
  AND SALES_PERS_NAME  is not null

AND :P126_CHECK_SALESPERSON_FLAG='Y'
    union 

SELECT * from(SELECT SALES_PERS_NAME d,
SALES_PERS_ID r
FROM
(SELECT SALES_PERS_ID,
DLR_ID,
SALES_PERS_EMP_ID,
SALES_PERS_NAME,
OEM_CODE,
ROW_NUMBER() OVER(PARTITION BY SALES_PERS_EMP_ID, SALES_PERS_NAME, 
 OEM_CODE ORDER BY OEM_CODE) SR
FROM SALES_PERSON_DIM
WHERE (OEM_CODE = :P126_DEALERSHIP_CODE OR :P126_DEALERSHIP_CODE IS NULL 
   )
AND SALES_PERSON_ACTIVE_FLG='Y')
WHERE SR=1
AND SALES_PERS_NAME is not null
ORDER BY 1)
UNION
SELECT CFL_RESPONSIBLE_PERSON,
SALES_PERS_ID
FROM CUSTOMER_FOLLOWUPS
WHERE  CFL_ID= :P126_CFL_ID
AND CUST_ID = :P126_CUST_ID

AND :P126_CHECK_SALESPERSON_FLAG='N'