6 Questions about Oracle stored procedures

Source: Internet
Author: User
Moon Pale Wolf 2017-11-27 23:17:37

In Oracle, the data table alias cannot be added as, such as:

Select A.appname from appinfo a;--correct;

Select A.appname from appinfo as a;--error

May conflict with the keyword as in the stored procedure in Oracle

in a stored procedure, when a field is select, it must be followed by into, and if you select the entire record, it is a different matter to use the cursor.

Select Af.keynode into KN from appfoundation af where Af.appid =aid and af.foundationid=fid;--have into, compile correctly;

Select Af.keynode from Appfoundation af where Af.appid =aid and af.foundationid=fid;--no into, compile an error;

In the use of select ... into. Syntax, you must first ensure that the record in the database, or you will report "No data Found" exception.

You can use SELECT COUNT (*) from to see if the record exists in the database before this syntax, and if it exists, reuse select...into ...

4. In the stored procedure, the alias can not be the same as the field name, otherwise, although the compilation can pass, but in the runtime will be an error;

5. In the stored procedure, with regard to the problem of NULL, suppose that there is a table A, defined as follows:

CREATE TABLE A (

ID VARCHAR2 (m) primary key NOT NULL,

Vcount Number (8) is not NULL,

Bid varchar2 NOT null--foreign key

);

If in the stored procedure, use the following statement:

Select SUM (vcount) into Fcount from where bid= ' xxxxxxx ';

If the record for bid= "xxxxxx" does not exist in table A, then fcount=null (even if the Fcount definition has a default value set, such as: Fcount number (8): =0 is still invalid, fcount will still be null), This may be a problem when you use Fcount, so it's best to decide here:

If Fcount is null then

fcount:=0;

End If;

That's all OK.

6.Hibernate calling Oracle Stored Procedures

This.pnumberManager.getHibernateTemplete (). Execute (

New Hibernatecallback () {

Public Object Doinhinernate (sessions session)

Throws hibernateexception,sqlexception{

CallableStatement cs=session.connection (). Preparecall ("{Call Modifyapppnumber_remain (?)}");

Cs.setstring (1,foundationid);

Cs.execute ();

return null;

}

} );

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.