您的位置:首页 > 数据库 > SQL

Testing/Running the stored procedure(has OUT params) in Oracle sqldeveloper or sqlplus

2011-08-29 11:56 736 查看
sql>var v_result numbersql>exec sp_isauthorized('a', 'b', :v_result)PL/SQL procedure successfully completed.sql>print v_result -- or turn autoprint on===================================================To test the stored procedure, we can either execute it from within an environment that allows you to execute stored procedures and supply their parameters, such as SQL Navigator or Toad, or we can run it from within sqlplus.Executing a stored procedure from within sqlplus is straightforward once you know how.Firstly, start up sqlplus and declare a sqlplus variable of type refcursor. This declares a sqlplus variable of type refcursor (a sqlplus type), called "results":SQL> var results refcursorNext, execute the procedure, supplying a number as a parameter, and assigning the result into our variable, "results". Note the unusual syntax.SQL> exec :results := sp_get_stocks(20.0)PL/SQL procedure successfully completed.Finally, use the sqlplus print statement to print out the result setSQL> print resultsRIC PRICE UPDATED------ --------- ---------AMZN 15.5 21-OCT-01SUNW 16.25 21-OCT-01ORCL 14.5 21-OCT-01If this works successfully, similar to the above, the stored procedure (well, function) is working correctly.

Java client 调用:

if(cs==null)
cs=m_Conn.prepareCall("{call p(?,?)}");
cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cs.setString(2,column);
cs.execute();
rs=(ResultSet)cs.getObject(1);
while(rs.next()){
System.out.println(column+"="+rs.getString(1));
}
rs.close();
rs=null;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐