Java calls Oracle Functions

Source: Internet
Author: User

Java calls Oracle functions. A function is essentially a stored procedure that returns a result. This example shows how to call functions with in, out, and in/out parameters.

Similar methods.

CallableStatement cs;
Try {
// Call a function without parameters. The function returns a VARCHAR.
// Pre-processes callable statements
  
Cs = connection. prepareCall ("{? = Call myfunc }");
  
// Register the return value type
Cs. registerOutParameter (1, I );
  
// Execute and retrieve the returned value
Cs.exe cute ();
String retValue = cs. getString (1 );
  
// Call a function with an in parameter; the function returns a VARCHAR
Cs = connection. prepareCall ("{? = Call myfuncin (?)} ");
  
// Register the type of the return value
Cs. registerOutParameter (1, Types. VARCHAR );
  
// Set the value for the IN parameter
Cs. setString (2, "a string ");
  
// Execute and retrieve the returned value
Cs.exe cute ();
RetValue = cs. getString (1 );
  
// Call a function with an out parameter; the function returns a VARCHAR
Cs = connection. prepareCall ("{? = Call myfuncout (?)} ");
  
// 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.exe cute ();
RetValue = cs. getString (1); // return value
String outParam = cs. getString (2); // OUT parameter
  
// Call a function with an in/out parameter; the function returns a VARCHAR
Cs = connection. prepareCall ("{? = Call myfuncinout (?)} ");
  
// Register the types of the return value and OUT parameter
Cs. registerOutParameter (1, Types. VARCHAR );
Cs. registerOutParameter (2, Types. VARCHAR );
  
// Set the value for the IN/OUT parameter
Cs. setString (2, "a string ");
  
// Execute and retrieve the returned values
Cs.exe cute ();
RetValue = cs. getString (1); // return value
OutParam = cs. getString (2); // IN/OUT parameter
} Catch (SQLException e ){
}

Replace () for Oracle Functions ()

Oracle Functions

Differences in case and decode usage and Performance Comparison of Oracle Functions

Simple Oracle functions and stored procedures

The Oracle function obtains the time period in seconds or minutes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.