Getting error in Procedure Call from Java Code - java

A) Getting This Error :
" PLS-00306: wrong number or types of arguments in call to 'PRC_ST_PSB_BNK_REF_GEN'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored "
1) JAva Code
SqlParameterSource inParameters =
new MapSqlParameterSource().addValue("IN_BATCHRUNID", Long.valueOf(this.batchRunId));
this.jdbcCall =
new SimpleJdbcCall(this.jdbcTemplate).withProcedureName("PRC_ST_PSB_BNK_REF_GEN").declareParameters(new SqlParameter[]
{ new SqlOutParameter("OUT_REFCURSOR", -10, new BeanPropertyRowMapper(NetBankReconDTO.class)) });
this.recuMap = this.jdbcCall.execute(inParameters);
2) Procedure
CREATE or REPLACE PROCEDURE "PRC_ST_CSB_REF_GEN"
(
IN_BATCHRUNID NUMBER,
OUT_REFCURSOR OUT SYS_REFCURSOR,
OUT_TOTREC OUT NUMBER,
OUT_SUCCREC OUT NUMBER,
OUT_FAILEREC OUT NUMBER,
OUT_STATUSCODE OUT NUMBER,
OUT_STATUSDESC OUT VARCHAR2,
OUT_TOTALAMT OUT NUMBER,
OUT_TOTALREC OUT NUMBER
)
AS
LV_NETBANKID NUMBER;
LV_CNT NUMBER;
LV_AMT NUMBER(18,2);
LV_NTRP_STATUS NUMBER;
BEGIN
SELECT NETBANKID INTO LV_NETBANKID FROM VTSTBATCHPRCSTRN WHERE BATCHRUNID=IN_BATCHRUNID;
UPDATE VTSTREFVOIDREQ RREQ SET REFVOIDBATCHRUNID=IN_BATCHRUNID,CURRSTATUSCODE='A'
WHERE REFVOIDFLAG='V' AND CURRSTATUSCODE='I' AND
EXISTS ( SELECT 1 FROM VTSTAUTHZTRN AUTH WHERE AUTH.TRNREFNO = RREQ.TRNREFNO AND
AUTH.NETBANKID=LV_NETBANKID );
UPDATE VTSTSETTLEREQ SET NBREFBATCHRUNID=IN_BATCHRUNID, CURRSTATUSCODE=6040,CURRSTATUSDESC='Sent to NetBank for Refund'
WHERE NETBANKID=LV_NETBANKID AND CURRSTATUSCODE=6020 AND SETTLETYPE='R';
/* Update NTRP's transaction table */
LV_NTRP_STATUS := FN_NTRP_REFUND_UPDATE(IN_BATCHRUNID);
/* Tot Count And Tot Amount */
SELECT COUNT(1) , NVL(SUM(RREQ.REQAMT),0) INTO LV_CNT, LV_AMT
FROM VTSTREFVOIDREQ RREQ
INNER JOIN VTSTAUTHZTRN AUTH ON AUTH.TRNREFNO = RREQ.TRNREFNO
INNER JOIN CGCMN.VTMESTR STR ON STR.STOREID = AUTH.STOREID
WHERE REFVOIDBATCHRUNID=IN_BATCHRUNID ;
SELECT COUNT(1)+LV_CNT, NVL(SUM(SREQ.SETTLEAMT),0)+LV_AMT INTO LV_CNT, LV_AMT
FROM VTSTSETTLEREQ SREQ
INNER JOIN VTSTAUTHZTRN AUTH ON AUTH.TRNREFNO = SREQ.TRNREFNO
INNER JOIN CGCMN.VTMESTR STR ON STR.STOREID = AUTH.STOREID
WHERE SREQ.NBREFBATCHRUNID=IN_BATCHRUNID AND SREQ.NETBANKID=LV_NETBANKID AND SREQ.CURRSTATUSCODE=6040;
OPEN OUT_REFCURSOR for
SELECT
AUTH.TRNREFNO AS OTHPARAMETER,
'CSB' AS BANKNAME,
'WORLDLINE' AS MEBUSSNAME,
TO_CHAR(AUTH.HOSTTRNDATE,'DD/MM/YYYY HH:MI:SS') AS TRNDATE,
TO_CHAR(RREQ.REFUNDREQDATE,'DD/MM/YYYY HH:MI:SS') AS REFDATE,
NET.NETBANKMEID AS PAYEEID,
AUTH.RRN AS BANKREFNO,
AUTH.TRNREFNO AS TRNREFNO,
AUTH.TOTTRNAMT AS TRNAMT,
RREQ.REQAMT AS REFAMT
FROM VTSTREFVOIDREQ RREQ
INNER JOIN VTSTAUTHZTRN AUTH ON AUTH.TRNREFNO = RREQ.TRNREFNO
INNER JOIN VTSMNETBNK NET ON AUTH.NETBANKID=NET.NETBANKID
INNER JOIN CGCMN.VTMESTR STR ON STR.STOREID = AUTH.STOREID WHERE REFVOIDBATCHRUNID=IN_BATCHRUNID
UNION ALL
SELECT
AUTH.TRNREFNO AS OTHPARAMETER,
'CSB' AS BANKNAME,
'WORLDLINE' AS MEBUSSNAME,
TO_CHAR(AUTH.HOSTTRNDATE,'DD/MM/YYYY HH:MI:SS') AS TRNDATE,
TO_CHAR(SREQ.SETTLEREQDATE,'DD/MM/YYYY HH:MI:SS') AS REFDATE,
NET.NETBANKMEID AS PAYEEID,
AUTH.RRN AS BANKREFNO,
AUTH.TRNREFNO AS TRNREFNO,
AUTH.TOTTRNAMT AS TRNAMT,
SREQ.SETTLEAMT AS REFAMT
FROM VTSTSETTLEREQ SREQ
INNER JOIN VTSTAUTHZTRN AUTH ON AUTH.TRNREFNO = SREQ.TRNREFNO
INNER JOIN VTSMNETBNK NET ON AUTH.NETBANKID=NET.NETBANKID
INNER JOIN CGCMN.VTMESTR STR ON STR.STOREID = AUTH.STOREID
WHERE SREQ.NBREFBATCHRUNID=IN_BATCHRUNID AND SREQ.NETBANKID=LV_NETBANKID AND SREQ.CURRSTATUSCODE=6040;
/* Refund Response Ledger Posting */
SELECT COUNT(1) INTO LV_CNT FROM VTSTSETTLEREQ SREQ
INNER JOIN VTSMLVVEHICLE LV ON LV.LVID=SREQ.LVID AND LV.LVTYPE='A'
WHERE NBREFBATCHRUNID=IN_BATCHRUNID AND SETTLETYPE='R' ;
IF LV_CNT > 0 THEN
BEGIN
PRC_LED_NB_REF_FILERESP( IN_BATCHRUNID, 'SYSTEM','SYSTEM',OUT_STATUSCODE,OUT_STATUSDESC);
END;
END IF;
OUT_SUCCREC:=LV_CNT;
OUT_FAILEREC:=0;
OUT_STATUSCODE:=0;
OUT_STATUSDESC:='SUCCESS';
OUT_TOTALAMT:=LV_AMT;
OUT_TOTALREC:=LV_CNT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
ROLLBACK;
OUT_STATUSCODE := 1;
OUT_STATUSDESC := 'No Data Found';
END;
WHEN OTHERS THEN
BEGIN
ROLLBACK;
OUT_STATUSCODE := 1;
OUT_STATUSDESC := SQLERRM;
END;
END PRC_ST_CSB_REF_GEN;
PLS-00306: wrong number or types of arguments in call to 'PRC_ST_PSB_BNK_REF_GEN'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

Related

get a custom query result containing Clob in Java Spring App

I need to get a very long string from Oracle DB in Spring App, but using a function returning clob leads to internal server error 500. How to get a custom query result containing Clob?
PL/SQL function returning a very long string in clob:
create or replace function getVeryLongString(id_ in number)
return clob as
CURSOR cur IS select x.TARGET || ' pX=' || x.px as tpx -- to get concat string in order of PX desc
from (
select distinct a.ID,
a.TARGET,
MAX(a.PX) OVER (PARTITION BY a.TARGET, a.ID) as px
from BA_ACTIVITYDATA A
where A.TARGET is not null
and a.ID = id_
order by px desc
) x;
l_data clob := '';
begin
FOR fld IN cur
LOOP
l_data := l_data || fld.tpx || ' | ';
end loop;
return rtrim( l_data, ' | ');
end
;
I use this function in Query in Java Spring app:
public interface TargetRepository extends JpaRepository<List, Long> {
#Query(
value = "select t1.fieldA,\n" +
" t1.fieldB,\n" +
" t2.fieldC,\n" +
" getVeryLongString(t3.value1) as fieldD\n" +
"from tableA t1\n" +
"join tableB t2 on t1.id = t2.id\n" +
"join tableC t3 on t3.id = t2.id\n" +
"where t.id = :id",
nativeQuery = true
)
DataTypePX getDataById(Long id);
}
TargetActivity interface looks like:
public interface DataTypePX {
String getFIELDA();
String getFIELDB();
String getFIELDC();
String getFIELDD();
}
Using the above code leads to 500 ERROR.
to fix it I need to change function getVeryLongString as returning varchar2 - it works, but it leads to cutting of result string only to 4000 symbols:
create or replace function getVeryLongString(id_ in number)
return varchar2 as
CURSOR cur IS select x.TARGET || ' pX=' || x.px as tpx -- to get concat string in order of PX desc
from (
select distinct a.ID,
a.TARGET,
MAX(a.PX) OVER (PARTITION BY a.TARGET, a.ID) as px
from BA_ACTIVITYDATA A
where A.TARGET is not null
and a.ID = id_
order by px desc
) x;
-- l_data varchar2(32767) := '';
l_data clob := '';
begin
FOR fld IN cur
LOOP
l_data := l_data || fld.tpx || ' | ';
end loop;
return rtrim( substr(l_data, 1, 4000), ' | ');
end;

Intersection in DB2 using INTERSECT

I have a query in DB2 that I need intersection on.
SELECT * FROM records where id = 1
intersect
SELECT * FROM records where id = 2
Now this size of ids can grow dynamically, do we have anything in DB2 that can take the list of ids as the parameter? something like
intersect in (1,2,3,4,5) so that it may consider intersection on of result set on these ids using a single query?
You can create a TABLE with the ID LIST, and then create a procedure to create dinamically the SQL Statement to Execute.
Something like this:
CREATE PROCEDURE
YOUR_PROCEDURE
(
)
LANGUAGE SQL
SPECIFIC YOUR_PROCEDURE
NOT DETERMINISTIC
MODIFIES SQL DATA
CALLED ON NULL INPUT
INHERIT SPECIAL REGISTERS
SET OPTION
ALWBLK = *ALLREAD ,
ALWCPYDTA = *YES ,
COMMIT = *NONE ,
CLOSQLCSR = *ENDMOD ,
DECRESULT = (31, 31, 00) ,
DFTRDBCOL = *NONE ,
DLYPRP = *NO ,
DYNDFTCOL = *NO ,
DYNUSRPRF = *USER ,
SRTSEQ = *HEX ,
OUTPUT = *PRINT,
DBGVIEW = *SOURCE
BEGIN
DECLARE LAST_ELEMENT SMALLINT DEFAULT 0 ;
DECLARE FIRST_ELEMENT SMALLINT DEFAULT 1 ;
DECLARE STMT VARCHAR ( 5000 ) ;
DECLARE ID_CODE_TO_USE NUMERIC (9 , 0) ;
DECLARE ID_LIST CURSOR FOR
SELECT
ID_CODE
FROM
YOUR_TEMPORARY_TABLE ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET LAST_ELEMENT = -1 ;
OPEN ID_LIST ;
SET STMT = '' ;
SET FIRST_ELEMENT = 1 ;
FETCH_ID_LIST:
LOOP
FETCH ID_LIST
INTO
ID_CODE_TO_USE ;
-------
IF LAST_ELEMENT = -1 THEN
LEAVE FETCH_ID_LIST ;
END IF ;
-------
IF FIRST_ELEMENT= 1 THEN
SET STMT = 'SELECT * FROM RECORD WHERE ID = ' CONCAT CHAR(ID_CODE_TO_USE)
SET FIRST_ELEMENT = 0 ;
END IF ;
-------
SET STMT = 'INTERSECT SELECT * FROM RECORD WHERE ID = ' CONCAT CHAR(ID_CODE_TO_USE)
END LOOP FETCH_ID_LIST;
CLOSE ID_LIST ;
IF STMT <> '' THEN
EXECUTE IMMEDIATE STMT ;
END IF ;
END ;
Run this as is:
with ids (id) as
(
select id
from xmltable
(
'for $id in tokenize($s, ",") return <i>{string($id)}</i>'
-- the following string of IDs may be passed as a parameter
passing '1,2,3' as "s"
columns id int path 'if (. castable as xs:integer) then xs:integer(.) else ()'
)
)
, tab (id, c1, c2) as
(
values
(1, 1, 1)
, (1, 1, 1)
, (2, 1, 1)
, (2, 1, 1)
, (3, 1, 1)
, (1, 2, 2)
, (2, 2, 2)
)
select t.c1, t.c2
from tab t
join ids i on i.id=t.id
group by t.c1, t.c2
having count(distinct t.id) = (select count(1) from ids);
C1 C2
-- --
1 1
If this is not you want to have, then provide some example with source data and the exact result desired.

Get Exception while executing a oracle procedure in java

I am trying to execute a procedure in oracle, but i get a exception while executing the procedure.Please help me where i am wrong.
Error :
java.sql.SQLException: ORA-06550: line 1, column 36:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( ) , * # % & = - + < / > at in is mod remainder not rem =>
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || indicator multiset member submultiset
The symbol ")" was substituted for ";" to continue.
Procedure :
CREATE OR REPLACE PROCEDURE "TEST_101"."AVG_UNLOADING"
(
P_CODE IN VARCHAR2,
P_DATE IN VARCHAR2,
P_VANID IN NUMBER,
P_CURSOR OUT SYS_REFCURSOR
)
IS
BEGIN
OPEN P_CURSOR
FOR
select CARGO_NAME,IMP_EXP_NAME,'TEMP_CARGO_Import',ROUND(SUM(QTY)/((((extract(day from max(END_TIME)-DISCHRG_CMNCD_ANCHRG_TM)*(24*60))+
(extract(day from max(END_TIME)- DISCHRG_CMNCD_ANCHRG_TM)*(60)) + (EXTRACT(DAY FROM max(END_TIME)- DISCHRG_CMNCD_ANCHRG_TM)))-DELAYS)/(24*60))) QTY
from(SELECT (SELECT C.CARGO_CATEGORY_NAME FROM IPT_CARGOMASTER C WHERE C.CARGO_CODE =LL.CARGO_CODE )CARGO_NAME,IL.IMP_EXP_NAME,CASE L.CARGO_TYPE_CODE WHEN 'VC001' THEN LL.DISCHARGE_QUANTITY WHEN 'VC002' THEN LL.QUANTITY_GMT WHEN 'VC004' THEN LL.QUANTITY_GMT
else LL.DISCHARGE_QUANTITY end QTY ,L.DISCHRG_CMNCD_ANCHRG_TM,LL.END_TIME ,(SELECT SUM(T3.TOTAL_TIME) FROM IPT_LOADUNLOADDELAYLINES T3 WHERE T3.ID = L.ID AND T3.MINUS_DELAY_HOURS = 'true') AS DELAYS
,LL.LINE_ID,L.VAN_ID FROM IPT_LOADINGUNLOADING L JOIN IPT_LOADUNLOADOPERATIONLINES LL ON L.ID=LL.ID LEFT JOIN IPT_IMPORTEXPORTFORM I ON I.VAN_ID=L.VAN_ID JOIN IPT_IGMEPCARGOLINES IL ON I.ID=IL.ID AND LL.CARGO_CODE=IL.CARGO_CODE
where L.PORTDETAIL_CODE= P_CODE and I.PORTDETAIL_CODE=L.PORTDETAIL_CODE and IL.IMP_EXP_NAME like '%KKR%' AND LL.END_TIME<=TO_TIMESTAMP(TO_CHAR(P_DATE || ' 06:59'),'dd/MM/yyyy HH:MI')
and L.VAN_ID in (P_VANID )
)t group by CARGO_NAME, IMP_EXP_NAME, 'TEMP_CARGO_Import',DISCHRG_CMNCD_ANCHRG_TM,DELAYS;
END AVG_UNLOADING;
Executing procedure
stkagentlist = "{call AVG_UNLOADING(?,?,?,?}";
callableStatement = conn.prepareCall(stkagentlist);
callableStatement.setString(1, portCode);
callableStatement.setString(2, dt );
callableStatement.setString(3, vanids );
callableStatement.registerOutParameter(4, OracleTypes.CURSOR);
callableStatement.executeUpdate();
stkagentlist = "{call AVG_UNLOADING(?,?,?,?}";
I think in this statement the closing round bracket is missing, it should be:
stkagentlist = "{call AVG_UNLOADING(?,?,?,?)}";

SQL statement that uses a #variable fails when executed in java

I have the following statement which requires an SQL variable:
SELECT #i := 53; UPDATE my_table SET index = (SELECT #i := #i + 1), status = 0 WHERE id = '12345' ORDER BY seqindex ASC;
For some reason it works fine when I execute it on MySQL's workbench but it fails whenever I execute it within Java. I get org.springframework.jdbc.BadSqlGrammarException.
Any help will be appreciated.
Use Single quotes for table name or column name they have underscore like this 'my_table'
SELECT #i := 53; UPDATE 'my_table' SET index = (SELECT #i := #i + 1),
status = 0 WHERE id = '12345' ORDER BY seqindex ASC;

not all named parameters have been set hibernate in createSQLQuery

I am getting the error of not all named parameters have been set. Below is my code.
my SqlQuery which is running fine at mysql prompt, You can refer schema in the question SQL Query
SELECT t.*
FROM (
SELECT #lim := 2,
#cg := ''
) vars,
(select * from Table1 order by product,amount, make) t
WHERE CASE WHEN #cg <> product THEN #r := #lim ELSE 1 END > 0
AND (#r := #r - 1) >= 0
AND (#cg := product) IS NOT NULL
ORDER BY
product,amount, make
my java code
try {
context.dbl.startTransaction();
Session session = context.dbl.getSession();
//String sqlQuery = "from com.infibeam.inventoryservice.dbObjects.PopularBrandDO";
String sqlQuery = "SELECT t.* ";
sqlQuery=sqlQuery + "FROM (";
sqlQuery=sqlQuery + "SELECT #lim := 2,";
sqlQuery=sqlQuery + "#cg := ''";
sqlQuery=sqlQuery + ") vars, ";
sqlQuery=sqlQuery + "(select * from Table1 order by product,amount, make) t";
sqlQuery=sqlQuery + " WHERE CASE WHEN #cg <> product THEN #r := #lim ELSE 1 END > 0";
sqlQuery=sqlQuery + " AND (#r := #r - 1) >= 0 ";
sqlQuery=sqlQuery + " AND (#cg := product) IS NOT NULL ";
sqlQuery=sqlQuery + " ORDER BY product,amount, make";
//Query query = session.createQuery(sqlQuery);
SQLQuery query = session.createSQLQuery(sqlQuery);
listItems = query.list();
}catch(RuntimeException e) {
e.printStackTrace();
}
Below is the exception i am getting
org.hibernate.QueryException: Not all named parameters have been set: [] [SELECT t.* FROM (SELECT #lim := 2,#cg := '') vars, (select * from Table1 order by product,amount, make) t WHERE CASE WHEN #cg <> product THEN #r := #lim ELSE 1 END > 0 AND (#r := #r - 1) >= 0 AND (#cg := product) IS NOT NULL ORDER BY product,amount, make]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:291)
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:199)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:143)
at com.infibeam.weaverbird.helper.PopularBrandFacetHelper.bootstrap(PopularBrandFacetHelper.java:48)
Thanks in advance...
The problem is the assignments with :=, which are by the way no standard SQL.
In SQL after a : always a parameter is expected, like in where value = :param and :param has the be set as a parameter then. Now hibernate is scanning the select and find colons where no set parameters follow.
Solution: Redesign your selection using hibernate standards.
You can use two different HQL queries.
First: Select all product: select distinct product from Table1
Second: For each product you do from Table1 where product = :prod, :prod you set as a parameter with the actual product, and with setMaxResults(2) you can limit the number of rows as you need.
Now it is many selects and not a single one, but nevertheless they might be faster than the single query (the single query is complicated and risks an inefficient search strategy in the database). And a big advantage, now it is purely HQL and so your program is portable to different databases.

Categories