Calling An Oracle Stored Proc in Jasper

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Step 1: Create a Temp Table First, create a temp table to temporarily hold the results from the stored

procedure, so the Jasper Report can query it via the stored function, with a standard select query. To create the temp table, use this sql:
CREATE GLOBAL TEMPORARY TABLE CODA.TEMP_BNP_REPORT ( CMPCODE VARCHAR2(12), DOCCODE VARCHAR2(12), DOCNUM VARCHAR2(12), PERIODO VARCHAR2(8), CODEENTITE VARCHAR2(12), CODFORNITORE VARCHAR2(72), NUMINTERNOFATTURA VARCHAR2(35), NUMERORIGHEFATTURA NUMBER(5), NUMEROFATTURAFORNITORE VARCHAR2(32), TIPODOCUMENTO VARCHAR2(12), TIPOTRANSAZIONE VARCHAR2(12), DATAFATTURA VARCHAR2(12), DATESAISIE VARCHAR2(12), DATECOMPTABLE VARCHAR2(12), DATEPAIEMENT VARCHAR2(12), DEVISEFACTURE VARCHAR2(12), DEVISEENTITE VARCHAR2(12), CONTO VARCHAR2(72), MONTANTHT NUMBER(9,2), MONTATTTC NUMBER(9,2), TVA NUMBER(9,2), QUANTITA VARCHAR2(12), FABRICANT VARCHAR2(72), CENTROCOSTO VARCHAR2(72), VALUEHOME NUMBER, TAXLINECODE VARCHAR2(12), HOMETAXTURN NUMBER, EL2 VARCHAR2(72), LINETYPE NUMBER(5), TAXCODE VARCHAR2(12), PERCENTUALE NUMBER, PERIOD NUMBER(5), XREF VARCHAR2(72) ) on commit preserve rows; /

Step 2: Create the Return Type This step creates the type that will be used to return the results from the temp table. This type should describe the result set you are expecting in the Jasper Report.
CREATE OR REPLACE TYPE coda.BNP_RPT_ACQUISTI_AUTO AS OBJECT ( CMPCODE VARCHAR2(12), DOCCODE VARCHAR2(12), DOCNUM VARCHAR2(12), PERIODO VARCHAR2(8), CODEENTITE VARCHAR2(12), CODFORNITORE VARCHAR2(72), NUMINTERNOFATTURA VARCHAR2(35), NUMERORIGHEFATTURA NUMBER(5), NUMEROFATTURAFORNITORE VARCHAR2(32), TIPODOCUMENTO VARCHAR2(12), TIPOTRANSAZIONE VARCHAR2(12), DATAFATTURA VARCHAR2(12), DATESAISIE VARCHAR2(12), DATECOMPTABLE VARCHAR2(12), DATEPAIEMENT VARCHAR2(12), DEVISEFACTURE VARCHAR2(12), DEVISEENTITE VARCHAR2(12), CONTO VARCHAR2(72), MONTANTHT NUMBER(9,2), MONTATTTC NUMBER(9,2), TVA NUMBER(9,2), QUANTITA VARCHAR2(12), FABRICANT VARCHAR2(72), CENTROCOSTO VARCHAR2(72), VALUEHOME NUMBER, TAXLINECODE VARCHAR2(12), HOMETAXTURN NUMBER, EL2 VARCHAR2(72), LINETYPE NUMBER(5), TAXCODE VARCHAR2(12), PERCENTUALE NUMBER, PERIOD NUMBER(5), XREF VARCHAR2(72) ); /

Step 3: Create a Table of the Type In this step we create a table of the type we created in the previous step. This table is what we will be selecting from in the Jasper Report. It is not a real table, but instead a type or object representing the structure of the table that we will funnel the stored procedures results through.
CREATE OR REPLACE TYPE CODA.BNP_RPT_ACQUISTI_AUTO_TABLE AS TABLE OF CODA.BNP_RPT_ACQUISTI_AUTO; /

Step 4: Create the Package Next, create the package which will perform the needed data gathering
create or replace package coda.PKG_BNP is -- Author : 470030 -- Created : 07/04/2009 17:41:04 -- Purpose : FUNCTION FNCT_BNP_RPT_ACQUISTI_AUTO ( nANNO NUMBER, nINIZIOPERIODO NUMBER, nFINEPERIODO NUMBER ) return BNP_RPT_ACQUISTI_AUTO_TABLE pipelined; end ; / create or replace package body coda.PKG_BNP is -- Private type declarations PROCEDURE BNP_RPT_ACQUISTI_AUTO(nANNO NUMBER, nINIZIOPERIODO NUMBER, nFINEPERIODO NUMBER) AS BEGIN EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_BNP_REPORT'; COMMIT; --Fatture INSERT INTO TEMP_BNP_REPORT (CMPCODE, DOCCODE, DOCNUM, PERIODO, CODEENTITE, CODFORNITORE, NUMINTERNOFATTURA, NUMERORIGHEFATTURA, NUMEROFATTURAFORNITORE, TIPODOCUMENTO, TIPOTRANSAZIONE, DATAFATTURA, DATESAISIE, DATECOMPTABLE, DATEPAIEMENT, DEVISEFACTURE, DEVISEENTITE, CONTO, MONTANTHT, MONTATTTC, TVA, QUANTITA, FABRICANT,

CENTROCOSTO, VALUEHOME, TAXLINECODE, HOMETAXTURN, EL2, LINETYPE, TAXCODE, PERCENTUALE, PERIOD, XREF) SELECT dh.CMPCODE, dh.DOCCODE, dh.DOCNUM, TO_CHAR(DH.YR) || TO_CHAR(PERIOD, '00') AS PERIODO, 'ARVIT' AS CODEENTITE, dlriep.EL2, pl.USRREF1, 1 AS NUMERORIGHEFATTURA, dl.REF1 AS NUMEROFATTURAFORNITORE, 'FT' AS TIPODOCUMENTO, 'RE' AS TIPOTRANSAZIONE, TO_CHAR(dh.DOCDATE, 'YYYYMMDD') AS DATAFATTURA, TO_CHAR(dl.VALDATE, 'YYYYMMDD') AS DATESAISIE, TO_CHAR(dl.VALDATE, 'YYYYMMDD') AS DATECOMPTABLE, NVL(TO_CHAR(dlriep.PAYDATE, 'YYYYMMDD'), '') AS DATEPAIEMENT, 'EUR' AS DEVISEFACTURE, 'EUR' AS DEVISEENTITE, dl.EL1 AS CONTO, 0 AS MONTANTHT, 0 AS MONTATTTC, 0 AS TVA, '' AS QUANTITA, '' AS FABRICANT, dl.EL6 AS CENTROCOSTO, dl.VALUEHOME, dl.TAXLINECODE, dl.HOMETAXTURN, dl.EL2, dl.LINETYPE, tline.TAXCODE, RATE / 10000000 AS PERCENTUALE, dh.PERIOD, dh.XREF FROM OAS_DOCHEAD dh, OAS_DOCLINE dl, OAS_TAXLINE tline, OAS_TAXLIST tlist, OAS_DOCLINE dlriep, OAS_PAYLINE pl WHERE tlist.CMPCODE = tline.CMPCODE AND tlist.TAXCODE = tline.TAXCODE AND tline.CMPCODE = dl.CMPCODE AND tline.DOCCODE = dl.DOCCODE AND tline.DOCNUM = dl.DOCNUM AND tline.DOCLINENUM = dl.DOCLINENUM AND pl.CMPCODE(+) = dlriep.CMPCODE AND pl.DOCCODE(+) = dlriep.DOCCODE AND pl.DOCNUM(+) = dlriep.DOCNUM AND pl.DOCLINENUM(+) = dlriep.DOCLINENUM AND pl.PARTPAIDORIG In (0, 1) AND dlriep.CMPCODE = dh.CMPCODE AND dlriep.DOCCODE = dh.DOCCODE

AND AND AND AND AND AND AND AND

dlriep.DOCNUM = dh.DOCNUM dlriep.LINETYPE = 157 dl.CMPCODE = dh.CMPCODE dl.DOCCODE = dh.DOCCODE dl.DOCNUM = dh.DOCNUM dl.LINETYPE = 158 dh.CMPCODE = '22-1' dh.DOCCODE In ('FORFATCSP1-I', 'FORFATCSP3-I', 'FORFATCSP4-I', 'FORFATCSP7-I', 'FORFTCSP15-I', 'FORFATCSP-I') -- A99 DTI 7940

2006/01/30 -AND dh.PERIOD >= nINIZIOPERIODO AND dh.PERIOD <= nFINEPERIODO AND dh.YR = nANNO AND dh.STATUS = 78; /* Note di credito */ INSERT INTO TEMP_BNP_REPORT (CMPCODE, DOCCODE, DOCNUM, PERIODO, CODEENTITE, CODFORNITORE, NUMINTERNOFATTURA, NUMERORIGHEFATTURA, NUMEROFATTURAFORNITORE, TIPODOCUMENTO, TIPOTRANSAZIONE, DATAFATTURA, DATESAISIE, DATECOMPTABLE, DATEPAIEMENT, DEVISEFACTURE, DEVISEENTITE, CONTO, MONTANTHT, MONTATTTC, TVA, QUANTITA, FABRICANT, CENTROCOSTO, VALUEHOME, TAXLINECODE, HOMETAXTURN, EL2, LINETYPE, TAXCODE, PERCENTUALE) SELECT dh.CMPCODE, dh.DOCCODE, dh.DOCNUM, TO_CHAR(DH.YR) || TO_CHAR(DH.PERIOD, '00'), 'ARVIT', dlriep.EL2, pl.USRREF1, 1, dl.REF1, 'NC', 'RE', TO_CHAR(dh.DOCDATE, 'YYYYMMDD'), TO_CHAR(dl.VALDATE, 'YYYYMMDD'), TO_CHAR(dl.VALDATE, 'YYYYMMDD'),

NVL(TO_CHAR(dlriep.PAYDATE, 'YYYYMMDD'), ''), 'EUR', 'EUR', dl.EL1, 0, 0, 0, '', '', dl.EL6, dl.VALUEHOME, dl.TAXLINECODE, dl.HOMETAXTURN, dl.EL2, dl.LINETYPE, tline.TAXCODE, RATE / 10000000 FROM OAS_DOCHEAD dh, OAS_DOCLINE dl, OAS_TAXLINE tline, OAS_TAXLIST tlist, OAS_DOCLINE dlriep, OAS_PAYLINE pl WHERE tlist.CMPCODE = tline.CMPCODE AND tlist.TAXCODE = tline.TAXCODE AND AND AND AND AND AND AND AND AND AND AND AND AND AND AND AND AND AND AND tline.CMPCODE = dl.CMPCODE tline.DOCCODE = dl.DOCCODE tline.DOCNUM = dl.DOCNUM tline.DOCLINENUM = dl.DOCLINENUM pl.CMPCODE(+) = dlriep.CMPCODE pl.DOCCODE(+) = dlriep.DOCCODE pl.DOCNUM(+) = dlriep.DOCNUM pl.DOCLINENUM(+) = dlriep.DOCLINENUM pl.PARTPAIDORIG In (0, 1) dlriep.CMPCODE = dh.CMPCODE dlriep.DOCCODE = dh.DOCCODE dlriep.DOCNUM = dh.DOCNUM dlriep.LINETYPE = 157 dl.CMPCODE = dh.CMPCODE dl.DOCCODE = dh.DOCCODE dl.DOCNUM = dh.DOCNUM dl.LINETYPE = 158 dh.CMPCODE = '22-1' dh.DOCCODE In ('FORNCCSP1-I', 'FORNCCSP3-I', 'FORNCCSP4-I', 'FORNCCSP7-I', 'FORNCCSP15-I', 'FORNCCSP-I') -- A99 DTI 7940

2006/01/30 -AND dh.PERIOD >= nINIZIOPERIODO AND dh.PERIOD <= nFINEPERIODO AND dh.YR = nANNO AND dh.STATUS = 78; DELETE TEMP_BNP_REPORT WHERE DATECOMPTABLE IS NULL; UPDATE TEMP_BNP_REPORT SET DATECOMPTABLE = TO_CHAR(nANNO - 1) || '1231' WHERE CONTO IN (SELECT CONTO FROM ARVAL_BNP_REPORT_CONTI_DT3112); UPDATE TEMP_BNP_REPORT SET NUMINTERNOFATTURA = rtrim(NUMINTERNOFATTURA); COMMIT;

END; FUNCTION FNCT_BNP_RPT_ACQUISTI_AUTO(nANNO NUMBER, nINIZIOPERIODO NUMBER, nFINEPERIODO NUMBER) return BNP_RPT_ACQUISTI_AUTO_TABLE pipelined is PRAGMA AUTONOMOUS_TRANSACTION; TYPE ref0 is REF CURSOR; myCursor ref0; out_rec CODA.BNP_RPT_ACQUISTI_AUTO := CODA.BNP_RPT_ACQUISTI_AUTO(null, null, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, 0, 0, 0, null, null, null, 0, null, 0, null, 0, null, 0, 0, null); BEGIN BNP_RPT_ACQUISTI_AUTO(nANNO, nINIZIOPERIODO, nFINEPERIODO); open myCursor for select CMPCODE, DOCCODE, DOCNUM, PERIODO, CODEENTITE, CODFORNITORE, NUMINTERNOFATTURA, NUMERORIGHEFATTURA, NUMEROFATTURAFORNITORE, TIPODOCUMENTO, TIPOTRANSAZIONE, DATAFATTURA,

DATESAISIE, DATECOMPTABLE, DATEPAIEMENT, DEVISEFACTURE, DEVISEENTITE, CONTO, MONTANTHT, MONTATTTC, TVA, QUANTITA, FABRICANT, CENTROCOSTO, VALUEHOME, TAXLINECODE, HOMETAXTURN, EL2, LINETYPE, TAXCODE, PERCENTUALE, PERIOD, XREF from TEMP_BNP_REPORT; LOOP FETCH myCursor into OUT_REC.CMPCODE, OUT_REC.DOCCODE, OUT_REC.DOCNUM, OUT_REC.PERIODO, OUT_REC.CODEENTITE, OUT_REC.CODFORNITORE, OUT_REC.NUMINTERNOFATTURA, OUT_REC.NUMERORIGHEFATTURA, OUT_REC.NUMEROFATTURAFORNITORE, OUT_REC.TIPODOCUMENTO, OUT_REC.TIPOTRANSAZIONE, OUT_REC.DATAFATTURA, OUT_REC.DATESAISIE, OUT_REC.DATECOMPTABLE, OUT_REC.DATEPAIEMENT, OUT_REC.DEVISEFACTURE, OUT_REC.DEVISEENTITE, OUT_REC.CONTO, OUT_REC.MONTANTHT, OUT_REC.MONTATTTC, OUT_REC.TVA, OUT_REC.QUANTITA, OUT_REC.FABRICANT, OUT_REC.CENTROCOSTO, OUT_REC.VALUEHOME, OUT_REC.TAXLINECODE, OUT_REC.HOMETAXTURN, OUT_REC.EL2, OUT_REC.LINETYPE, OUT_REC.TAXCODE, OUT_REC.PERCENTUALE, OUT_REC.PERIOD, OUT_REC.XREF; EXIT WHEN myCursor%NOTFOUND; PIPE ROW(out_rec); END LOOP; CLOSE myCursor; RETURN; END; begin -- Initialization null; end;

Step 5: Testing and Using the Stored Function In order to use the stored function you execute the code below:
select * from TABLE(CODA.PKG_BNP.FNCT_BNP_RPT_ACQUISTI_AUTO(2008,1,1))

This code can now be used within a Jasper Report, as you have turned a stored procedure into a stored function accessible with a standard select. To the Jasper Report you are merely issuing a standard query.

Subject: Overview of Temporary Tables Doc ID: 68098.1 Modified Date : 04-NOV-2008

Type: BULLETIN Status: PUBLISHED

You might also like