I have connected to an oracle database in python and calls a procedure. The procedure is being called successfully without any errors. But I'm not able to get the return data from procedure
python code
c = conn.cursor()
outVal = c.var(int)
data = c.callproc("TAC_CALC_MAX_EMI",[54,"5.42.247.83",10000,1000,1,1,2,'N',1000,1,1,1,1,1])
result =conn.commit()
print(data)
Procedure
CREATE OR REPLACE PROCEDURE TEXOL.TAC_CALC_MAX_EMI
(V_PROGRAM_ID IN NUMBER,
V_IP_ADDRESS IN VARCHAR2 ,
V_INCOME_SALARY IN NUMBER,
V_ADD_INCOME IN NUMBER ,
V_NATIONALITY IN NUMBER,
V_MARITAL_ST IN NUMBER,
V_FAMILY_SIZE IN NUMBER,
V_MORTGAGE IN CHAR,
O_MAX_EMI OUT NUMBER,
O_FOOD OUT NUMBER,
O_HEALTH OUT NUMBER,
O_TRANSPORTATION OUT NUMBER,
O_COMMUNICATION OUT NUMBER,
O_EDUCATION OUT NUMBER
)
IS
L_FOOD NUMBER ;
L_HEALTH NUMBER ;
L_TRANSPORTATION NUMBER ;
L_COMMUNICATION NUMBER ;
L_EDUCATION NUMBER ;
L_INCOME NUMBER;
L_INC_COND NUMBER ;
L_TCDC_PERCENT NUMBER;
L_INC_MAX NUMBER;
L_TOTAL_DBR NUMBER:=0;
BEGIN
L_TOTAL_DBR := 0 ;
L_INC_COND := 0;
L_TCDC_PERCENT := 0 ;
SELECT * INTO L_FOOD ,L_HEALTH ,L_TRANSPORTATION , L_COMMUNICATION , L_EDUCATION FROM
(SELECT TCP_ID ,TCD_VALUE FROM TAC_CALC_DBR
WHERE TCC_ID = V_NATIONALITY
AND TCMS_ID = V_MARITAL_ST
AND TCFS_ID = V_FAMILY_SIZE)
PIVOT
(
SUM(TCD_VALUE)
FOR TCP_ID IN (1, 2, 3,4,5)) ;
--==========================================================================
L_INCOME := V_INCOME_SALARY + (V_ADD_INCOME / 2) ;
SELECT DISTINCT TCDC_INCOME INTO L_INC_COND FROM TAC_CALC_DBR_CONDITIONS ;
IF L_INCOME >= L_INC_COND THEN
SELECT TCDC_PERCENT INTO L_TCDC_PERCENT FROM TAC_CALC_DBR_CONDITIONS WHERE TCDC_COND = '<=' ;
ELSIF L_INCOME < L_INC_COND AND V_MORTGAGE = 'Y' THEN
SELECT TCDC_PERCENT INTO L_TCDC_PERCENT FROM TAC_CALC_DBR_CONDITIONS WHERE TCDC_COND = '>' AND TCDC_COND2 = 'Y';
ELSE
SELECT TCDC_PERCENT INTO L_TCDC_PERCENT FROM TAC_CALC_DBR_CONDITIONS WHERE TCDC_COND = '>' AND TCDC_COND2 = 'N' ;
END IF;
SELECT SUM(TCD_VALUE) INTO L_TOTAL_DBR FROM TAC_CALC_DBR WHERE TCC_ID=V_NATIONALITY AND TCMS_ID=V_MARITAL_ST AND TCFS_ID = V_FAMILY_SIZE;
L_INC_MAX := ((L_INCOME - L_TOTAL_DBR)* (L_TCDC_PERCENT/100)) ;
O_MAX_EMI := L_INC_MAX;
O_FOOD := L_FOOD ;
O_HEALTH := L_HEALTH ;
O_TRANSPORTATION := L_TRANSPORTATION;
O_COMMUNICATION := L_COMMUNICATION;
O_EDUCATION := L_EDUCATION;
END ;
/
I'm not familiar with procedures or SQL in general. Please suggest a way to get the return data from the procedure
Review the first example in the cx_Oracle documentation:
outVal = cursor.var(int)
cursor.callproc('myproc', [123, outVal])
print(outVal.getvalue())