日期:2014-05-16 浏览次数:20626 次
import java.sql.*; class DbmsOutput { public DbmsOutput(Connection conn) throws SQLException { enable_stmt = conn.prepareCall("begin dbms_output.enable(:1); end;"); disable_stmt = conn.prepareCall("begin dbms_output.disable; end;"); show_stmt = conn .prepareCall("declare " + " l_line varchar2(4000); " //set the buffer size to max + " l_done number; " + " l_buffer long; " + "begin " + " loop " + " exit when length(l_buffer)+255 > :maxbytes OR l_done = 1; " + " dbms_output.get_line( l_line, l_done ); " + " l_buffer := l_buffer || l_line || chr(10); " + " end loop; " + " :done := l_done; " + " :buffer := l_buffer; " + "end;"); }
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class TestOracle { /** * @param args */ public static void main(String args[]) throws SQLException { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:orcl", "username", "password"); conn.setAutoCommit(false); Statement stmt = conn.createStatement(); DbmsOutput dbmsOutput = new DbmsOutput(conn); dbmsOutput.enable(1000000); stmt.execute("begin p1.test_output(400);p1.test_output(400);p1.test_output(400); end;"); stmt.close(); dbmsOutput.show(); dbmsOutput.close(); conn.close(); } }
CREATE OR REPLACE PACKAGE BODY P1 AS PROCEDURE test_output( times IN NUMBER ) AS str varchar2(4000); BEGIN for x in 1..times loop str := str || ' hello' || x; end loop; dbms_output.put_line('result:' || str); END test_output; END P1;