Related
i have a very strange issue going on with nested cursor loops.
i've pasted the code below. The overall function of the code is to fetch each row from cursor cur1 and use some info from cur1 to run a loop on another cursor cur2. fairly straight forward - just like a nested 2-tier for loop. The issue I run into is that when the first (any?) iteration through cur2 produces NOTFOUND, the subsequent/other iterations also produce NOTFOUND even though i explicitly run the cursor select statement manually and see data. I've also modified the data so that the first iteration DOES have data as a test, and everything works fine...
create or replace PROCEDURE EvalEqu
(prim_indg_ref_in NUMBER,
stock_ref_in NUMBER)
IS
SD_REF STOCK_DETAILS.STOCK_DETAIL_REF%TYPE; -- Variable used to hold stock_details_ref Stock_details
CAL_REF CALCULATIONS.CALC_REF%TYPE; -- Variable used to hold calc_ref value
CALCSTRG CALCULATIONS.CALCULATION_STATEMENT%TYPE; -- Variable used to hold calculation string from Calculations
CALCSTRGTEMP CALCULATIONS.CALCULATION_STATEMENT%TYPE; -- Variable used to hold calculation as parm values are substitued in
CALCVALTEMP STOCK_DETAILS.DATA%TYPE; -- Variable used hold andcheck calculated value sig figs
CALCVAL STOCK_DETAILS.DATA%TYPE; -- Variable used to populate calc value on Stock_details once calcualted
PARM CALC_COA_VALS.PARM_NAME%TYPE; -- Variable used to hold parm names used for substitution
PARMVAL STOCK_COA_DATA.DATA%TYPE; -- Variable used to hold CoA value from form that replaces PARM value
--Define cursor to hold all calculations associated to a stock record
cursor stock_calc is select SD.STOCK_DETAIL_REF, CALC.CALC_REF, CALC.CALCULATION_STATEMENT
from stock_details sd,
calculations calc
where SD.LABEL_REF = calc.label_ref
and CALC.Prim_Ing_Ref = prim_indg_ref_in
and SD.STOCK_REF = stock_ref_in;
--Define cursor to hold all parm names and their respective CoA values from form
cursor calc_parms is select CCV.PARM_NAME, SCD.DATA
from calc_coa_vals ccv, stock_coa_data scd
where CCV.COA_VAL_REF=SCD.COA_VAL_REF
and SCD.STOCK_REF=stock_ref_in
and CCV.CALC_REF=CAL_REF;
BEGIN
-- Open calculation cursor
IF NOT stock_calc%ISOPEN then
OPEN stock_calc;
END IF;
-- Loop through each calcualtion for Stock to calculate values
LOOP
FETCH stock_calc INTO SD_REF, CAL_REF, CALCSTRG;
EXIT WHEN stock_calc%NOTFOUND;
-- Open parm cursor to loop through each parm used in calculation
IF NOT calc_parms%ISOPEN then
OPEN calc_parms;
END IF;
FETCH calc_parms into PARM, PARMVAL;
IF calc_parms%NOTFOUND
THEN
-- No parameters are associated with this calculation
-- It is a simple integer and can be returned as such
CALCVAL := CALCSTRG;
ELSE
WHILE calc_parms%FOUND
LOOP
CALCSTRGTEMP := REPLACE(CALCSTRG, PARM, PARMVAL);
CALCSTRG := CALCSTRGTEMP;
FETCH calc_parms into PARM, PARMVAL;
END LOOP;
CLOSE calc_parms;
-- evaluate the equation
EXECUTE IMMEDIATE 'SELECT to_char(('||CALCSTRG||'),''999999999990.099999999999999'') from dual ' INTO CALCVALTEMP;
IF instr(to_char(to_number(CALCVALTEMP)), '.') = 0 -- whole number or 0, no padding
THEN
CALCVAL := to_char(to_number(CALCVALTEMP));
ELSE
IF ABS(to_number(CALCVALTEMP)) < 1
THEN
IF instr(CALCVALTEMP, '-') = 0 -- Indicates positive number
THEN
EXECUTE IMMEDIATE 'SELECT LPAD(RPAD(to_CHAR(trunc(to_number('||CALCVALTEMP||'),12-(instr('||CALCVALTEMP||',''.'')-1))), 12,''0''), 13, ''0'') from dual ' INTO CALCVAL;
ELSE -- Negative number
EXECUTE IMMEDIATE 'SELECT LPAD(RPAD(to_CHAR(trunc(ABS(to_number('||CALCVALTEMP||')),12-(instr(ABS(to_number('||CALCVALTEMP||')),''.'')-2))), 12,''0''), 14, ''-0'') from dual ' INTO CALCVAL;
END IF;
ELSE
IF instr(CALCVALTEMP, '-') = 0 -- Indicates positive number
THEN
EXECUTE IMMEDIATE 'SELECT RPAD(to_CHAR(trunc(to_number('||CALCVALTEMP||'),12-(instr('||CALCVALTEMP||',''.'')-1))), 13,''0'') from dual ' INTO CALCVAL;
ELSE -- Negative number
EXECUTE IMMEDIATE 'SELECT RPAD(to_CHAR(trunc(to_number('||CALCVALTEMP||'),12-(instr('||CALCVALTEMP||',''.'')-2))), 14,''0'') from dual ' INTO CALCVAL;
END IF;
END IF;
END IF;
END IF;
-- Update stock_details record with newly calculated value
UPDATE stock_details
SET DATA = CALCVAL
WHERE STOCK_DETAIL_REF = SD_REF;
END LOOP;
CLOSE stock_calc;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
Data for cursor 1: stock_ref=124000
STOCK_DETAIL_REF STOCK_REF LABEL_REF DATA
--------------------------------------- --------------------------------------- --------------------------------------- ------------------------------------------------------------
217924 124000 1000 1.0
217925 124000 2602 (A1*2)
217926 124000 2603 (A1*3)
217927 124000 2604 (A1*4)
Prim_Ing_Ref = 1234
CALC_REF Prim_Ing_Ref LABEL_REF CALCULATION_STATEMENT
--------------------------------------- --------------------------------------- --------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
846 1234 666 1.0
847 1234 667 1.0
848 1234 690 1.0
849 1234 1000 1.0
850 1234 2602 (A1*2)
851 1234 2603 (A1*3)
852 1234 2604 (A1*4)
Result from cursor1:
STOCK_DETAIL_REF CALC_REF CALCULATION_STATEMENT
--------------------------------------- --------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
217924 849 1.0
217925 850 (A1*2)
217926 851 (A1*3)
217927 852 (A1*4)
Cursor 2 looks for values for the parameters in the equations and substitutes them for the requested values and evaluates the equations. Cursor 2 seems to returned nothing for ALL entries in Cursor 1 if ANY NOTFOUND occurs. so for the 1.0 value, there are no parameters., but this causes the rest of the cursor loops to fail
Cursor 2 data:
STOCK_REF CALC_REF PARM_NAME DATA
--------------------------------------- --------------------------------------- --------- ------------------------------------------------------------
124000 850 A1 25
124000 851 A1 25
124000 852 A1 25
these are for the 3 equations shown above in CALCULATION_STATEMENT. however, as said, the routine fails, just for this specific instance where static numeric values are intermixed with equations (i.e. the cursor2 returns NOTFOUND for at least one item in cursor1). manually running the cursor's select statement retrieves the data just fine. I can only assume that the implementation of the cursor is incorrect somehow.
you need to pass the value of c1 into c2 as a parameter. Have a look at the example here:
PL/SQL referencing another cursor in a cursor
BTW, I assume this line:
FETCH stock_calc INTO ...
should be:
FETCH cur1 INTO ...
Update Following Comments
(Please tick this if you felt I have helped with the answer)
To re-iterate what was said in the comments:
you need to CLOSE calc_parms within IF calc_parms%NOTFOUND THEN... at the moment you only close it in the ELSE statement.
Also, if performance is an issue, you should look at looping through calc_parms before you loop through stock_calc. As calc_parms is not being changed by anything happening in stock_calc, PARM and PARMVAL have exactly the same values in every loop through stock_calc.
I'm having an issue with an SQLRPGLE program which must insert records in a table.
I've been debugging my program with strdbg command and I found out that the problem was caused by a packed decimal field called Mes in my data structure, when trying to insert that value into an integer field.
Source data structure definition (the first field in the DS is the field which hypotetically needs casting):
D DataDS DS QUALIFIED TEMPLATE
D Mes 6P 0
D Unidad 2P 0
D Subunidad 3P 0
D Grupopas 8P 0
D Productor 8P 0
D Asegurado 9P 0
. . .
. . .
. . .
The destination field is an integer.
P Exportar...
P B
D PI
D data DS LIKEDS(DataDS)
/free
ClrBI();
CLEAR data;
EXEC SQL DECLARE B1 CURSOR FOR
SELECT MES,UNIDAD, SUBUNIDAD, GRUPOPAS,
PRODUCTOR, ASEGURADO, RAMA, TIPO_MOVIM,
SUCURSAL,IFNULL(FACULTATIV,' '), CONDIC_IVA,
UNIDAD_FC, SUBUNID_FC, GRUPOPR_FC,
MATRICULA, CANALCOBRO, IFNULL(CANALCOBRX,' '),
PRIMACOB, PREMIOCOB, DEREMICOB,
RECADMCOB, RECFINCOB, IVACOB,
PER_IVACOB, ACR_IVACOB, ISSCOB,
INTERNOCOB, PER_IBRCOB, COMISICOBR,
COMISIAGEN,COMISIORGA,COMISIOTRS
COMISITOT
FROM BICOBRANZA
WHERE MES = :mes;
EXEC SQL OPEN B1;
EXEC SQL FETCH NEXT FROM B1 INTO :data;
DOW SQLCOD = 0;
SetBI(data);
CLEAR data;
EXEC SQL FETCH NEXT FROM B1 INTO :data;
ENDDO;
EXEC SQL CLOSE B1;
/end-free
P E
This is the first time I see an error like this.
Does anyone faced this problem before? I don't know even where to start.
Thanks in advance.
A six digit number with no decimal digits (6P 0) has a value range of -999999 to 999999.
An small integer column has a value range of -32768 to 32767..
Casting will work just fine, as long as your packed field value fits.
You'll need to have the DB column be a large (4 byte (10 digits)) or big ( 8 bytes (20 digits)) integer.
After reading several articles about SQLRPGLE and retrieving data and storing them in data structure arrays, I came up with dynamic sql statements.
This works fine as long as I am using these dynamic to-replace fields for my where condition. But as soo as I am using these ? parameter in the select part, or in general as replacement for database fields, the result is blank.
Here is the DDS definition and the program:
TESTPF
A**************************************************************************
A*
A*-------------------------------------------------------------------------
A*
A R TESTPFR
A
A FLD01 2S 0
A FLD02 20A
A
A**************************************************************************
I have already filled this file with some dummy data. Here is what's inside:
runqry () qtemp/testpf
FLD01 FLD02
000001 1 Text 01
000002 2 Text 02
000003 3 Text 03
000004 4 Text 04
000005 5 Text 05
000006 6 Text 06
000007 7 Text 07
000008 8 Text 08
000009 9 Text 09
000010 10 Text 10
And this is the program:
TST001I
D**********************************************************************************************
D* Standalone Fields
D*---------------------------------------------------------------------------------------------
D stm s 500a inz(*blanks)
D fieldName01 s 10a inz(*blanks)
D fieldName02 s 10a inz(*blanks)
D fieldName03 s 2a inz(*blanks)
D text s 20a inz(*blanks)
D
C**********************************************************************************************
C* M A I N P R O G R A M M
C**********************************************************************************************
stm = 'SELECT fld02 FROM testpf WHERE fld01 = 1';
exec sql prepare s1 from :stm;
exec sql declare c1 cursor for s1;
exec sql open c1;
exec sql fetch c1 into :text;
exec sql close c1;
dsply text; // Prints 'Text 01'
text = *blanks;
stm = 'SELECT fld02 FROM testpf WHERE fld01 = ?';
exec sql prepare s2 from :stm;
exec sql declare c2 cursor for s2;
fieldName03 = '2';
exec sql open c2 using :fieldName03;
exec sql fetch c2 into :text;
exec sql close c2;
dsply text; // Prints 'Text 02'
text = *blanks;
stm = 'SELECT ? FROM testpf WHERE fld01 = 3';
exec sql prepare s3 from :stm;
exec sql declare c3 cursor for s3;
fieldName01 = 'FLD02';
exec sql open c3 using :fieldName01;
exec sql fetch c3 into :text;
exec sql close c3;
dsply text; // Prints ' '
text = *blanks;
stm = 'SELECT ? FROM testpf WHERE ? = ?';
exec sql prepare s4 from :stm;
exec sql declare c4 cursor for s4;
fieldName01 = 'FLD02';
fieldName02 = 'FLD01';
fieldName03 = '4';
exec sql open c4 using :fieldName01, :fieldName02, :fieldName03;
exec sql fetch c4 into :text;
exec sql close c4;
dsply text; // Prints ' '
text = *blanks;
*inlr = *on;
C**********************************************************************************************
This is the output:
DSPLY Text 01
DSPLY Text 02
DSPLY
DSPLY
DSPLY
May someone help me and explain why this is the case?
When using a prepared statement, you can use ? as a parameter marker wherever you can use a host variable in a static statement. Of your four sample prepared statements, the first 3 should work, though the third one will not return what you seem to expect as it is equivalent to:
SELECT 'FLD02' FROM testpf WHERE fld01 = 3
I would expect to receive the value 'FLD02' as the result, not the value in column FLD02. This is because the ? is not a string replacement marker, but a parameter field marker. You can't use it to select a column, but you can use it to provide a value for comparisons, or a constant to be output.
The fourth sample is valid SQL, but it is equivalent to:
SELECT 'FLD02' FROM testpf WHERE 'FLD01' = '4'
This will return nothing since 'FLD01' does not equal '4'.
Another consequence of this is that the ? can be used to provide a numeric value to the prepared statement. So you can do this:
dcl-s seqno Packed(5:0);
exec sql declare c2 cursor for s2;
stm = 'SELECT fld02 FROM testpf WHERE fld01 = ?';
exec sql prepare s2 from :stm;
seqno = 2;
exec sql open c2 using :seqno;
Also notice that I removed the declaration of the cursor to somewhere outside the logic flow as the declaration is not an executable statement. I see programs where the declare is in a subroutine that is called before a separate subroutine containing the open for the cursor. This is semantically incorrect. The DECLARE CURSOR statement is more correctly equivalent to an RPGLE dcl- statement. But because the SQL precompiler processes the source linearly, largely without regard to subroutines or sub-procedures, the requirement is for the DECLARE CURSOR to be physically before the OPEN in the source.
Generally I like to put my SQL Declares at the head of the program right after the SET OPTION statement which must be the first SQL embedded in the program. This is where I put the declares when I am using prepared statements. I also declare the statement name as well though this isn't strictly necessary. There is a little gotcha for this though, and that exists when using static SQL with locally scoped host variables. To deal with this, I declare static cursors a bit differently when using sub-procedures. The SQL precompiler recognizes that sub-procedures use locally scoped variables, so if you are declaring a static cursor with locally scoped host variables, the host variables and the cursor declaration must be in the same scope. That means I must declare my static cursors in the same sub-procedure as the open. I still declare the cursor up near the RPGLE dcl- statements to keep the declarations together.
So i have a requirement where I need to read through records of all records of a file and insert them into another file if they meet a set of rules which are described in another table as shown below..
A record after it has been read from the first file has to meet all the sequences of at least one Rule to make it eligible to be written into the Second table.
For example once a record is read from CAR file, the rules below have to be checked till all sequences of atleast one rule set is satisfied. For this I was planning to Create a dynamic SQL program something of this sort. But this does not work as Prepared SQL does not support host variables.
If any body can suggest or provide any guidance on how to create SQL statemtns dynamically and check if records satisfy the required rules for them to be entered into the second file, it would be great
So basically what I am looking for is once I select a field from a table, how do I store it somehere to do further validation and checking.
Update
:
Based on the intelligent advice from Danny117, I have come up with the below code:
H Option(*NoDebugIO:*SrcStmt)
D RULEDS E DS EXTNAME(RULESTABLE)
D MAXRUL S 1 0
D MAXSEQ S 1 0
D STMT S 512
D WHERESTMT S 512 INZ('')
D FullSqlStmt S 512 INZ('')
D RULINDEX S 1 0 INZ(1)
D SEQINDEX S 1 0 INZ(1)
D APOS C CONST('''')
/Free
Exec SQL SELECT MAX(RULENO)INTO :MAXRUL FROM RULESTABLE;
Exec SQL DECLARE RULCRS CURSOR FOR SELECT * FROM RULESTABLE;
Exec SQL OPEN RULCRS;
Exec SQL FETCH RULCRS INTO :RULEDS;
DoW (Sqlcod = 0 AND RULINDEX <= MAXRUL);
Exec SQL SELECT MAX(SEQNO) INTO :MAXSEQ FROM RULESTABLE
WHERE RULENO=:RULINDEX ;
DoW (SEQINDEX <= MAXSEQ);
If (Position <> '');
Field = 'SUBSTR('+%Trim(Field)+','+%Trim(Position)+','
+'1'+')';
EndIf;
WhereStmt = %Trim(WhereStmt) + ' ' + %Trim(field)+ ' ' +
%Trim(condition) + ' ' + APOS + %Trim(Value) + APOS;
If (SeqIndex < MaxSeq);
WhereStmt = %Trim(WhereStmt) + ' AND ';
EndIf;
Exec SQL FETCH NEXT FROM RULCRS INTO :RULEDS;
SeqIndex = SeqIndex + 1;
EndDo;
FullSqlStmt = %Trim('INSERT INTO ITMRVAT SELECT * +
FROM ITMRVA WHERE '+ %Trim(WhereStmt));
Exec SQL Prepare InsertStmt from :FullSqlStmt;
Exec SQL EXECUTE InsertStmt;
RulIndex = RulIndex + 1;
EndDo;
This produces SQL statement as shown below which is what I want. Now let me go ahead and look at the other parts of the code.
> EVAL FullSqlStmt
FULLSQLSTMT =
....5...10...15...20...25...30...35...40...45...50...55...60
1 'INSERT INTO ITMRVAT SELECT * FROM ITMRVA WHERE STID = 'PLD' '
61 'AND ENGNO LIKE '%415015%' AND SUBSTR(ENGNO,1,1) = 'R' AND SU'
121 'BSTR(ENGNO,5,1) = 'Y' '
181 ' '
241 ' '
301 ' '
361 ' '
421 ' '
481 ' '
But the issue is now as I mentioned in my comment to Danny, how to handle if a new rule involving second table is specified..
Embedded SQL does allow for 'dynamic statements' in ILE languages. You are able to have a query within a character field and then pass it into the Embedded SQL.
Dcl-S lQuery Varchar(100);
lQuery = 'SELECT * FROM CUST';
EXEC SQL
PREPARE SCust FROM :lQuery;
EXEC SQL
DECLARE SearchCust CURSOR FOR SCust;
//Continue working with cursor..
You may want to just prepare, execute and return a result set:
lQuery = 'SELECT * FROM CUST WHERE ID = ' + %Char(CustID);
EXEC SQL
PREPARE SCust FROM :lQuery;
DECLARE c1 CURSOR FOR SCust;
OPEN c1;
FETCH c1 INTO :CustDS;
CLOSE c1;
Optional extra: You may also want to use field markers (?) in your query.
//'SELECT * FROM CUST WHERE CUSTID = ?';
EXEC SQL OPEN SearchCust USING :CustID;
//'INSERT INTO CUST VALUES(?,?)';
EXEC SQL EXECUTE CUST USING :CustID;
You have to translate the rules into a join statement or a where clause. The join statement is more complex so go that route.
If you were smart (and you are) consider saving the rules as a SQL clause that you can join or use in a where clause. Its infinitely flexible this way a more modern design.
rule 1 / car.year = 1990 and car.engno like '%43243%' and substring(car.vin,12,1) = 'X'
eval statement =
insert into sometable
Select car.* from car
join sysibm.sysdummy1
on car.year = 1990
and car.engno lile '%43243%'
...etc on to rule 2 starting with "OR"
or car.year = PLD
and car.engno like '%1234%'
...etc other rules starting with "OR"
exec immediate statement
Please i need help.
(I SEARCHED A lot and get more confused . )
I use Toad 9.7.25 and i made this procedure (in a package)
PROCEDURE ReportaCC(pfcorte IN DATE, lcursor IN OUT SYS_REFCURSOR)
IS
BEGIN
OPEN lcursor FOR
select c1, c3, c3 from table1 where hdate = pfcorte;
close lcursor;
END;
In toad's sql editor i´d like execute that procedure and show the cursor results in toad's datagrid:
--- I WANT THIS CODE CAN EXECUTE IN TOAD'S SQL EDITOR.
DECLARE
PFCORTE DATE;
LCURSOR SYS_REFCURSOR;
BEGIN
PFCORTE := '31/08/2012';
-- LCURSOR := NULL; -- Modify the code to initialize this parameter
mypaq.REPORTACC( TO_DATE(PFCORTE,'DD/MM/YYYY') , LCURSOR );
:to_grid := LCURSOR;
COMMIT;
END;
When i execute the script (F9), and set the variable :to_grid type cursor,
i get the next error:
"ORA-24338: statement handle not executed"
What can be the problem
Thanks in advance.
Thanks four your posts... worked fine!
But now have another question...
If i replace the simple query (select c1, c2, c3 from table...) for a mor complex like this:
PROCEDURE ReportaCC(pfcorte IN DATE, lcursor OUT SYS_REFCURSOR)
IS
BEGIN
OPEN lcursor FOR
SELECT ENC.CVEOTORGANTE, ENC.NOMBREOTORGANTE, ENC.IDENDINTIFICADORDEMEDIO, TO_CHAR(SYSDATE, 'YYYYMMDD') AS FECHAEXT, ENC.NOTAOTORGANTE,
CIRCRED.valida_cc.QUITASIGNOS(VCL.APELLIDOPATERNO) AS VAL_APELLIDOPATERNO,
CIRCRED.valida_cc.QUITASIGNOS(VCL.APELLIDOMATERNO) AS VAL_APMATERNO,
CIRCRED.valida_cc.QUITASIGNOS(VCL.APELLIDOADICIONAL) AS APELLIDOADICIONAL ,
CIRCRED.valida_cc.QUITASIGNOS(VCL.NOMBRES) AS NOMBRES,
VCL.FECHANACIMIENTO,
circred.valida_cc.valida_rfc(Vcl.rfc,'CORRIGE') AS VALRFC,
circred.valida_cc.valida_curp(VCL.CURP,'CORRIGE') AS VALCURP, VCL.NACIONALIDAD,
circred.valida_cc.valida_RESIDENCIA('ESIACOM', SC.TIPOVIV ) AS VAL_RESIDENCIA, VCL.NUMEROLICENCIACONDUCIR,
circred.valida_cc.valida_EDOCIVIL('ESIACOM', VCL.ESTADOCIVIL) AS VAL_ESTADOCIVIL, VCL.SEXO,
circred.valida_cc.valida_IFE(VCL.CLAVEELECTORIFE,'CORRIGE') AS CLAVEELECTORIFE,
VCL.NUMERODEPENDIENTES,
VCL.FECHADEFUNCION, VCL.INDICADORDEFUNCION, VCL.TIPOPERSONA,
CIRCRED.valida_cc.QUITASIGNOS(VCL.DIRECCION) AS DIRECCION,
CIRCRED.valida_cc.QUITASIGNOS(VCL.COLONIAPOBLACION) AS COLONIAPOBLACION,
CIRCRED.valida_cc.QUITASIGNOS(VCL.DELEGACIONMUNICIPIO) AS DELEGACIONMUNICIPIO,
CIRCRED.valida_cc.QUITASIGNOS(VCL.CIUDAD) AS CIUDAD,
VCL.ESTADO, circred.valida_cc.valida_cp(VCL.CP, VCL.CDGEF) AS VAL_CP, VCL.FECHARESIDENCIA,
circred.valida_cc.valida_TEL(VCL.NUMEROTELEFONO,'CORRIGE') AS VAL_TEL, circred.valida_cc.valida_TIPODOMICILIO('ESIACOM', 'C') AS VAL_TIPODOMICILIO, VCL.TIPOASENTAMIENTO,
EMP.*,
ENC.CVEOTORGANTE CVEACTUAL, ENC.NOMBREOTORGANTE, SAL.CUENTAACTUAL, SAL.TIPORESPONSABILIDAD, SAL.TIPOCUENTA, SAL.TIPOCONTRA, SAL.CLAVEUNIDADMONETARIA, SAL.VALORACTIVOVALUACION,
SAL.NUMPAGOS, SAL.FREQPAGOS,SAL.PAGOPACCL, SAL.FECHAAPERTURACUENTA,
TO_CHAR(circred.valida_cc.FUN_FULTDEPCL(sal.CLNS, sal.CDGNS, sal.CDGNS, sal.CDGCL, sal.CICLO, SAL.INICICLO, SAL.FREQPAGOS, pfcorte ), 'YYYYMMDD') AS FULTPAGO,
SAL.FECHAULTIMACOMPRA, SAL.FECHACIERRECUENTA, SAL.FECHACORTE, SAL.GARANTIA, SAL.CREDITOMAXIMO,
SAL.SALDOCL, SAL.limitecredito, SAL.SDOVENCL, SAL.NUMPAGVEN, SAL.pagoactual, SAL.HISTORICOPAG, SAL.CLAVEPREVENCION, SAL.TOTPAGREP, SAL.CLAVEANTERIOROTORGANTE,
SAL.NOMBREANTERIOROTORGANTE, SAL.NUMEROCUENTAANTERIOR,
SAL.SUMSALDO, SAL.sumsdoven, SAL.numcred, SAL.numdirecc, SAL.numempleo, SAL.numctas, ENC.NOMBREOTORGANTE, NULL AS DOMDEVOL
FROM
CIRCRED.VW_ENCABEZADO ENC,
circred.VW_DATOSPERDOM VCL,
ICARO.VW_PROYINVE SC,
CIRCRED.EMPLEO EMP,
CIRCRED.VW_SALDOINCOB SAL
WHERE SAL.FUENTEBD = 'ESIACOM'
AND SAL.CDGCL = VCL.CDGCL
AND SAL.CDGCL = SC.CDGCL(+) AND SAL.CICLO = SC.CICLO(+) and SAL.INICICLO = SC.INICIO(+)
AND SAL.FCORTE = pfcorte
AND SAL.STATUSCC IN ('INCOB', 'CIERR', 'CEROS') ;
END ReportaCC;
Why cant display the results?
(The query works fine if i execute it directly in a TOAD SQL editor)
Thanks again....!!!
After you hit F9 the "Variables" dialog appears and you select Type=Cursor from the dropdown list then press OK:
The reason you are getting the "ORA-24338: statement handle not executed" error is because you are closing your cursor before it is accessed.
This is the process that is happening:
Execute procedure
OPEN statement returns a pointer to the result set in memory (but does not return any data)
CLOSE statement discards the results before they are accessed
Procedure call ends
The client caller (in this case TOAD) attempts to access the result stream, but the pointer is invalid, so nothing can be read and the error is thrown
Solution: Remove the close lcursor; statement.
As your procedure is doing only a select statement better use a function like
CREATE or REPLACE function ReportaCC(pfcorte IN DATE)
RETURN SYS_REFCURSOR
AS
lcursor SYS_REFCURSOR;
BEGIN
OPEN lcursor FOR
select c1, c3, c3 from table1 where hdate = pfcorte;
RETURN lcursor ;
END;
/
Do not close lcursor here, close from your calling statement because if you close lcursor then you wouldn't be able to see any results.
And execute as
select ReportaCC(<>) from dual
from toad, double click cursor in datagrid to see the results.