当我调用一个程序时....如何检查列中的重复值?

时间:2014-11-27 02:17:18

标签: sql oracle11g

我坚持做SQL分配......我创建了这个程序

SET SERVEROUTPUT ON;

CREATE OR REPLACE PROCEDURE insert_glaccount
(
  account_number_param general_ledger_accounts.account_number%TYPE,
  account_description_param general_ledger_accounts.account_description%TYPE
)
AS 
BEGIN   
  INSERT INTO general_ledger_accounts
  VALUES (account_number_param, account_description_param);          
END;
/

我需要调用该程序并检查重复的帐号。如果有重复,那么我需要输出一条消息。我一直在尝试不同的东西,但似乎没有任何效果。

感谢任何帮助或建议,谢谢

1 个答案:

答案 0 :(得分:0)

试试这个

declare
  total_row number;
begin
  select count(*)
  into   total_row 
  from   general_ledger_accounts
  where conditions whatever you want


  if total_row then
    ...
  else
    ...
  end if;