2011-11-17 69 views
1

我使用Oracle 10g和我得到與被假設的工作代碼的一些問題。這讓我瘋狂。該代碼是這樣的:與選擇Oracle類型錯誤進入

CREATE OR REPLACE TRIGGER trig_t1 
AFTER INSERT ON t1 
DECLARE 
    count1 INTEGER; 
    foo t1.field1%TYPE; --field is a VARCHAR2(20) 
BEGIN 
    SELECT COUNT(1) INTO count1 --error in this line 
    FROM t1 
    WHERE condition; 

    foo:='bar'; 

    UPDATE t1 SET field1=foo --error in this line 
    WHERE some condition ; 
END;  

它「有錯誤編譯」,都是類型的「PLS-00382:表達式類型錯誤的」。 我只是不明白...有人知道我的代碼有什麼問題嗎?

+0

的問題是在對語句的條件。非常感謝您的重播。 – Jzop

回答

2

你能後的T1定義是什麼?您的代碼似乎爲我工作,如果T1有一個名爲FIELD1一列。是否有可能在表中與本地變量共享名稱的列?

SQL> create table t1(field1 varchar2(20)); 

Table created. 

SQL> create or replace trigger trg_t1 
    2 after insert on t1 
    3 declare 
    4 l_count1 integer; 
    5 foo  t1.field1%type; 
    6 begin 
    7 select count(*) 
    8  into l_count1 
    9  from t1; 
10 
11 foo := 'bar'; 
12 
13 update t1 
14  set field1 = foo 
15  where 1=1; 
16 end; 
17/

Trigger created. 

SQL> insert into t1 values('foo'); 

1 row created. 

SQL> select * from t1; 

FIELD1 
-------------------- 
bar