Oracle stored procedure with a divided reference: input parameters (in) and output parameter (out)
E.g:
1 create or replace procedure out_test(v_user in emp.user_name%type, 2 v_salary out emp.salary%type, 3 v_deptno out emp.emp_deptno%type) as 4 begin 5 select salary, emp_deptno 6 into v_salary, v_deptno 7 from emp 8 where user_name = v_user; 9 exception 10 when NO_DATA_FOUND then 11 dbms_output.put_line('No data found'); 12 when TOO_MANY_ROWS then 13 dbms_output.put_line('Too many rows found'); 14 end out_test;
Call the stored procedure from the command line using bind variables
1 SQL> var v_user varchar2(20); 2 SQL> var v_salary number; 3 SQL> var v_deptno number; 4 SQL> exec :v_user := 'Lisi'; 5 6 PL/SQL procedure successfully completed 7 v_user 8 --------- 9 Lisi 10 11 SQL> exec out_test(:v_user, :v_salary, :v_deptno); 12 13 PL/SQL procedure successfully completed 14 v_user 15 --------- 16 Lisi 17 v_salary 18 --------- 19 v_deptno 20 ---------
Developer stored in plsql performed with the procedure, may be performed without direct reference with the type of the parameter to be input in the variable value, with out without the input type, the output will be below plsql
Call stored in the hibernate EJB () stored procedure execution process
EJB call a stored procedure
to call the stored procedure, we can methods execute SQL statements by createNativeQuery EntityManager objects () (Note: here that the SQL statement, not EJB3 QL), call stored procedures SQL format is as follows:
{Call stored procedure name (parameter 1, parameter 2, ...)}
stored procedure you can call at two in the EJB3
1. No return value stored procedure.
2. The ResultSet return value (the value returned in the form select) stored procedure, EJB3 return value can not call to the stored procedure parameter OUT
1. Call no return value stored procedure
// no return call a stored procedure parameter
Query Query = em.createNativeQuery ( "{Procedure Call ()}");
Query.executeUpdate ();
2. stored procedure call returns a single value
// stored procedure call returns a single value
Query Query = em.createNativeQuery ( "Call GetPersonName {()?}");
Query.setParameter (. 1, new new Integer (. 1));
String result = query.getSingleResult () toString () .;
3. The call returns all of the columns of the table stored procedure
calls the stored procedure allows EJB3 Persistence operating environment will be directly filled into a column value Entity instance (in this case filled into Person object), and the result is returned as examples
// Call Person returns all of the columns of the stored procedure
Query Query = em.createNativeQuery ( "Call GetPersonList {()}", Person.class);
List query.getResultList Result = ();
stored procedure GetPersonList:
the CREATE pROCEDURE `GetPersonList` ()
the NOT DETERMINISTIC
the SECURITY DEFINER the SQL
the COMMENT ''
the BEGIN
SELECT * from Person;
the END;
4. stored procedure call returns the column portion
Create a stored procedure:
the CREATE PROCEDURE `GetPersonPartProperties` ()
the NOT DETERMINISTICSQL the SECURITY DEFINER
the COMMENT ''
the BEGIN
the SELECT the personid, PERSONNAME from Person;
the END;
// call returns the column portion of the stored procedure
Query query = em .createNativeQuery ( "Call GetPersonPartProperties {()}");
List query.getResultList Result = ();