尝试写入文件时出错

Error when trying to write to file

我有以下程序应该将一些数据写入文件。

CREATE OR REPLACE PROCEDURE export_to_xml
IS
  F UTL_FILE.FILE_TYPE;
  CURSOR c_cursor IS
    SELECT x FROM (select xmlelement( "user", xmlforest( uname, action, time ) ) as x from table_log);
  action c_cursor%ROWTYPE;
BEGIN
  F := UTL_FILE.FOPEN('XML', 'log.xml', 'w');
  OPEN c_cursor;
  LOOP
    EXIT WHEN c_cursor%NOTFOUND;
    FETCH c_cursor INTO action;
    UTL_FILE.PUT(F, action.x);
    UTL_FILE.NEW_LINE(F);
  END LOOP;
  CLOSE c_cursor;
  UTL_FILE.FCLOSE(F);
END;
/

但是当我尝试编译程序时出现以下错误

PLS-00306: wrong number or types of arguments in call to 'PUT'

有人知道问题的原因吗?我知道它来自 UTL_FILE.PUT(F, action.x); 但我没有看到任何其他方式来引用光标。

xmlelementreturns一个XMLType。您可以使用 getStirngVal() 将其转换为 varchar,以便您可以将其与 put:

一起使用
CURSOR c_cursor IS
    SELECT x FROM (select xmlelement( "user", xmlforest( uname, action, time ) ).getStringVal() as x from table_log);
  action c_cursor%ROWTYPE;