删除 oracle 中 table 中所有列中的回车符 return 和换行符

Remove carriage return and line feed in the all columns in a table in oracle

必须删除 oracle 中多个 table 中所有列中的回车符 return and/or 换行符。 想到动态 SQL 查询并在 UPDATE 查询中使用注入传递 table 名称和列名称。 已尝试对列进行以下查询,但它出错了。 请协助我。

DECLARE
    TableName VARCHAR2(256);
    ColumnName VARCHAR2(256);
    plsql_block VARCHAR2(500);
BEGIN
    TableName := 'TEST';
    ColumnName := 'VALUE2';
    plsql_block := 'BEGIN UPDATE :A SET :B = REPLACE(:B, CHR(13), '''') END;';
    EXECUTE IMMEDIATE plsql_block USING TableName, ColumnName, ColumnName;
END;

错误信息:

Error report -
ORA-06550: line 1, column 19:
PL/SQL: ORA-00903: invalid table name
ORA-06550: line 1, column 7:
PL/SQL: SQL Statement ignored
ORA-06550: line 1, column 54:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   ( begin case declare end exception exit for goto if loop mod
   null pragma raise return select update while with
   <an identifier> <a double-quoted delimited-identifier>
   <a bind variable> << continue close current delete fetch lock
   insert open rollback savepoint set sql execute commit forall
   merge pipe purge json_exists json_value json_query
   json_object json_array
ORA-06512: at line 9
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

您必须连接 table/column 个名称。

示例数据:

SQL> CREATE TABLE test
  2  AS
  3     SELECT 'abc
  4  def' value2 FROM DUAL;

Table created.

SQL> SELECT * FROM test;

VALUE2
-------
abc
def

PL/SQL 块(无需在动态 SQL 中使用 BEGIN-END;纯 UPDATE 即可):

SQL> DECLARE
  2     TableName    VARCHAR2 (256);
  3     ColumnName   VARCHAR2 (256);
  4     plsql_block  VARCHAR2 (500);
  5  BEGIN
  6     TableName := 'TEST';
  7     ColumnName := 'VALUE2';
  8     plsql_block :=
  9           'UPDATE '
 10        || DBMS_ASSERT.sql_object_name (tablename)
 11        || ' SET '
 12        || DBMS_ASSERT.simple_sql_name (columnname)
 13        || ' = REPLACE('
 14        || DBMS_ASSERT.simple_sql_name (columnname)
 15        || ', CHR(10), '''')';
 16
 17     EXECUTE IMMEDIATE plsql_block;
 18  END;
 19  /

PL/SQL procedure successfully completed.

结果:

SQL> SELECT * FROM test;

VALUE2
-------
abcdef

SQL>