JDBC调用PL/SQL函数
来源:互联网 发布:淘宝直播怎么上传宝贝 编辑:程序博客网 时间:2024/05/14 09:48
函数的一般的格式:
举例应用:
在java代码里去调用函数:
CallableStatement cs;
try {
// 调用一个没有参数的函数; 函数返回 a int
// 预处理callable语句
cs = connection.prepareCall("{? = call get_age}");
// 注册返回值类型
cs.registerOutParameter(1, i);
// Execute and retrieve the returned value
cs.execute();
int retValue = cs.getInt(1);
// 调用有一个in参数的函数; the function returns a number
// 调用有一个in/out参数的函数; the function returns a VARCHAR
// Set the value for the IN/OUT parameter
1. CREATE OR REPLACE FUNCTUION funcion_name [参数表列]
2. RETURN DATATYPE
3. IS|AS
4. PL/SQL BLOCK
2. RETURN DATATYPE
3. IS|AS
4. PL/SQL BLOCK
举例应用:
1. CREATE OR REPLACE FUNCTION get_age(per_id in person_id)
2. return number
3. is
4. v_age person.id%type :=0;
5. begin
6. select age
7. into V_age
8. from person
9. where id=per_id;
10. return v_age;
11. end get_age;
12. /
2. return number
3. is
4. v_age person.id%type :=0;
5. begin
6. select age
7. into V_age
8. from person
9. where id=per_id;
10. return v_age;
11. end get_age;
12. /
CallableStatement cs;
try {
// 调用一个没有参数的函数; 函数返回 a int
// 预处理callable语句
1. cs = connection.prepareCall("{? = call get_age}");
2. // 注册返回值类型
3. cs.registerOutParameter(1, i);
4. // Execute and retrieve the returned value
5. cs.execute();
6. int retValue = cs.getInt(1);
2. // 注册返回值类型
3. cs.registerOutParameter(1, i);
4. // Execute and retrieve the returned value
5. cs.execute();
6. int retValue = cs.getInt(1);
// 注册返回值类型
cs.registerOutParameter(1, i);
// Execute and retrieve the returned value
cs.execute();
int retValue = cs.getInt(1);
// 调用有一个in参数的函数; the function returns a number
1. cs = connection.prepareCall("{? = call get_age(?)}");
2. // Register the type of the return value
3. cs.registerOutParameter(1, Types.number);
4. // Set the value for the IN parameter
5. cs.setInt(2, 95001);
6. // Execute and retrieve the returned value
7. cs.execute();
8. retValue = cs.getInt(1);
2. // Register the type of the return value
3. cs.registerOutParameter(1, Types.number);
4. // Set the value for the IN parameter
5. cs.setInt(2, 95001);
6. // Execute and retrieve the returned value
7. cs.execute();
8. retValue = cs.getInt(1);
// 调用有一个out参数的函数; the function returns a VARCHAR
cs = connection.prepareCall("{? = call get_age(?)}");
// Register the types of the return value and OUT parameter
cs.registerOutParameter(1, Types.VARCHAR);
cs.registerOutParameter(2, Types.VARCHAR);
// Execute and retrieve the returned values
cs.execute();
retValue = cs.getString(1); // return value
String outParam = cs.getString(2); // OUT parameter
cs = connection.prepareCall("{? = call get_age(?)}");
// Register the types of the return value and OUT parameter
cs.registerOutParameter(1, Types.VARCHAR);
cs.registerOutParameter(2, Types.VARCHAR);
// Execute and retrieve the returned values
cs.execute();
retValue = cs.getString(1); // return value
String outParam = cs.getString(2); // OUT parameter
// 调用有一个in/out参数的函数; the function returns a VARCHAR
1. cs = connection.prepareCall("{? = call get_age(?)}");
2. // Register the types of the return value and OUT parameter
3. cs.registerOutParameter(1, Types.NUMBER);
4. cs.registerOutParameter(2, Types.NUMBER);
2. // Register the types of the return value and OUT parameter
3. cs.registerOutParameter(1, Types.NUMBER);
4. cs.registerOutParameter(2, Types.NUMBER);
// Set the value for the IN/OUT parameter
1. cs.setInt(2, 95002);
2.
3. // Execute and retrieve the returned values
4. cs.execute();
5. retValue = cs.getInt(1); // return value
6. outParam = cs.getInt(2); // IN/OUT parameter
7. } catch (SQLException e) {
8. }
2.
3. // Execute and retrieve the returned values
4. cs.execute();
5. retValue = cs.getInt(1); // return value
6. outParam = cs.getInt(2); // IN/OUT parameter
7. } catch (SQLException e) {
8. }
转自:http://jdnis.javaeye.com/blog/219990
- JDBC调用PL/SQL函数
- JDBC调用PL/SQL函数
- JDBC调用存储函数(PL/SQL)
- jdbc调用pl/sql存储过程
- jdbc的pl/sql的java调用存储过程
- PL/SQL --> 动态SQL调用包中函数或过程
- Java,PL/SQL调用 ORACLE存储函数以及存储过程
- 用pl/sql自己编写简单的存储过程及jdbc调用存储过程
- pl/sql单行函数
- PL/SQL函数总结
- 内置pl/sql函数
- pl/sql函数索引
- PL/SQL简单函数
- PL/SQL常用函数
- PL/SQL常用函数
- PL/SQL 常用函数
- pl/sql常用函数
- PL/SQL 常用函数
- php环境配置(PHP+MySQL+Apache)
- ACE_Service_Config和ACE_Reactor调用关系
- 黑马程序员_java异常机制
- struts2学习笔记validate
- 那些年Google公开的大数据领域论文
- JDBC调用PL/SQL函数
- git 生成patch和使用patch
- android短彩信幻灯片异步加载机制
- CSS诊断样式表
- C++Primer第五版【学习笔记】——第三章 Strings,Vectors,Arrays
- [算法]打印出所有的“水仙花数”
- 省赛热身赛第三场——Second-price Auction
- latex双栏排版中的图表及公式通栏
- N-Tier Architecture and Tips