1

我在将创建的函数中的参数传递到“Where”子句中的 SQL*Plus“Select”语句时遇到问题。但是,在这种“Where”子句的情况下,我使用的任何语法似乎都不正确或根本不使用。

这是我创建的函数,它看起来可以编译并运行良好:

CREATE OR REPLACE FUNCTION SA_BILL_CNTRL_EXTRNL_FXN(p_client_code      VARCHAR2
                                                   ,p_bill_seq         VARCHAR2
                                                   ,p_bill_control_seq VARCHAR2)
  RETURN VARCHAR2 IS
  v_external_id      VARCHAR2(30);
  v_client_code      VARCHAR2(4) := p_client_code;
  v_bill_seq         NUMBER := to_number(p_bill_seq);
  v_bill_control_seq NUMBER := to_number(p_bill_control_seq);
  v_cnt              NUMBER;
BEGIN
  SELECT COUNT(*)
  INTO v_cnt
  FROM BillControl@SQL_SAREP bc
  WHERE bc."ExternalID" IS NOT NULL
        AND bc."ExternalID" != ''
        AND bc."ClientCode" = p_client_code
        AND bc."BillControlSeq" = v_bill_control_seq
        AND bc."BillSeq" = v_bill_seq;
  IF v_cnt = 1 THEN
    SELECT bc."ExternalID"
    INTO v_external_id
    FROM BillControl@SQL_SAREP bc
    WHERE bc."ExternalID" IS NOT NULL
          AND bc."ExternalID" != ''
          AND bc."ClientCode" = p_client_code
          AND bc."BillControlSeq" = v_bill_control_seq
          AND bc."BillSeq" = v_bill_seq;
  ELSE
    v_external_id := NULL;
  END IF;
  RETURN v_external_id;
END SA_BILL_CNTRL_EXTRNL_FNX;
/

此外,当我在函数中使用“IN OUT”参数时,它在运行后失败。

现在,这是我在传递参数时遇到困难的“选择”语句:

SELECT NVL(TRIM(eb.CASE_NUM_REEVALUATED), TRIM(eb.CASE_NUM_DUPLICATED)) CaseNumReev
      ,gnc.BILL_CONTROL_SEQ
FROM EPE_Bill eb NETWORK_CROSSWALK gnc
WHERE substr(eb.MIC_BILL_ID, 5, 4) = SA_BILL_CNTRL_EXTRNL_FNX(p_client_code)
      AND gnc.BILL_CONTROL_SEQ = SA_BILL_CNTRL_EXTRNL_FNX(p_bill_seq) 
      AND (to_number(substr(eb.MIC_BILL_ID, 10, 10), '9999999999') = SA_BILL_CNTRL_EXTRNL_FNX(p_bill_control_seq) 
GROUP BY CaseNumReev, gnc.BILL_CONTROL_SEQ;

在过去的两天里,我完全被弄糊涂了。有了这个,如果你能帮助我解决问题,我将不胜感激。

再次感谢...

4

1 回答 1

1

试试下面的函数,我也做了一个假设,因为你只传递一个参数,其余的必须是 NULL

CREATE OR REPLACE FUNCTION SA_BILL_CNTRL_EXTRNL_FXN(p_client_code IN VARCHAR2 DEFAULT NULL                                               
                                               ,p_bill_seq     IN    VARCHAR2 DEFAULT NULL
                                               ,p_bill_control_seq IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2 IS
v_external_id      VARCHAR2(4000);
v_client_code      VARCHAR2(4) := p_client_code;
v_bill_seq         NUMBER := to_number(p_bill_seq);
v_bill_control_seq NUMBER := to_number(p_bill_control_seq);
v_cnt              NUMBER;
BEGIN
     SELECT COUNT(*)
     INTO v_cnt
     FROM BillControl@SQL_SAREP bc
     WHERE bc."ExternalID" IS NOT NULL
     AND bc."ExternalID" != ''
     AND bc."ClientCode" = NVL(p_client_code,bc."ClientCode")
     AND bc."BillControlSeq" = NVL(v_bill_control_seq,bc."BillControlSeq")
     AND bc."BillSeq" = NVL(v_bill_seq,bc."BillSeq");
   IF v_cnt = 1 THEN
      SELECT bc."ExternalID"
      INTO v_external_id
      FROM BillControl@SQL_SAREP bc
      WHERE bc."ExternalID" IS NOT NULL
      AND bc."ExternalID" != ''
      AND bc."ClientCode" = NVL(p_client_code,bc."ClientCode")
      AND bc."BillControlSeq" = NVL(v_bill_control_seq,bc."BillControlSeq")
      AND bc."BillSeq" = NVL(v_bill_seq,bc."BillSeq");
  ELSE
     v_external_id := NULL;
  END IF;
       RETURN v_external_id;
END SA_BILL_CNTRL_EXTRNL_FNX;
/

你的 SQL 应该是

SELECT REC.CaseNumReev,REC.BILL_CONTROL_SEQ FROM
(
 SELECT NVL(TRIM(eb.CASE_NUM_REEVALUATED), TRIM(eb.CASE_NUM_DUPLICATED)) CaseNumReev
  ,gnc.BILL_CONTROL_SEQ AS BILL_CONTROL_SEQ
 FROM EPE_Bill eb ,NETWORK_CROSSWALK gnc
 WHERE substr(eb.MIC_BILL_ID, 5, 4) = SA_BILL_CNTRL_EXTRNL_FNX(p_client_code)
 AND gnc.BILL_CONTROL_SEQ = SA_BILL_CNTRL_EXTRNL_FNX(p_bill_seq) 
 AND (to_number(substr(eb.MIC_BILL_ID, 10, 10), '9999999999')     =SA_BILL_CNTRL_EXTRNL_FNX(p_bill_control_seq))rec    
GROUP BY REC.CaseNumReev,REC.BILL_CONTROL_SEQ
于 2012-05-09T16:34:00.550 回答