Oracle SQL:如何在XMLTable的路径中传递sysdate

时间:2016-09-05 05:14:28

标签: sql xml oracle xmltable

我正在从xml中检索数据以插入表中。但我还想在以下xmltable表中插入一个额外的数据sysdate:

sample XML data:
<employee_info>                             
<employee_id>ID1234</employee_id>
<name>John</name>
</employee_info>

-- This is the query Notice at  CREATED_ON :

INSERT INTO TBL_EMPLOYEE TBL (TBL.EMP_ID, TBL.Name, TBL.Created_on) 
    SELECT x.* FROM XMLTABLE('/employee_info'
                        PASSING xmlData
                        COLUMNS  EMP_ID  VARCHAR2(10)     PATH   'employee_id',                                                        
                                 Name    VARCHAR2(50)     PATH    'name',                                                                                        
                                 CREATED_ON DATE     PATH '<created_on>sysdate</created_on>');

如何传递不属于给定xml示例的列sysdate上的CREATED_ON。请帮忙。感谢

1 个答案:

答案 0 :(得分:1)

您不需要在xml级别上操作以使列具有sysdate:

INSERT INTO tbl_employee tbl
     (tbl.emp_id
     ,tbl.name
     ,tbl.created_on)
SELECT t.emp_id, t.name, sysdate
  FROM xmltable('/employee_info' 
                passing xmldata 
                columns 
                        emp_id VARCHAR2(10) path 'employee_id', 
                        NAME VARCHAR2(50) path 'name'
               ) t;