XML をテーブルに保存しようとしています。XML の形式は次のとおりです。
<employees>
<employees_id> 1</employees_id>
<employees_name>Teradata</employees_name>
<department_id>100</department_id>
<department_name>Techinical</department_name>
<department_id>200</department_id>
<department_name>Management</department_name>
<department_id>300</department_id>
<department_name>Telecom</department_name>
</employees>
<employees>
<employees_id> 2</employees_id>
<employees_name>AT&T</employees_name>
<department_id>400</department_id>
<department_name>Techinical</department_name>
<department_id>500</department_id>
<department_name>Management</department_name>
<department_id>600</department_id>
<department_name>Telecom</department_name>
</employees>
私のテーブルには id 列と xmltype 列しかありません。
私が使用している手順は次のとおりです。
DECLARE
CTX DBMS_XMLGEN.CTXHANDLE;
LCLOB$XML_AS_CLOB CLOB;
LREC$EMPLOYEES_EMPNO NUMBER;
BEGIN
FOR LREC$EMPLOYEES_EMPNO IN (198, 197, 180)
LOOP
--Create context for XML
CTX :=
DBMS_XMLGEN.NEWCONTEXT (
'SELECT employees.EMPLOYEE_ID, employees.FIRST_NAME,
departments.DEPARTMENT_ID, departments.DEPARTMENT_NAME
FROM EMPLOYEES, departments
WHERE employees.department_id = departments.department_id and
employees.employees_id =' || LREC$EMPLOYEES_EMPNO);
--Get XML file of Context
-- Set the row header to be EMPLOYEE
DBMS_XMLGEN.setRowTag(CTX, 'EMPLOYEE');
LCLOB$XML_AS_CLOB := DBMS_XMLGEN.GETXML (CTX);
DBMS_XMLGEN.CLOSECONTEXT (CTX);
INSERT INTO HR.OFFLINE_XML (id, XML_FILE)
VALUES ( LREC$EMPLOYEES_EMPNO, XMLTYPE (LCLOB$XML_AS_CLOB));
END LOOP;
COMMIT;
END;
エラーレポート:
ORA-06550: line 7, column 4:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
* & - + / at mod remainder rem .. <an exponent (**)> ||
multiset year day
ORA-06550: line 18, column 16:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charac
ORA-06550: line 19, column 23:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charac
ORA-06550: line 20, column 16:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charac
ORA-06550: line 21, column 5:
PLS-00103: Encountered the symbol "INSERT" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
The symbol "b
ORA-06550: line 24, column 4:
PLS-00103: Encountered the symbol "COMMIT" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action: