从表值创建目录时出错

时间:2013-08-21 23:24:18

标签: plsql

我想使用触发器调用的过程创建/修改oracle目录。我想从表中的值获取路径,并且在该值发生更改时从激活的触发器调用该过程。我在程序中有以下代码:

 CREATE OR REPLACE
PROCEDURE update_directory(
    v_directory IN fe_system_parameter.value%type)
AS
  dir_path              VARCHAR2(32767);
  command VARCHAR2(32767);
BEGIN
  SELECT VALUE
  INTO dir_path
  FROM fe_system_parameter
  WHERE name = 'DWH_DIRECTORY';

  command := 'CREATE OR REPLACE DIRECTORY DWH_DIR AS ' || dir_path;

  execute immediate(command);
END update_directory; 

当dir的值包含'/'字符,例如:/ DIR /时,我收到以下错误:

PLS-00103: Encountered the symbol "/" when expecting one of the following:

   ( ) - + case mod new not null <an identifier>
   <a double-quoted delimited-identifier> <a bind variable>
   table continue avg count current exists max min prior sql
   stddev sum variance execute multiset the both leading
   trailing forall merge year month day hour minute second
   timezone_hour timezone_minute timezone_region timezone_abbr
   time timestamp interval date
   <a string literal with character set specification>
ORA-06512: at "SYS.DBMS_JOB", line 82
ORA-06512: at "SYS.DBMS_JOB", line 140
ORA-06512: at "SOMESCHEMA.TRI_UPDATE_DIRECTORY", line 3
ORA-04088: error during execution of trigger 'SOMESCHEMA.TRI_UPDATE_DIRECTORY'

我不知道问题可能是什么。

1 个答案:

答案 0 :(得分:0)

您需要添加单引号,例如:

command := 'CREATE OR REPLACE DIRECTORY DWH_DIR AS ''' || dir_path || '''';