2016-09-05 58 views
0

我從xml檢索數據以插入到表中。但我也想在下列XMLTABLE表中插入一個額外的數據SYSDATE:Oracle SQL:如何在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>'); 

如何傳遞的sysdate上,是不是給定XML部分樣品列CREATED_ON。請幫忙。由於

回答

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; 
+0

感謝@Marcin萊夫斯基 – user5005768