Sunday, 3 January 2016

XML : How to get data in xml format from pl sql using php

I am new in pl sql and xml. i have write a pl sql function to retrieve data in xml format by call the function from php.

this is the xml format i wanted:

          <transaction>          <salary_year>$year</salary_year>          <salary_month>$month</salary_month>          <employee_id>$empID </employee_id>          <department_code>$dptCode</department_code>          <salary_head>$salHD</salary_head>          <description>$description</description>          <amount>$amount</amount>          <operator_id>$optID</operator_id>          <transaction_date>$trDate</transaction_date>          </transaction>    

here is the pl sql function with package & package body:

  create or replace PACKAGE  PAYROLL AS                 FUNCTION get_all_payroll_transactions return  clob;       END PAYROLL;    FUNCTION get_all_payroll_transactions return  clob IS    ret  clob;  isSuccess  clob;     BEGIN        SELECT CAST(XMLElement( "transaction", XMLElement("salary_year", SALYR),        XMLElement("salary_month", SALMT),                      XMLElement("employee_id", EMPID),                      XMLElement("department_code", DPTID),                      XMLElement("salary_head", SALHD),                      XMLElement("description", DESCRP),                      XMLElement("amount", ALAMT),                      XMLElement("operator_id", OPID),                      XMLElement("transaction_date", TRADT)       ) AS VARCHAR2(4000)) into isSuccess FROM PAYROLLFILE;      ret:=to_char(sql%rowcount);  COMMIT;    RETURN '<result><status affectedRow='||ret||'>success</status></result>';  EXCEPTION  WHEN OTHERS THEN  RETURN '<result><status>Error</status></result>';       END get_all_payroll_transactions;  END PAYROLL;    

here is php code for calling the function:

  $stid = oci_parse($conn, " begin                                    :result :=  PAYROLL.get_all_payroll_transactions();                                                          end;" );            oci_bind_by_name($stid, ':result',$ru, 500);          oci_execute($stid);    

please help me to fix the error.thanks

No comments:

Post a Comment