OracleデータベースでJavaアプリケーションをプログラミングしています。私が使っているPL/SQL文は次のとおりです。Java PL/SQL '即時実行'
DECLARE
USER_COUNT INTEGER;
BEGIN
SELECT COUNT(*) INTO USER_COUNT FROM dba_users WHERE username=?;
IF (USER_COUNT = 0) THEN
EXECUTE IMMEDIATE 'CREATE USER ? IDENTIFIED BY ?';
EXECUTE IMMEDIATE 'GRANT CREATE SESSION, CREATE TABLE, CREATE ANY INDEX TO ?';
ELSE
raise_application_error(-20101, 'User ? already exists. Please drop it or choose another username.');
END IF;
END;
/
しかし、疑問符前後に引用符がある場合、私は「は無効な列インデックス」エラーの多くを得ました。例えば:
EXECUTE IMMEDIATE 'CREATE USER ? IDENTIFIED BY ?';
が動作していないが、
EXECUTE IMMEDIATE CREATE USER ? IDENTIFIED BY ?;
が良いです。
java.sql.SQLException: ORA-06550: line 6, column 23:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
(- + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternat
は何をすべきかを教えてください:私は2番目の形式を使用することを選択した場合
しかし、私は別の構文エラーを得ました。
あなただけの、Javaから3つのステートメントを実行していない任意の理由は? – Andreas