日期:2014-05-16 浏览次数:20313 次
create or replace procedure batchUpdateStudent(p_age in number) as begin update STUDENT set AGE=AGE+1 where AGE>p_age; end;
//hibernater 不支持直接更新或删除的存储过程,可以绕过Hibernate, //而在Hibernate中直接使用JDBC tx = session.beginTransaction(); Connection con=session.connection(); String procedure = "{call batchUpdateStudent(?) }"; CallableStatement cstmt = con.prepareCall(procedure); cstmt.setInt(1,0); //把年龄参数设为0 cstmt.executeUpdate(); tx.commit();
Create or REPLACE FUNCTION selectAllEmployments RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR; BEGIN OPEN st_cursor FOR Select EMPLOYEE,EMPLOYER, STARTDATE, ENDDATE, REGIONCODE, EID, VALUE, CURRENCY FROM EMPLOYMENT; RETURN st_cursor; END;
<sql-query name="selectAllEmployees_SP" callable="true"> <return alias="emp" class="Employment"> <return-property name="employee" column="EMPLOYEE"/> <return-property name="employer" column="EMPLOYER"/> <return-property name="startDate" column="STARTDATE"/> <return-property name="endDate" column="ENDDATE"/> <return-property name="regionCode" column="REGIONCODE"/> <return-property name="id" column="EID"/> <return-property name="salary"> <return-column name="VALUE"/> <return-column name="CURRENCY"/> </return-property> </return> { ? = call selectAllEmployments() } </sql-query>
<hibernate-mapping package="com.unmi.vo"> <class name="Test" table="TEST"/> <sql-query callable="true" > <return alias="aa" > <return-property name="oborqt" column="OBORQT"/> <return-property column="MOORQT"/> <return-property name="roschn" column="ROSCHN"/> <return-property column="PLANDATE"/> <return> { ? = call selectAllUsers() } </sql-query> </hibernate-mapping>
Session session = HibernateUtil.currentSession(); Query query = session.getNamedQuery("selectAllUsers"); List list = query.list(); System.out.println(list);
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert> <sql-delete callable="true">{? = call deletePerson (?)}</sql-delete> <sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>