Monday, September 18, 2023

OIC - PLSQL - How to feed comma separated fields as input and fetch table of records output using stored Procedure

Usecase:  We have a requirement in oracle integration where we need to pass comma separated ids as input and fetch the employee names along with the ids as a table of records from a database table using stored procedure.


PLSQL CODE:

Create object type:

CREATE OR REPLACE TYPE employee_row_type AS OBJECT(

id number,

firstname varchar2(200)

);

Create a table of rows types:

CREATE OR REPLACE TYPE employee_table_type AS TABLE OF employee_row_type;

Create the stored procedure:

CREATE OR REPLACE PROCEDURE fetch_employee_data(p_employee_ids IN VARCHAR2,p_employee_data OUT employee_table_type)

IS

BEGIN

SELECT employee_row_type(id,firstname)

BULK COLLECT INTO p_employee_data FROM employees_sd WHERE id IN (SELECT TO_NUMBER(REGEXP_SUBSTR(p_employee_ids, '[^,]+',1,LEVEL)) FROM DUAL CONNECT BY REGEXP_SUBSTR(p_employee_ids, '[^,]+',1,LEVEL) IS NOT NULL);

END fetch_employee_data;

/


Test code:

DECLARE 

v_emp_ids varchar2(100) := '1,2,3';

v_emp_data employee_table_type;

BEGIN

fetch_employee_data(v_emp_ids,v_emp_data);

FOR i IN 1..v_emp_data.COUNT LOOP

dbms_output.put_line('Empno = ' || v_emp_data(i).id || ', Name: ' || v_emp_data(i).firstname);

END LOOP;

END;

/

OIC screenshots:







Test:






Thursday, September 14, 2023

OIC - Different types of Translation failure in the mapper using XSD structure of the file contents

UseCase: While mapping the elements in the mapper using XSD structure of the file contents, getting below 2 types of translation errors:

Error1:

ORABPEL - 11101 

Translation Failure

Translation to native failed. Element not completed: 'UserLabel1'.

The data does not conform to the NXSD schema. Please correct the problem.


Solution 1:

Map all the elements of the complex type element UserLabel1.


Error2 :

ORABPEL - 11101 

Translation Failure

Translation to native failed. Element 'UsernameLabel1' not expected..

The data does not conform to the NXSD schema. Please correct the problem.



Solution 2:

this is because few of elements before the element UsernameLabel1 are not mapped. Map all the elements.


For your reference following XSD used:




Wednesday, September 13, 2023

OIC - PLSQL - How to feed table of record types and fetch table of records output using Package and Procedure

Usecase:  We have a requirement in oracle integration where we need to pass a table of employee ids and fetch the employee names along with the ids from a database table using stored procedure.


PLSQL code:

Package definition:

CREATE OR REPLACE PACKAGE PKG_DUMMY AS

TYPE rcd_type IS RECORD

(

Id NUMBER,

Fname VARCHAR2(100)

);

TYPE rcd_tbl IS TABLE OF rcd_type;

PROCEDURE GET_FNAME(

tbl_io IN OUT rcd_tbl,

sqlcode_io IN OUT NUMBER,

sqlerrm_io IN OUT VHARCHAR2

);

END PKG_DUMMY;


Package Body:

CREATE OR REPLACE PACKAGE BODY PKG_DUMMY AS

PROCEDURE GET_FNAME(

tbl_io IN OUT rcd_tbl,

sqlcode_io IN OUT NUMBER,

sqlerrm_io IN OUT VARCHAR2

) IS

v_tbl rcd_tbl := rcd_tbl();

BEGIN

FOR idx in 1..tbl_io.count LOOP

v_tbl.extend;

v_tbl(idx).id := tbl_io(idx).id;

BEGIN

SELECT firstname into v_tbl(idx).fname from employees_sd where id := tbl_io(idx).id;

EXCEPTION

WHEN OTHERS THEN

v_tbl(idx).fname :='NA';

END;

END LOOP;

tbl_io := v_tbl;

sqlcode_io :=0;

sqlerrm_io := Null;

sqlcode_io := SQLCODE;

sqlcode_io := SQLERRM;

DBMS_OUTPUT.PUT_LINE('procname : ' || 'Others Exception. SQL: '||to_char(sqlcode_io) || ':' || substr(sqlerrm, 1 , 70)|| '.');

END GET_FNAME;

END PKG_DUMMY;


Call from OIC and Test:









Test codes from Database:

DECLARE

TBL_IO PKG_DUMMY.RCD_TBL;

SQLCODE_IO NUMBER;

SQLERRM_IO VARCHAR2(100);

BEGIN

TBL_IO := PKG_DUMMY.RCD_TBL();

TBL_IO.extend;

TBL_IO(1) := PKG_DUMMY.RCD_TYPE(1, 'a');

TBL_IO.extend;

TBL_IO(2) := PKG_DUMMY.RCD_TYPE(2, 'a');

SQLCODE_IO :=NULL;

SQLERRM_IO := NULL;

PKG_DUMMY.GET_FNAME(

TBL_IO => TBL_IO,

SQLCODE_IO => SQLCODE_IO,

SQLERRM_IO => SQLERRM_IO);

FOR i in 1..tbl_io.count LOOP

DBMS_OUTPUT.PUT_LINE(' ID : ' || tbl_io(i).id || ' and fname : ' || tbl_io(i).fname);

END LOOP;

END;

PLSQL code screenshots:




The same we can also do using package and function as below code:

Package definition:

CREATE OR REPLACE PACKAGE EMPPKG IS

TYPE EMP_REC IS RECORD(

id NUMBER,

fname VARCHAR2(100)

);

TYPE EMP_TABLE IS TABLE OF EMP_REC;

FUNCTION getEmployeeData(

p_emp_data EMP_TABLE

) RETURN EMP_TABLE;

END EMPPKG;


Package Body:

CREATE OR REPLACE PACKAGE BODY EMPPKG IS

FUNCTION getEmployeeData(

p_emp_data EMP_TABLE

) RETURN EMP_TABLE

IS

v_result  EMP_TABLE := EMP_TABLE();

BEGIN

FOR i IN 1..p_emp_data.COUNT LOOP

v_result.extend;

v_result(i).id := p_emp_data(i).id;

SELECT firstname INTO v_result(i).fname FROM Employees_sd WHERE id = p_emp_data(i).id;

END LOOP;

RETURN v_result;

END getEmployeeData;

END EMPPKG;


Test code:

DECLARE

P_EMP_DATA EMPPKG.EMP_TABLE;

v_return EMPPKG.EMP_TABLE;

BEGIN

P_EMP_DATA := EMPPKG.EMP_TABLE();

P_EMP_DATA.extend;

P_EMP_DATA(1) := EMPPKG.EMP_REC(1, 'a');

P_EMP_DATA.extend;

P_EMP_DATA(2) := EMPPKG.EMP_REC(2, 'a');

v_return := EMPPKG.GETEMPLOYEEDATA(

P_EMP_DATA => P_EMP_DATA

);

FOR i in 1..v_return.count LOOP

DBMS_OUTPUT.PUT_LINE(' ID : ' || v_return(i).id || ' and fname : ' || v_return(i).fname);

END LOOP;

END;

Thursday, August 17, 2023

XSLT - How to get last 4 characters only from a substring with variable length of characters each time

We can use the string-length() in conjunction with substring to get the last 4 characters


<xsl:value-of select="substring(cbc:Note, string-length(cbc:Note) - 3)" />


Example:

Input: Note: abcdefg1234

Output: 1234

Friday, August 11, 2023

WSDL links

Wsdl links:
  1. Abstract wsdl vs Concrete wsdl
  2.  Oneway Message Pattern WSDL
  3. WSDL - Asyn Callback Service | Async BPEL vs Sync BPEL
  4. Sample Calculator WSDL
  5. Oneway employee wsdl and imported XSD

WSDL - Oneway users wsdl file

Oneway users Wsdl file:

<?xml version="1.0" encoding="UTF-8"?>

<definitions targetNamespace="urn:UserWSDL" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:UserWSDL" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:weo="http://www.example.org">

<types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org" targetNamespace="http://www.example.org" elementFormDefault="qualified">

<xsd:element name="Users">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="User" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:integer"/>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>

<portType name="UserServicePort">
<operation name="UserGetOP">
<input message="tns:UserRequestPort"/>
</operation>
</portType>

<message name="UserRequestPort">
<part name="part" element="weo:Users"/>
</message>
</definitions>


OIC - How to convert XML data to Json data and store it in a variable

Usecase: Here we have a requirement that Source will send xml payload using our exposed or triggered SOAP API and then we will convert it to JSON format and store it in a variable to insert the json data into a database table.

Logic steps:

  1. Create a WSDL file and create a SOAP trigger connection.
  2. Create a App driven orcehstration  and configure with the created soap connection
  3. Take a stage and write file with json sample and map the xml data to json data.
  4. Take stage again and read the json file using opaque schema
  5. Take a assign and create a variable and store the read file reference with decodebase64().
  6. Add tracking, save, activate , copy the wsdl and open a project in soap ui tool and add basic authentication and test


Opaque xsd:

https://soalicious.blogspot.com/2022/02/xsd-opaque-schema.html

Users.json:

{

"Users":{

"User":[

{

"id": 1,

"firstName":"string",

"lastName":"string",

"email":"string",

"country":"string"

},

{

"id": 2,

"firstName":"string",

"lastName":"string",

"email":"string",

"country":"string"

},

{

"id": 3,

"firstName":"string",

"lastName":"string",

"email":"string",

"country":"string"

}

]

}

}


Used oneway wsdl:

https://soalicious.blogspot.com/2023/08/wsdl-oneway-users-wsdl-file.html

Detailed with screenshots:

Soap connection:



Integration flow:


Configure soap trigger






Stage to write xml to json file







Read the json file as opaque:





Take assign and map the read file reference with decodebase64() inbuilt function.


Test from SOAPUI


Monitoring >> activity stream



Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...