0

編集: 要求ごとに、SQL*Plus で何が起こっているかをここに示します。 編集 2: 問題は、列名がキーワード SQL> ドロップ テーブル コメントでした。

Table Dropped.

SQL> create table comments (
 2 comment_id number not null,
 3 post_id number not null,
 4 user_id number not null,
 5 message varchar2(2500) not null,
 6 timestamp timestamp(6) not null);

Table Created

SQL> create sequence comment_seq
 2 start with 1
 3 increment by 1
 4 nomaxvalue;

Sequence Created

SQL> ed

Wrote file afiedt.buf //NOTEPAD OPENED UP

1 create or replace trigger comment_trigger
2      before insert on comments
3      for each row
4 begin
5     select comment_seq.nextval
6     into :new.comment_id
7     from dual;
8 end;
SQL> /

    ERROR at Line 2:
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-320: the declaration of the type of this expression is
    incomplete or malformed

    SQL> show errors
    No errors.
4

3 に答える 3

2

数値列のデータ型を修正すると仮定すると(number(300)は有効なデータ型ではありません)、そのコードはうまくいくようです。エラーが発生する場合は、ここに投稿したこと以外のことを行っていることを意味します。

SQL> create table comments (
  2    comment_id number not null,
  3    post_id    number not null,
  4    user_id    number not null,
  5    message    varchar2(2500) not null,
  6    timestamp  timestamp(6) not null
  7  );

Table created.

SQL> create sequence comment_seq
  2  start with 1
  3  increment by 1
  4  nomaxvalue;

Sequence created.

SQL> ed
Wrote file afiedt.buf

  1  create or replace trigger comment_trigger
  2    before insert on comments
  3    for each row
  4  begin
  5    select comment_seq.nextval
  6      into :new.comment_id
  7      from dual;
  8* end;
SQL> /

Trigger created.
于 2012-07-24T18:27:35.263 に答える
1

コメントで展開中...

このエラーはtimestampcommentsテーブルで名前が付けられた列が原因で発生します。予約語をオブジェクト名として使用することは、混乱やあいまいな問題を引き起こす可能性があり、エスケープする必要がある可能性があるため、お勧めできません (こちらのように)。

この場合、表がエラーなしで作成されたとしても、特に列名が単なる予約語ではなくデータ型であるため、(コンパイルされたPL/SQLの「ライブラリ・ユニット」である可能性がありますが)トリガーは失敗します。

これはバグ 6331062、「PLS-320 if a column name is a datatype (eg "TIMESTAMP")」のようで、バグ レポートによると、パッチセット 10.2.0.5 (ノート 1088172.1 を参照) および 11.1.0.7 で修正されています。 11gR2 ベース リリースでは、Justin と Craig が認識しなかった理由が説明されます。(ジャスティンは 11gR2 を使用していると思います。クレイグの出力は、彼が 11.1.0.7 を使用していることを示しています)。

于 2012-07-25T07:32:50.163 に答える
0

オラクルのバージョンは?

また、"ed" を使用する代わりに、トリガー コードをそのまま SQL*Plus に入れるとどうなるでしょうか。

しかし、奇妙なことに、あなたのスクリプトは私にとってはうまく機能するからです:

Oracle Database 11g Enterprise Edition Release 11.1.0.7.0

SQL> create table comments (
  2   comment_id number not null,
  3   post_id number not null,
  4   user_id number not null,
  5   message varchar2(2500) not null,
  6   timestamp timestamp(6) not null);

Table created.

SQL> create sequence comment_seq
  2   start with 1
  3   increment by 1
  4   nomaxvalue;

Sequence created.

SQL> ed
Wrote file afiedt.buf

  1  create or replace trigger comment_trigger
  2        before insert on comments
  3        for each row
  4   begin
  5       select comment_seq.nextval
  6       into :new.comment_id
  7       from dual;
  8*  end;
SQL> /

Trigger created.
于 2012-07-24T19:28:02.383 に答える