不允许对NULL SELF参数进行Oracle方法调度

时间:2016-01-17 03:57:19

标签: xml oracle plsql

我在包下有一个功能。我将一些xml数据传递给该函数。但是我收到了这个错误。有人可以解释一下吗?我正在解释我想在代码中做什么。我想输入除tsih_rate字段之外的所有字段。它将以自动方式计算和填充。

FUNCTION save_settings_insurance_health(employeeData NVARCHAR2) RETURN CLOB IS

ret CLOB;
xmlData XMLType;
v_code NUMBER;
v_errm VARCHAR2(500);
input_rate number(7,2);

BEGIN

xmlData:=XMLType(employeeData);

INSERT INTO TBL_SETTINGS_INSURANCE_HEALTH SELECT temp1.* FROM XMLTABLE('/employees/employee/insurance/health'
                                  PASSING xmlData
                                  COLUMNS tsih_class NVARCHAR2(10) PATH 'tsih_class',
                                          tsih_rate NUMBER(7,2) PATH 'tsih_rate' default null,
                                          tsih_total NUMBER(7,2) PATH 'tsih_total',
                                          tsih_eff_date_from DATE PATH 'tsih_eff_date_from',
                                          tsih_eff_date_to DATE PATH 'tsih_eff_date_to',
                                          tsih_created_on DATE PATH 'tsih_created_on',
                                          tsih_created_by NVARCHAR2(10) PATH 'tsih_created_by')temp1;
ret:=to_char(sql%rowcount);
input_rate:=to_number(xmlData.extract('/employees/insurance/health/tsih_total/text()').getstringval())/12;
INSERT INTO TBL_SETTINGS_INSURANCE_HEALTH (tsih_rate) VALUES (input_rate);
COMMIT;

RETURN '<result><status affectedRow='||ret||'>success</status></result>';
DBMS_OUTPUT.PUT_LINE(ret);
EXCEPTION
WHEN OTHERS THEN
v_code := SQLCODE;
v_errm := SUBSTR(SQLERRM, 1 , 500);
DBMS_OUTPUT.PUT_LINE('Error code ' || v_code || ': ' || v_errm);
RETURN '<result><status>Error'||v_errm||'</status></result>';  

END save_settings_insurance_health;  

我的输入pl / sql如下:

declare
   result clob;
begin
   -- Call the function
   result := PMIS.SAVE_SETTINGS_INSURANCE_HEALTH('<employees>
                      <employee>
                        <insurance>
                          <health>
                            <tsih_class>teacher</tsih_class>
                            <tsih_total>1200</tsih_total>
                            <tsih_eff_date_from>2016-1-16</tsih_eff_date_from>
                            <tsih_eff_date_to></tsih_eff_date_to>
                            <tsih_created_on>2016-1-16</tsih_created_on>
                            <tsih_created_by>Wahid</tsih_created_by>
                          </health>
                        </insurance>
                      </employee>
                  </employees>');

  DBMS_OUTPUT.PUT_LINE(result);
end;  

1 个答案:

答案 0 :(得分:0)

XPath表达式缺少“employee”。

更改此行:

input_rate:=to_number(xmlData.extract('/employees/insurance/health/tsih_total/text()').getstringval())/12;

对此:

input_rate:=to_number(xmlData.extract('/employees/employee/insurance/health/tsih_total/text()').getstringval())/12;