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;
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;
相关文章推荐
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- Creating a Stored Procedure or Function in an Oracle Database
- Running Oracle's SQL Plus in Linux Ubuntu
- This function has none of Deterministic,no sql,or reads sql data in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable
- use regular expression in the oracle sqlplus
- oracle.jbo.RowInconsistentException: JBO-25014: Another user has changed the row with primary key or
- 首次使用Oracle SQL Developer 提示: enter the full pathname for java.exe
- How to use Oracle 11g ODP.NET UDT in an Oracle Stored Procedure's Where clause
- Not running in a hosted service or the Development Fabric
- 安装ORACLE 10g时出现An unexpected exception has been detected in native code outside the VM异常的解决方案
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决
- Install Oracle SQL Developer in Ubuntu
- oracle sqlplus输入scott/tiger报错:the account is locked的解决办法
- Testing the sql statement in Access 2007
- If running in the context of a test using the mocking API or bootstrap Grails correctly
- SharePoint Designer Check In and Check Out Error – Cannot perform this operation.The file is no longer check out or has been del
- oracle:完整剖析PL/SQL DEVELOPER与SQL PLUS字符集设置
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- SQL Server Error Messages - Msg 1776 : There are no primary or candidate keys in the referenced Table
- Maven-010-maven 编译报错:Failure to ... in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced.