0

私は次の実行中のコードを持っています:

DECLARE
  rec_present NUMBER (10) := 0;
BEGIN
  SELECT COUNT (*)
  INTO rec_present
  FROM ref_cross_exchange_rate
  WHERE local_ccy_pk =
    &localCcy
  AND base_ccy_pk =
    &baseccy
  AND base_date =
    &BaseDate;
  IF rec_present = 0 THEN
    INSERT
    INTO ref_cross_exchange_rate
      (
        cross_exchange_rate_pk,
        base_date ,
        local_ccy_pk ,
        base_ccy_pk 
      )
      VALUES
      (
        (SELECT NVL (MAX (cross_exchange_rate_pk), 0) + 1
          FROM ref_cross_exchange_rate
        )
        ,
        &BaseDate,
        &localCcy,
        &baseccy
      );
    DBMS_OUTPUT.put_line ('1 RECORD INSERTED');
  ELSE
    DBMS_OUTPUT.put_line ('RECORD ALREADY EXISTS');
  END IF;
END;
/
COMMIT;

しかし、問題は、同じ値を数回入力する必要があることです。そのため、次のようにいくつかの変更を行いました。

DECLARE
  rec_present number (10) := 0;
  bdate Date          := &basedate;
  local_ccy     NUMBER(10,0)  := &localccy;
  base_ccy      NUMBER(10,0)  := &baseccy;
  exchange_rate NUMBER(20,10) := &ExchangeRate;
BEGIN
  SELECT COUNT (*)
  INTO rec_present
  from ref_cross_exchange_rate
  where local_ccy_pk = local_ccy
  and base_ccy_pk    = base_ccy
  AND base_date      =TO_DATE (bdate) ;
  IF rec_present     = 0 THEN
    INSERT
    INTO ref_cross_exchange_rate
      (
        cross_exchange_rate_pk,
        base_date ,
        local_ccy_pk ,
        base_ccy_pk 
      )
      VALUES
      (
        (SELECT NVL (MAX (cross_exchange_rate_pk), 0) + 1
          FROM ref_cross_exchange_rate
        )
        ,
        TO_DATE (bdate),
        local_ccy,
        base_ccy
      );
    DBMS_OUTPUT.put_line ('1 RECORD INSERTED');
  ELSE
    DBMS_OUTPUT.put_line ('RECORD ALREADY EXISTS');
  END IF;
END;
/
COMMIT;

しかし、残念ながらそれは機能していません。この質問からの提案を試しましたが、機能しませんでした。

エラー:

エラーレポート:

ORA-06550: line 3, column 26:
PLS-00382: expression is of wrong type
ORA-06550: line 3, column 9:
PL/SQL: Item ignored
ORA-06550: line 13, column 24:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 13, column 24:
PL/SQL: ORA-00904: "BDATE": invalid identifier
ORA-06550: line 8, column 3:
PL/SQL: SQL Statement ignored
ORA-06550: line 40, column 9:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 40, column 9:
PL/SQL: ORA-00904: "BDATE": invalid identifier
ORA-06550: line 15, column 5:
PL/SQL: SQL Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
commited.
4

1 に答える 1

0

変数に値を適切に割り当てるために、宣言部分に引用符を追加しました。

これはうまくいくはずです、

DECLARE

  rec_present number (10) := 0;
  bdate Date          := '&basedate';
  local_ccy     NUMBER(10,0)  := '&localccy';
  base_ccy      NUMBER(10,0)  := '&baseccy';
  exchange_rate NUMBER(20,10) := '&ExchangeRate';

BEGIN
  SELECT COUNT (*)
  INTO rec_present
  from ref_cross_exchange_rate
  where local_ccy_pk = local_ccy
  and base_ccy_pk    = base_ccy
  AND base_date      =TO_DATE (bdate) ;
  IF rec_present     = 0 THEN
    INSERT
    INTO ref_cross_exchange_rate
      (
        cross_exchange_rate_pk,
        base_date ,
        local_ccy_pk ,
        base_ccy_pk 
      )
      VALUES
      (
        (SELECT NVL (MAX (cross_exchange_rate_pk), 0) + 1
          FROM ref_cross_exchange_rate
        )
        ,
        TO_DATE (bdate),
        local_ccy,
        base_ccy
      );
    DBMS_OUTPUT.put_line ('1 RECORD INSERTED');
  ELSE
    DBMS_OUTPUT.put_line ('RECORD ALREADY EXISTS');
  END IF;
END;
/
COMMIT;
于 2013-02-06T05:27:46.940 に答える