MyBatis call Oracle Stored procedure no_data_found exception handling analysis when select into is not logged

Source: Internet
Author: User

Tag: Transaction does not have plain key test statement to_date error RAC

First, according to this article: http://www.cnblogs.com/coolzdp/p/7717332.html

We know that in the SELECT * stored ProcedureINTO 如果没有记录是不会往下执行的,直接抛出NO_DATA_FOUND异常,

This in plsql Developer Direct Test Execution No problem , will be reported ORA-1403 exception.

But it is not thrown when called in MyBatis.NO_DATA_FOUND异常,而是在select * into语句为空时默默的终止执行该过程。

There is a problem with transaction processing at the service layer, and the service layer calls the SELECT * into empty stored procedure logic must be faulty, should throw an exception to the controller layer,

Now it just terminates, and the subsequent statement executes, so it's not right.

My guess is that the MyBatis is NO_DATA_FOUND异常 filtered, and the catch is no longer thrown .

My approach is that if there is a select INTO, the Plsql process is finally manually captured NO_DATA_FOUND异常 , throwing a custom exception :

EXCEPTION    when  Then   raise_application_error ('-20000'Select into did not find data ');

If it is the kind that needs to prompt the user to indicate why the select into must have a record, then honestly use the following statement:

SELECT COUNT(*) intoV_playvoyagecount fromPlan_voyageWHEREVessel_id_=P_vesselid andSailing_date_=To_date (P_saildate,'YYYY-MM-DD'); IFV_playvoyagecount= 0   ThenRaise_application_error (-20000,'No record'); END IF;

Refer to this article: https://www.cnblogs.com/zhangxsh/p/3494340.html

In fact, this article is not about calling stored procedures in MyBatis NO_DATA_FOUND异常 , but for

In select Fn_test (' 1 ') from dual; The call function in SQL returns NULL to terminate without NO_DATA_FOUND throwing an exception.

The difference is that this is the processing of Oracle itself, the above is the processing of mybatis.

MyBatis call Oracle Stored procedure no_data_found exception handling analysis when select into is not logged

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.