1
CREATE OR REPLACE PROCEDURE ResetVersionNumberValue IS
  sql_stmt    VARCHAR2(2000);
BEGIN
  FOR sql_stmt IN (select 'update '|| table_name ||
                          ' set version = 0'
                     from user_tables
                     where table_name like 'MY_%')
  LOOP
      EXECUTE IMMEDIATE sql_stmt;
  END LOOP;

  COMMIT;
END;

为什么 about 程序没有编译?它给出错误说

错误(8,26):PLS-00382:表达式类型错误

如何解决这个问题?

4

2 回答 2

3

两件事情:

  1. 您需要记住,在迭代游标时,它会返回 ROW,而不是 VALUE,并且
  2. 游标中的 SELECT 需要为游标生成的行中的值命名。

尝试:

CREATE OR REPLACE PROCEDURE ResetVersionNumberValue IS
BEGIN
  FOR aRow IN (select 'update '|| table_name ||
                          ' set version = 0' AS SQL_STMT
                     from user_tables
                     where table_name like 'MY_%')
  LOOP
      EXECUTE IMMEDIATE aRow.SQL_STMT;
  END LOOP;

  COMMIT;
END;

分享和享受。

于 2013-05-16T11:13:24.200 回答
1
CREATE OR REPLACE PROCEDURE ResetVersionNumberValue IS
BEGIN   
FOR sql_stmt IN ( 
        select 'update '|| table_name || ' set version = 0' as x 
        from    user_tables 
        where   table_name like 'MY_%')  
LOOP
      EXECUTE IMMEDIATE  sql_stmt.x;   
END LOOP;   
COMMIT; 
END;
于 2013-05-16T11:11:36.727 回答