Oracle query of all sequences JAVA + Oracle Functions

Source: Internet
Author: User

-- View All sequences of current users

Select SEQUENCE_OWNER, SEQUENCE_NAME from dba_sequences where sequence_owner = 'username ';

Note:

1. You must log on as an administrator;

2. sequence_owner must be in upper case, regardless of whether your user name is in upper case. Only uppercase letters can be recognized.

Take the query of a BOOK table as an example:

Create table BOOK
(
Booknumber char (3) not null,
BOOKNAME VARCHAR2 (50 ),
Bookprice number (18, 2)
)

To return a dataset, you need to use the reference cursor type in Oracle. However, the method used in Oracle is more complicated (I don't understand why Oracle is so complicated ), first, declare a referenced cursor type, which is achieved by creating a package:

Create or replace package PKG_TEST
AS
Type refcursor is ref cursor;
END PKG_TEST;

 
Then create our function stored procedure:
Create or replace function query_book (key varchar) return PKG_TEST.REFCURSOR is
Result PKG_TEST.REFCURSOR;
Begin
Open Result
Select * from book where key = book. booknumber;

Return (Result );
End query_book;

In this stored procedure, we passed in the query key value key and returned a DataSet object.
In this way, we have a stored procedure named query_book, which can return a result dataset. To call this stored procedure, you can call it through the CallableStatement interface. In this case, you need to write a statement similar '{? = Call query_book (?)} ', And the parameters and return values must be set using code. Here, some simple stored procedures can also be called through queries. The following is the call method I used:

Public class FuncTest {
Public static void main (String [] args) throws Exception {
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Connection connection = DriverManager. getConnection ("jdbc: oracle: thin: @ 127.0.0.1: 1521: LeeDB ",
"TEST", "test ");
Statement stmt = connection. createStatement ();
ResultSet dataset = stmt.exe cuteQuery ("SELECT query_book ('001') from dual ");
If (dataset. next ()){
ResultSet ret = (ResultSet) dataset. getObject (1 );

While (ret. next ()){
System. out. print (ret. getString (1 ));
System. out. print ("\ t ");
System. out. print (ret. getString (2 ));
System. out. print ("\ t ");
System. out. println (ret. getDouble (3 ));
}
}
}
}

Note that the data returned here is embedded with the dataset returned by function, which requires special processing.

Related Article

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.