oracle testing function that contains cursor with sql developer - oracle

I wrote a function in oracle but I cannot test it. It gives type error but I can call it from java. I want to test it in sql developer tool.I checked all parameter types but they are correct.
My function is like this:
create or replace
FUNCTION GET_STUDENT_SCORE_FN(
p_no IN VARCHAR2,
p_date IN DATE,
p_periods IN NUMBER,
p_cycle OUT VARCHAR2,
p_return_code OUT INTEGER,
p_return_desc OUT VARCHAR2)
RETURN SYS_REFCURSOR
AS
cursor_response_score SYS_REFCURSOR;
def_refcur SYS_REFCURSOR;
BEGIN
IF p_no IS NULL
THEN
p_cycle := NULL;
p_return_code := -1;
p_return_desc := ' no can not be null!';
RETURN def_refcur;
END IF;
OPEN cursor_response_score FOR
SELECT * from students;
return cursor_response_score;
END
I want to test my function.I wrote some codes like this
DECLARE
P_NO VARCHAR2(200);
P_DATE DATE;
P_PERIODS NUMBER;
P_CYCLE VARCHAR2(200);
P_RETURN_CODE NUMBER;
P_RETURN_DESC VARCHAR2(200);
v_Return SYS_REFCURSOR;
BEGIN
P_NO := '5325551374';
P_DATE := to_date('1002019','ddmmyyyy');
P_PERIODS := null;
v_Return := GET_STUDENT_SCORE_FN(
P_NO => P_NO,
P_DATE => P_DATE,
P_PERIODS => P_PERIODS,
P_CYCLE => P_CYCLE,
P_RETURN_CODE => P_RETURN_CODE,
P_RETURN_DESC => P_RETURN_DESC
);
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('P_CYCLE = ' || P_CYCLE);
*/
:P_CYCLE := P_CYCLE;
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('P_RETURN_CODE = ' || P_RETURN_CODE);
*/
:P_RETURN_CODE := P_RETURN_CODE;
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('P_RETURN_DESC = ' || P_RETURN_DESC);
*/
:P_RETURN_DESC := P_RETURN_DESC;
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
*/
:v_Return := v_Return; --<-- Cursor
END;
But it gives error like this when i run above query on sql developer( click: run)
ORA-06550: line 25, column 20:
PLS-00382: expression is of wrong type
ORA-06550: line 25, column 4:
PL/SQL: Statement ignored
ORA-06550: line 37, column 16:
PLS-00382: expression is of wrong type
ORA-06550: line 37, column 3:
PL/SQL: Statement ignored
I run above query in on sql page it gives
Bind Variable "P_CYCLE" is NOT DECLARED
anonymous block completed

You can test it from a SQL worksheet using variable and print:
var P_NO VARCHAR2(200);
-- has to be a string, unfortunately; var doesn't support dates directly
var P_DATE VARCHAR2(10);
var P_PERIODS NUMBER;
var P_CYCLE VARCHAR2(200);
var P_RETURN_CODE NUMBER;
var P_RETURN_DESC VARCHAR2(200);
var V_RETURN REFCURSOR;
BEGIN
:P_NO := '5325551374';
:P_DATE := '2019-02-10';
:P_PERIODS := null;
:V_RETURN := GET_STUDENT_SCORE_FN(
P_NO => :P_NO,
P_DATE => to_date(:P_DATE, 'YYYY-MM-DD'),
P_PERIODS => :P_PERIODS,
P_CYCLE => :P_CYCLE,
P_RETURN_CODE => :P_RETURN_CODE,
P_RETURN_DESC => :P_RETURN_DESC
);
END;
/
print P_CYCLE;
print P_RETURN_CODE;
print P_RETURN_DESC;
print V_RETURN;
Notice that the var and print commands don't have colons; but within the PL/SQL block (or just within SQL) they are treated as bind variables, so they do have them there.
The IN parameters don't necessarily have to be bound, so you could simplify slightly to:
var P_CYCLE VARCHAR2(200);
var P_RETURN_CODE NUMBER;
var P_RETURN_DESC VARCHAR2(200);
var V_RETURN REFCURSOR;
BEGIN
:V_RETURN := GET_STUDENT_SCORE_FN(
P_NO => '5325551374',
P_DATE => date '2019-02-10',
P_PERIODS => null,
P_CYCLE => :P_CYCLE,
P_RETURN_CODE => :P_RETURN_CODE,
P_RETURN_DESC => :P_RETURN_DESC
);
END;
/
print P_CYCLE;
print P_RETURN_CODE;
print P_RETURN_DESC;
print V_RETURN;

Related

Dynamic select execution missing expression error

I am using Oracle 12, and I want to make a dynamic procedure which selects rows from specific table but according to an unknown conditio. That condition will be specified as input parameter.
Suppose I have a column called employee id and I want to call the procedure
with the following condition
execute s('employeeid = 2')
My code is
create or replace procedure s (condition varchar)
as
TYPE EmpCurTyp IS REF CURSOR; -- define weak REF CURSOR type
emp_cv EmpCurTyp; -- declare cursor variable
my_ename VARCHAR2(15);
my_sal NUMBER := 2;
mycondition varchar2(100):=condition;
BEGIN
OPEN emp_cv FOR -- open cursor variable
'SELECT employeeid, employeename FROM employees WHERE = :s' USING mycondition;
END;
but I am getting an error
missing expression
What am I doing wrong, and will the result of this procedure be selected rows from employees table that satisfy applied condition ?
The USING is meant to handle values, not pieces of code; if you need to edit your query depending on an input parameter ( and I believe this is a very dangerous way of coding), you should treat the condition as a string to concatenate to the query.
For example, say you have this table:
create table someTable(column1 number)
This procedure does somthing similar to what you need:
create or replace procedure testDyn( condition IN varchar2) is
cur sys_refcursor;
begin
open cur for 'select column1 from sometable where ' || condition;
/* your code */
end;
Hot it works:
SQL> exec testDyn('column1 is null');
PL/SQL procedure successfully completed.
SQL> exec testDyn('column99 is null');
BEGIN testDyn('column99 is null'); END;
*
ERROR at line 1:
ORA-00904: "COLUMN99": invalid identifier
ORA-06512: at "ALEK.TESTDYN", line 4
ORA-06512: at line 1
This is not embedded in a procedure yet but I tested this and works:
DECLARE
TYPE OUT_TYPE IS TABLE OF VARCHAR2 (20)
INDEX BY BINARY_INTEGER;
l_cursor INTEGER;
l_fetched_rows INTEGER;
l_sql_string VARCHAR2 (250);
l_where_clause VARCHAR2 (100);
l_employeeid VARCHAR2 (20);
l_employeename VARCHAR2 (20);
l_result INTEGER;
o_employeeid OUT_TYPE;
o_employeename OUT_TYPE;
BEGIN
l_cursor := DBMS_SQL.OPEN_CURSOR;
l_sql_string := 'SELECT employeeid, employeename FROM employees WHERE ';
l_where_clause := 'employeeid = 2';
l_sql_string := l_sql_string || l_where_clause;
DBMS_SQL.PARSE (l_cursor, l_sql_string, DBMS_SQL.V7);
DBMS_SQL.DEFINE_COLUMN (l_cursor,
1,
l_employeeid,
20);
DBMS_SQL.DEFINE_COLUMN (l_cursor,
2,
l_employeename,
20);
l_fetched_rows := 0;
l_result := DBMS_SQL.EXECUTE_AND_FETCH (l_cursor);
LOOP
EXIT WHEN l_result = 0;
DBMS_SQL.COLUMN_VALUE (l_cursor, 1, l_employeeid);
DBMS_SQL.COLUMN_VALUE (l_cursor, 2, l_employeename);
l_fetched_rows := l_fetched_rows + 1;
o_employeeid (l_fetched_rows) := l_employeeid;
o_employeename (l_fetched_rows) := l_employeename;
l_result := DBMS_SQL.FETCH_ROWS (l_cursor);
END LOOP;
DBMS_SQL.CLOSE_CURSOR (l_cursor);
DBMS_OUTPUT.PUT_LINE (o_employeeid (1));
DBMS_OUTPUT.PUT_LINE (o_employeename (1));
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('GENERAL FAILURE: ' || SQLERRM);
END;

Oracle Dynamic delete statements with DECODE Function

Hi I have the following procedure:
create or replace procedure
SP_DELETE_FROM_TABLE(pTableName in VARCHAR2, pFieldName in VARCHAR2,
pFieldValue in VARCHAR2,pFieldType in VARCHAR2) is
querystring VARCHAR2(500);
begin
queryString := 'DELETE FROM ' ||pTableName||
' WHERE '||pFieldName ||' = DECODE(:pFieldType,integer,:pFieldValue)' ;
EXECUTE IMMEDIATE queryString USING pFieldType,pFieldValue;
end SP_DELETE_FROM_TABLE;
all my Parameters are of Type VARCHAR2, What I am trying to do is: When I call the procedure with the following values ('users_table','users_id','11','integer')
so by using DECODE I would like to check if pFieldValue is of type pFieldTypeand if yes return pFieldValue
so if pFieldValue is:11 and pfieldType is:integer it should delete users_id 11 if fieldType is string do nothing..
I'd create a function that checks parameter has correct type
and then use it in main procedure
--main procedure
create or replace procedure SP_DELETE_FROM_TABLE(pTableName in VARCHAR2, pFieldName in VARCHAR2,pFieldValue in VARCHAR2,pFieldType in VARCHAR2) is
querystring VARCHAR2(500);
begin
if 'Y' = is_type_correct(pFieldValue, pFieldType ) then
queryString := 'DELETE FROM ' ||pTableName|| ' WHERE '
||pFieldName ||' = :pFieldValue';
EXECUTE IMMEDIATE queryString USING pFieldValue;
end
else
null; --incorrect type and parameter, do nothing
end;
end SP_DELETE_FROM_TABLE;
--check function
CREATE OR REPLACE FUNCTION is_type_correct( p_val IN VARCHAR2, p_type varchar2 )
RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE
IS
l_num NUMBER;
l_date date;
BEGIN
if 'integer' = p_type
then
l_num := to_number( p_val );
elsif 'date' = p_type then
l_date := to_date(p_val, 'YYYY.MM.DD');
elsif 'varchar2' then
null;//do nothing
else
return 'N'; //uknown type
end if;
RETURN 'Y';
EXCEPTION
WHEN value_error THEN
RETURN 'N';
END is_number;
Just try to convert a string to a number, and when an exception occurs, do nothing:
querystring VARCHAR2(500);
some_number number;
begin
some_number := to_number( pFieldValue ); /* trying to convert to a number */
queryString := 'DELETE FROM ' ||pTableName||
' WHERE '||pFieldName ||' = :x' ;
EXECUTE IMMEDIATE queryString USING some_number;
EXCEPTION
WHEN VALUE_ERROR THEN null; /* do nothing when pFieldValue is not a number*/
end SP_DELETE_FROM_TABLE;

Oracle procedure to create_person fails with PLS-00306 error

I have a package specification:
G_PKG_NAME CONSTANT VARCHAR2(30) := 'XX_CUST_PKG';
PROCEDURE customer_load
( errbuff OUT NOCOPY VARCHAR2
, retcode OUT NOCOPY VARCHAR2);
And body with procedure which calls to HZ_PARTY_V2PUB API. It uses cursor to take data from a table and then sends it to API :
PROCEDURE create_customer
( errbuff OUT NOCOPY VARCHAR2
, retcode OUT NOCOPY VARCHAR2)
IS
ERR_SOURCE CONSTANT VARCHAR2(100) := G_PKG_NAME ||'.create_customer';
CURSOR c_load
IS
SELECT rowid row_id
, person_first_name
, person_last_name
, title
, known_as
, person_identifier
, gender
FROM xx_customer_info
WHERE NVL(status_flag, 'X') <> 'S';
r_load c_load%ROWTYPE;
--p_init_msg_list VARCHAR2(1) := FND_API.G_TRUE;
v_gender VARCHAR2(30); --hz_parties.sex%TYPE;
v_title VARCHAR2(60); --hz_parties.title%TYPE;
--API record type
person_rec HZ_PARTY_V2PUB.PERSON_REC_TYPE;
-- API output variables
x_return_status VARCHAR2(1);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);
x_party_id NUMBER;
x_party_number VARCHAR2(30);
x_profile_id NUMBER;
EXC_VALDN_ERR EXCEPTION;
BEGIN
errbuff := ' ';
retcode := RTN_SUCCESS;
msg_log ('Inside '||ERR_SOURCE);
FOR r_load in c_load LOOP
BEGIN
x_msg_data := NULL;
x_return_status := fnd_api.G_RET_STS_SUCCESS;
fnd_msg_pub.initialize;
-- example validation:
IF r_load.person_first_name IS NULL THEN
x_msg_data := ' "First name" cannot be null';
RAISE EXC_VALDN_ERR;
END IF;
-- Same validation for person_last_name here
-- Record Type:
person_rec.person_first_name := r_load.person_first_name;
person_rec.person_last_name := r_load.person_last_name;
person_rec.person_title := v_title;
person_rec.known_as := null;
person_rec.gender := v_gender;
person_rec.created_by_module := 'TCA_V2_API';
HZ_PARTY_V2PUB.create_person ( p_init_msg_list => FND_API.G_TRUE
, p_person_rec => person_rec
, x_party_id => x_party_id
, x_party_number => x_party_number
, x_profile_id => x_profile_id
, x_return_status => x_return_status
, x_msg_count => x_msg_count
, x_msg_data => x_msg_data);
msg_log('==========================');
msg_log('first name / last_name : '||r_load.person_first_name||' | '||r_load.person_last_name);
msg_log('x_return_status: '||x_return_status);
msg_log('x_msg_count: '||x_msg_count);
msg_log('x_msg_data: '||x_msg_data);
IF NVL(x_return_status, FND_API.G_RET_STS_ERROR) <> FND_API.G_RET_STS_SUCCESS THEN
IF NVL(x_msg_count, 0) > 1 THEN
FOR i IN 1..x_msg_count LOOP
x_msg_data := x_msg_data||i||'. '||substr(fnd_msg_pub.get(p_encoded => fnd_api.g_false ), 1, 255)||' , ';
msg_log(x_msg_data);
END LOOP;
END IF;
END IF;
msg_log('==========================');
EXCEPTION
WHEN OTHERS THEN
x_msg_data := 'EXC: '||NVL(x_msg_data, SQLERRM);
x_return_status := FND_API.G_RET_STS_ERROR;
END;
UPDATE xx_customer_info
SET status_flag = x_return_status
, error_message = x_msg_data
WHERE rowid = r_load.row_id;
END LOOP;
COMMIT;
msg_log ('Exit '||ERR_SOURCE);
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
msg_log('ERROR : '||ERR_SOURCE||' : '||NVL(SQLERRM, x_msg_data));
errbuff := 'ERROR : '||ERR_SOURCE||' : '||NVL(SQLERRM, x_msg_data);
retcode := RTN_ERROR;
END create_customer;
It should return errors or success.
When I test and run this in anonymous block:
begin
XX_CUST_PKG.create_customer;
end;
I get error message PLS-00306: wrong number or types of arguments in call to 'CREATE_CUSTOMER'. I can't see clearly where this error is referring to. I only have 2 OUT parameters, it should only give errbuff (which is x_msg_data) and retcode which is RTN_SUCCESS, RTN_WARNING or RTN_ERROR (I have this declared as constants '0', '1', '2') to output.
This was rewritten from initial package to the above example code, so that it handles exceptions, and few things had to be modified, but now I'm confused when testing it.
What did I leave out?
Any help?
The error you get is a PL/SQL compilation error, as you can see the error code starts with PLS-XXXX.. So it is not returned from your procedure. You missed to send the variables to hold the values from your procedure (out arguments)
Declare
errbuf varchar2(4000);
retcode varchar2(10);
begin
XX_CUST_PKG.create_customer(errbuf,retcode);
--printing the values
DBMS_OUTPUT.PUT_LINE(retcode||' '||errbuf);
end;
/

Stored procedure. RefCursor declaration issue

I'm trying to write a stored procedure, where I use a refcursor, but when I try to run it, Oracle tells me that the refcursor is not declared
Package:
create or replace package types
as
type cursorType is ref cursor;
end;
/
Procedure:
CREATE OR REPLACE PROCEDURE p_lista_veic_aluguer (
ESCRITORIO IN INT,
CATEGORIA IN CHAR,
DATA_INI IN DATE,
DATA_FIM IN DATE,
RETVAL IN OUT types.cursorType
) is
BEGIN
open retval for
SELECT B.COD_Veiculo,B.Marca
FROM VEICULO B
LEFT JOIN ALUGUER A
ON A.COD_VEICULO = B.COD_VEICULO
AND (data_ini BETWEEN A.DATA_LEVANTAMENTO AND A.DATA_ENTREGA
OR data_fim BETWEEN A.DATA_LEVANTAMENTO AND A.DATA_ENTREGA)
WHERE A.COD_VEICULO IS NULL
AND B.DATA_MANUTENCAO IS NULL
AND B.CATEGORIA = categoria
ORDER BY f_menor_dist(B.ESCRITORIO_ATUAL,escritorio) ASC;
END p_lista_veic_aluguer;
/
Testing :
SET DEFINE OFF;;
DECLARE
ESCRITORIO NUMBER;
CATEGORIA CHAR(200);
DATA_INI DATE;
DATA_FIM DATE;
variable RETVAL TYPES.cursorType;
BEGIN
ESCRITORIO := 22;
CATEGORIA := 'A';
DATA_INI := '2012/11/23';
DATA_FIM := '2012/11/30';
P_LISTA_VEIC_ALUGUER( ESCRITORIO => ESCRITORIO,
CATEGORIA => CATEGORIA,
DATA_INI => DATA_INI,
DATA_FIM => DATA_FIM,
RETVAL => RETVAL );
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('RETVAL = ' || RETVAL);
*/
print retval;
END;
Error:
Error report: ORA-06550: linha 6, coluna 19: PLS-00103: Encountered
the symbol "TYPES" when expecting one of the following:
:= . ( # % ; not null range default character The symbol ":=" was
substituted for "TYPES" to continue. ORA-06550: linha 16, coluna 9:
PLS-00103: Encountered the symbol "RETVAL" when expecting one of the
following:
:= . ( # % ; The symbol ":=" was substituted for "RETVAL" to
continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
SET DEFINE OFF;
variable RETVAL refcursor;
DECLARE
ESCRITORIO NUMBER;
CATEGORIA CHAR(200);
DATA_INI DATE;
DATA_FIM DATE;
BEGIN
ESCRITORIO := 22;
CATEGORIA := 'A';
DATA_INI := '2012/11/23';
DATA_FIM := '2012/11/30';
P_LISTA_VEIC_ALUGUER( ESCRITORIO => ESCRITORIO,
CATEGORIA => CATEGORIA,
DATA_INI => DATA_INI,
DATA_FIM => DATA_FIM,
RETVAL => RETVAL );
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('RETVAL = ' || RETVAL);
*/
print retval;
END;
Try this it will work.

Error calling Oracle stored procedure from Hibernate Native query

Consider the following codes:
String checkSeatQuery = "BEGIN USP_RESERVESEAT(IRESULT=>?, ICART_SESSION=>?, IEVENT_ID=>?, ISESSION_ID=>?, IPRICE_SCHEME_ID=>?, ISEAT_ID=>?, IBLOCK_ID=>?, INO_OF_SEAT=>?, IPOS=>?, ISOURCE=>?, IFLASH_SEAT_STATUS_KEY=>?); END;";
Query q = entityManager.createNativeQuery(checkSeatQuery);
q.setParameter(1, DataTypes.STRING); //value passed in: 1
q.setParameter(2, cartSessionId); //value passed in: BT71C49DD999300D33E70B69F0A43F3436
q.setParameter(3, tblEvent.getId()); //value passed in: 20
q.setParameter(4,null); //value passed in: null
q.setParameter(5, Integer.toString(tempTicket.getTblPriceSchemes().getId())); //value passed in: 366
q.setParameter(6, seatId); //value passed in: null
q.setParameter(7, blockId); //value passed in: null
q.setParameter(8, accumulatedSeat); //value passed in: 1
q.setParameter(9, pos); //value passed in: 1
q.setParameter(10, source); //value passed in: 1
q.setParameter(11, null); //value passed in: null
String outputs = (String) q.getResultList().get(0);
Oracle procedure:
DECLARE
IRESULT VARCHAR2(200);
ICART_SESSION VARCHAR2(200);
IEVENT_ID NUMBER;
ISESSION_ID NUMBER;
IPRICE_SCHEME_ID VARCHAR2(200);
ISEAT_ID VARCHAR2(200);
IBLOCK_ID NUMBER;
INO_OF_SEAT NUMBER;
IPOS NUMBER;
ISOURCE NUMBER;
IFLASH_SEAT_STATUS_KEY VARCHAR2(200);
BEGIN
ICART_SESSION := NULL;
IEVENT_ID := NULL;
ISESSION_ID := NULL;
IPRICE_SCHEME_ID := NULL;
ISEAT_ID := NULL;
IBLOCK_ID := NULL;
INO_OF_SEAT := NULL;
IPOS := NULL;
ISOURCE := NULL;
IFLASH_SEAT_STATUS_KEY := NULL;
USP_RESERVESEAT(
IRESULT => IRESULT,
ICART_SESSION => ICART_SESSION,
IEVENT_ID => IEVENT_ID,
ISESSION_ID => ISESSION_ID,
IPRICE_SCHEME_ID => IPRICE_SCHEME_ID,
ISEAT_ID => ISEAT_ID,
IBLOCK_ID => IBLOCK_ID,
INO_OF_SEAT => INO_OF_SEAT,
IPOS => IPOS,
ISOURCE => ISOURCE,
IFLASH_SEAT_STATUS_KEY => IFLASH_SEAT_STATUS_KEY
);
DBMS_OUTPUT.PUT_LINE('IRESULT = ' || IRESULT);
END;
I got the error message:
2012-05-10 15:45:16,267 WARN [org.hibernate.util.JDBCExceptionReporter] (http-localhost%2F127.0.0.1-8080-5) SQL Error: 6550, SQLState: 65000
2012-05-10 15:45:16,267 ERROR [org.hibernate.util.JDBCExceptionReporter] (http-localhost%2F127.0.0.1-8080-5) ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'USP_RESERVESEAT'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'USP_RESERVESEAT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Why is that? After web searching I couldn't find much helpful information..
I am using the following:
Oracle, version: Oracle Database 11g Release 11.1.0.0.0 - Production
Hibernate 3.3.2.GA
PL/SQL:
create or replace
PROCEDURE USP_RESERVESEAT
(
IRESULT OUT VARCHAR2
, ICART_SESSION IN VARCHAR2
, IEVENT_ID IN NUMBER
, ISESSION_ID IN NUMBER
, IPRICE_SCHEME_ID IN VARCHAR2
, ISEAT_ID IN VARCHAR2
, IBLOCK_ID IN NUMBER
, INO_OF_SEAT IN NUMBER
, IPOS IN NUMBER
, ISOURCE IN NUMBER
, IFLASH_SEAT_STATUS_KEY IN VARCHAR2
)as
Iprice_scheme_id_inv VARCHAR2 (3000);
Iseat_id_inv NUMBER;
Icheck NUMBER;
IPos1 NUMBER;
IPos2 NUMBER;
Icapacity NUMBER;
Itic_sold NUMBER;
Irv_cart NUMBER;
Irefund_tic NUMBER;
Irecord NUMBER;
Irecordc NUMBER;
Inew_seat NUMBER;
Iavailable VARCHAR2 (3000);
Istatus_name VARCHAR2 (3000);
Ilatest_seat_status_key VARCHAR2 (3000);
Ilatest_seat_status_name VARCHAR2 (3000);
Ichild NUMBER;
Itotal_child NUMBER;
Icount_row NUMBER;
Ipromo_quantity NUMBER;
Iis_package NUMBER;
Itocart_seat_id NUMBER;
Ilatest_flash_seat_id VARCHAR2 (3000);
Ipromo_tic NUMBER;
Iallotment NUMBER;
Iready_to_cancel NUMBER;
Iready_to_cancel_booking_id NUMBER;
IKILL NUMBER;
BEGIN
if (ISOURCE = '0') THEN
Istatus_name := 'Internet Reserved';
else
if (ISOURCE = '1') THEN
Istatus_name := 'POS Reserved';
else
if (ISOURCE = '2') THEN
Istatus_name := 'CS Reserved';
else
if (ISOURCE = '3') THEN
Istatus_name := 'Call Centre Reserved';
else
if (ISOURCE = '4') THEN
Istatus_name := 'Promoter Reserved';
end IF;
end IF;
end IF;
end IF;
end IF;
begin
INSERT INTO tbl_cart_session
( cart_session,
event_id,
price_scheme_id,
no_of_seat,
created_date
)
VALUES
(
Icart_session,
Ievent_id,
Iprice_scheme_id,
INO_OF_SEAT,
sysdate
);
update tbl_cart_session set created_date=sysdate where cart_session=Icart_session;
select '1' into Iresult from dual;
end;
END USP_RESERVESEAT;
The IRESULT is an OUT parameter so you should register it like this:
String checkSeatQuery = "BEGIN USP_RESERVESEAT(IRESULT=>?, ICART_SESSION=>?, IEVENT_ID=>?, ISESSION_ID=>?, IPRICE_SCHEME_ID=>?, ISEAT_ID=>?, IBLOCK_ID=>?, INO_OF_SEAT=>?, IPOS=>?, ISOURCE=>?, IFLASH_SEAT_STATUS_KEY=>?); END;";
Query q = entityManager.createNativeQuery(checkSeatQuery);
q.registerOutParameter(1, DataTypes.STRING); //value passed in: 1
q.setParameter(2, cartSessionId); //value passed in: BT71C49DD999300D33E70B69F0A43F3436
q.setParameter(3, tblEvent.getId()); //value passed in: 20
q.setParameter(4,null); //value passed in: null
q.setParameter(5, Integer.toString(tempTicket.getTblPriceSchemes().getId())); //value passed in: 366
q.setParameter(6, seatId); //value passed in: null
q.setParameter(7, blockId); //value passed in: null
q.setParameter(8, accumulatedSeat); //value passed in: 1
q.setParameter(9, pos); //value passed in: 1
q.setParameter(10, source); //value passed in: 1
q.setParameter(11, null); //value passed in: null
String outputs = (String) q.getResultList().get(0);

Resources