标签:垃圾回收 报错 lex mod exec 问题: 能力 ram 方法
-- 判断用户从键盘输入的数字并打印相应语句 -- 接收键盘输入 -- accept addr prompt ‘xxx‘ -- addr 是一个地址值,在该地址上保持了输入的值 accept num prompt ‘请输入一个数字‘; declare pnum number := # -- 注意:取出存在在这个地址值的值要使用‘&‘符号相当于c的指针 begin if pnum = 0 then dbms_output.put_line(‘you input 0‘); else if pnum = 1 then dbms_output.put_line(‘you input 1‘); else then dbms_output.put_line(‘you input other number‘); end if; end;
declare --部门 cursor cdept is select deptno from dept; pdeptno dept.deptno%type; --部门中员工的薪水 cursor cemp(dno number) is select sal from emp where deptno=dno; psal emp.sal%type; --每个段的人数 count1 number; count2 number; count3 number; --部门的工资总额 salTotal number := 0; begin --部门 open cdept; loop --取一个部门 fetch cdept into pdeptno; exit when cdept%notfound; --初始化 count1:=0; count2:=0; count3:=0; --得到部门的工资总额 select sum(sal) into salTotal from emp where deptno=pdeptno; --取部门的中员工薪水 open cemp(pdeptno); loop --取一个员工的薪水 fetch cemp into psal; exit when cemp%notfound; --判断 if psal < 3000 then count1:=count1+1; elsif psal >=3000 and psal<6000 then count2:=count2+1; else count3:=count3+1; end if; end loop; close cemp; --保存结果 insert into msg values(pdeptno,count1,count2,count3,nvl(saltotal,0)); end loop; close cdept; commit; dbms_output.put_line(‘完成‘); end;
package demo; import java.sql.*; public class JDBCUtils { private static String driver = "oracle.jdbc.OracleDriver"; private static String url = "jdbc:oracle:thin:@169.254.35.157:1521/orcl"; private static String user = "scott"; private static String password = "tiger"; static{ // 注册驱动 try { Class.forName(driver); } catch (ClassNotFoundException e) { throw new ExceptionInInitializerError(e); } } public static Connection getConnection() { try { return DriverManager.getConnection(url, user, password); } catch (SQLException e) { e.printStackTrace(); } return null; } public static void release(Connection conn, Statement st, ResultSet rs) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally{ rs = null; // 置空作为垃圾回收 } } if (st != null) { try { st.close(); } catch (SQLException e) { e.printStackTrace(); } finally{ st = null; } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } finally{ conn = null; } } } }
/* procedure queryEmpInformation(eno in number, pename out varchar2, psal out number, pjob out varchar2) */ @Test public void testProcedure() { String sql = "{call queryEmpInformation(?,?,?,?)}"; Connection conn = null; CallableStatement call = null; try { conn = JDBCUtils.getConnection(); call = conn.prepareCall(sql); // 对于in参数,需要对其赋值 call.setInt(1, 7839); // 对于out参数,需要对其声明 call.registerOutParameter(2, OracleTypes.VARCHAR); call.registerOutParameter(3, OracleTypes.NUMBER); call.registerOutParameter(4, OracleTypes.VARCHAR); // 执行调用存储过程 call.execute(); // 从CallableStatement对象中取出输出out参数 String name = call.getString(2); Double sal = call.getDouble(3); String job = call.getString(4); System.out.println("name:" + name + " sal:" + sal + " job:" + job); } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtils.release(conn, call, null); } }
/* function queryEmpIncome(eno in number) return number */ @Test public void testFunction() { String sql = "{?= call queryEmpIncome(?)}"; Connection conn = null; CallableStatement call = null; try { conn = JDBCUtils.getConnection(); call = conn.prepareCall(sql); // 存储函数的输出参数即返回值,是第一个问号,对其注册 call.registerOutParameter(1, OracleTypes.NUMBER); // 赋值输入参数 call.setInt(2, 7839); call.execute(); double annIncome = call.getDouble(1); System.out.println("annual income:" + annIncome); } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtils.release(conn, call, null); } }
输出如下
@Test public void testCursor() { String sql = "{call mypackage.queryemplist(?,?)}"; Connection conn = null; CallableStatement call = null; try { conn = JDBCUtils.getConnection(); call = conn.prepareCall(sql); call.setInt(1, 10); call.registerOutParameter(2, OracleTypes.CURSOR); call.execute(); // CallableStatement是一个通用的接口,获取时获得Oracle适用的实现类对象,可以将其强制转换成Oracle适用的接口 ResultSet cursor = ((OracleCallableStatement) call).getCursor(2); while (cursor.next()) { System.out.println("name:"+cursor.getString("ename")); System.out.println("hiredate:"+cursor.getDate("hiredate")); } } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtils.release(conn, call, cursor); // 此处关闭ResultSet时同时关闭了这个光标 } }
触发器
标签:垃圾回收 报错 lex mod exec 问题: 能力 ram 方法
原文地址:https://www.cnblogs.com/zella1996/p/9550666.html