[OIC] How to use NVL in SQL query while using DB Adapter in Oracle Integration Cloud?

 

This post will show how to use NVL in SQL query while using DB Adapter in Oracle Integration Cloud.

 

We have below query as an example in which we are filtering on object type and getting count of each object type.

 

SELECT owner,object_name,object_type FROM all_objects WHERE object_type = NVL(#p_object_type,object_type)
 
 

  • Start with a REST Trigger with query parameter as "P_OBJECT_TYPE" and below response payload:
{
    "result": [
        {
            "owner": "",
            "object_name": "",
            "object_type": ""
        }
    ],
    "status":"",
    "message":""
}
 
 
 
  •  Then, add DB adapter and select Run a SQL Statement option
  •  But, when we try to use it DB Adapter we get below error:

 

 

 

Error: Unable to create the request and response data definition for this SQL Query. Please fix the SQL Statement or try to switch to Perform table operation option on the Welcome page. Refer Oracle documentation for further information.

 

  • To overcome this issue, we have to utilize Stored Procedure option. We can write standalone procedure or procedure in package. Here we will write below procedure:


CREATE OR REPLACE PROCEDURE get_data(
    p_in_object_type            IN     VARCHAR2 DEFAULT NULL,
    p_out_status                OUT    VARCHAR2,
    p_out_message               OUT    VARCHAR2,
    p_out_data                  OUT    SYS_REFCURSOR             
)
AS
   
BEGIN

    OPEN p_out_data FOR
    SELECT OWNER
        ,object_name
        ,object_type
    FROM all_objects
    WHERE object_type = NVL(p_in_object_type, object_type);

    p_out_status    :='Success';
    p_out_message   :='Data fetched successfully';
    
EXCEPTION
    WHEN OTHERS THEN
        p_out_status    :='Error';
        p_out_message   :='Exception: '||SQLERRM;
END get_data;
 
 
 

  •  Now use this procedure in DB Adapter as below:


 

  • Then map the fields as below. For each response field map the name field from DB Adapter response. 

  • Mapper code will look like below now:
<xsl:template match="/" xml:id="id_11">
      <nstrgmpr:executeResponse xml:id="id_12">
            <nstrgdfl:response-wrapper xml:id="id_31">
                  <xsl:for-each xml:id="id_56" select="$GetData/nsmpr0:OutputParameters/nsmpr0:P_OUT_DATA/nsmpr0:Row">
                        <nstrgdfl:result xml:id="id_36">
                              <nstrgdfl:owner xml:id="id_37">
                                    <xsl:value-of xml:id="id_38" select="nsmpr0:Column/@name"/>
                              </nstrgdfl:owner>
                              <nstrgdfl:object_name xml:id="id_39">
                                    <xsl:value-of xml:id="id_40" select="nsmpr0:Column/@name"/>
                              </nstrgdfl:object_name>
                              <nstrgdfl:object_type xml:id="id_41">
                                    <xsl:value-of xml:id="id_42" select="nsmpr0:Column/@name"/>
                              </nstrgdfl:object_type>
                        </nstrgdfl:result>
                  </xsl:for-each>
                  <nstrgdfl:status xml:id="id_32">
                        <xsl:value-of xml:id="id_33" select="$GetData/nsmpr0:OutputParameters/nsmpr0:P_OUT_STATUS"/>
                  </nstrgdfl:status>
                  <nstrgdfl:message xml:id="id_34">
                        <xsl:value-of xml:id="id_35" select="$GetData/nsmpr0:OutputParameters/nsmpr0:P_OUT_MESSAGE"/>
                  </nstrgdfl:message>
            </nstrgdfl:response-wrapper>
      </nstrgmpr:executeResponse>
</xsl:template>
 
  •  Now change the mapper code as below so that fields are correctly mapped:
<xsl:template match="/" xml:id="id_11">
      <nstrgmpr:executeResponse xml:id="id_12">
            <nstrgdfl:response-wrapper xml:id="id_31">
                  <xsl:for-each xml:id="id_56" select="$GetData/nsmpr0:OutputParameters/nsmpr0:P_OUT_DATA/nsmpr0:Row">
                        <nstrgdfl:result xml:id="id_36">
                              <nstrgdfl:owner xml:id="id_37">
                                    <xsl:value-of xml:id="id_38" select="nsmpr0:Column[@name='OWNER']"/>
                              </nstrgdfl:owner>
                              <nstrgdfl:object_name xml:id="id_39">
                                    <xsl:value-of xml:id="id_40" select="nsmpr0:Column[@name='OBJECT_NAME']"/>
                              </nstrgdfl:object_name>
                              <nstrgdfl:object_type xml:id="id_41">
                                    <xsl:value-of xml:id="id_42" select="nsmpr0:Column[@name='OBJECT_TYPE']"/>
                              </nstrgdfl:object_type>
                        </nstrgdfl:result>
                  </xsl:for-each>
                  <nstrgdfl:status xml:id="id_32">
                        <xsl:value-of xml:id="id_33" select="$GetData/nsmpr0:OutputParameters/nsmpr0:P_OUT_STATUS"/>
                  </nstrgdfl:status>
                  <nstrgdfl:message xml:id="id_34">
                        <xsl:value-of xml:id="id_35" select="$GetData/nsmpr0:OutputParameters/nsmpr0:P_OUT_MESSAGE"/>
                  </nstrgdfl:message>
            </nstrgdfl:response-wrapper>
      </nstrgmpr:executeResponse>
</xsl:template>

  • Now, validate and test the integration. 



Comments

All Categories

Call Fusion BIP Report2 Change Password1 Code Combinations2 Compute Instance2 CTE1 Customer1 Data Aggregation2 Database5 Date Conversion1 DB Adapter2 Decryption1 Development1 EBS4 Encryption1 ESS Jobs3 Examine1 FBDI3 Fusion APIs1 Fusion BIP7 GIT2 GL3 GL Journals1 GL_DAILY_CONVERSION_TYPES1 GL_DAILY_RATES1 ICS1 Identity Domain1 Integrations1 Java1 Journal Import1 Keys1 Legal Entity1 LookupTypeLOV1 LOV1 LOVs1 MultiPartAPIs1 Networking1 NVL2 NVL in OIC2 OCI11 OCI Billing1 OCI Compute5 OCI Cost Management1 OCI Events Service1 OCI Free Tier3 OCI Notifification Service1 OCI Security3 OIC4 OIC Mapper2 Oracle26 Oracle ADF17 Oracle APEX1 Oracle Apps59 Oracle Apps R126 Oracle ATP1 Oracle BIP8 Oracle Cloud12 Oracle Cloud Free Tier1 Oracle cloud Infrastructure9 Oracle Cloud Security2 Oracle Cloud VM1 Oracle DB4 oracle ebs5 Oracle ERP4 Oracle ERP Adapter2 Oracle ERP Cloud7 Oracle financials2 Oracle Forms1 Oracle Fusion57 Oracle Fusion BIP4 Oracle Fusion ERP17 Oracle Fusion Financials18 Oracle Integration Cloud3 Oracle OAF17 Oracle OCI14 Oracle OIC22 Oracle SOA 12c10 Oracle SQL17 Oracle VBCS1 Oracle VBS2 Oracle Visual Builder Cloud Service1 Oracle Visual Builder Studio2 Oracle Workflow Notifications1 Others10 Payables2 Payables Import1 Properties1 R121 Register BIP as ESS Job1 Reset Password1 Responsibility1 REST4 Security List1 Site Map1 SOAP2 SOAP API2 SOAP UI3 SQL16 SQL Functions3 SQL Queries14 SQL Query8 SQL Tips3 SSH1 TCA1 Value Sets1 VBCS1 Virtual Machine2 Virtual Machines1 XML1 XSLT1
Show more