1

对于可能是基本问题,我提前道歉。我是学生,现在是关键时刻!

我正在使用 Oracle 10g Express。

我创建了一个函数:

create or replace FUNCTION test_glaccounts_description
(
account_description_param VARCHAR2
) 
RETURN NUMBER
AS
  description_dup_var NUMBER;
BEGIN
  SELECT 1
  INTO description_dup_var
  FROM general_ledger_accounts
  WHERE account_description = account_description_param;

  RETURN description_dup_var;  
  EXCEPTION 
    WHEN NO_DATA_FOUND THEN
    RETURN 0;
END;

并想在程序中使用该功能。我试过了:

PROCEDURE insert_gla_with_test
(
  account_number_param  NUMBER,
  account_description_param VARCHAR2
)
 AS
BEGIN 
  IF test_glaccounts_description = 1 THEN
  INSERT INTO  general_ledger_accounts
  VALUES (account_number_param, account_description_param);
  ELSE raise_application_error (-20001, 'Duplicate account description');
  END IF;
END;

但它不喜欢“test_gla_accounts”行.....我做错了什么?据我了解,函数返回值1或0,在程序中,如果函数返回1,我希望将param字段添加到表中。如果函数返回 0,我希望该过程引发错误。

4

1 回答 1

4

test_glaccounts_description接受一个参数 ( account_description_param) 并返回一个NUMBER. 因此,为了调用该函数,您需要传入一个参数。假设您要传入account_description_param传递给insert_gla_with_test过程的

CREATE OR REPLACE PROCEDURE insert_gla_with_test
(
  account_number_param  NUMBER,
  account_description_param VARCHAR2
)
 AS
BEGIN 
  IF test_glaccounts_description( account_description_param ) = 1 THEN
    INSERT INTO  general_ledger_accounts
      VALUES (account_number_param, account_description_param);
  ELSE 
    raise_application_error (-20001, 'Duplicate account description');
  END IF;
END;
于 2012-12-05T18:30:00.807 回答