SQL queries in the database are fast, but queries for slower workarounds in the program

Source: Internet
Author: User

When writing Java, there is a way to query faster than other methods, but in the database query very quickly, originally because of the application of parameterized query when the parameter type error reason

1          Select *2             fromTransactionno,3 Fmis_accountrecord Accountrecord,4 UserInfo Inputuser,5 UserInfo CheckUser,6 transspecialoperation A,7 AccountInfo C8           whereInputuser.id (+)=Transactionno.ninputuserid9              andCheckuser.id (+)=Transactionno.ncheckuseridTen              andTransactionno.id (+)=accountrecord.ntransactionnoid One              andA.ntransactionnoid=transactionno.id A              andAccountrecord.ndirectionid= 2 -              andAccountrecord.nofficeid= 1 -              andAccountrecord.ncurrencyid= 1 the              andA.npayaccountid=C.id (+) -              andAccountrecord.dtexecutebetween ?  and? +              andNVL (Accountrecord.nstatusid,0)>= 0 A              andTransactionno.ntransactiontypeid= 559

After the modification the program quickly:

//                 ps.settimestamp (1, tsdatestart); //                 Ps.settimestamp (2, tsdateend);                 New java.sql.Date (Tsdatestart.gettime ()));                 Ps.setdate (new java.sql.Date (Tsdateend.gettime ()));

Refer to C #:

The code is as follows

String sql = "SELECT * from Lis_v_labtestsample WHERE patient_id=:P";
Hlsaccess.commandtext = SQL;
HlsAccess.Parameters.Clear ();
HLSACCESS.PARAMETERS.ADD (":P", Oracle.DataAccess.Client.OracleDbType.Varchar2). Value = Patid;

This specifies that the type of the parameter is VARCHAR2, but the database is indeed number, which causes the field type error to result in the table scan, resulting in a slow query.

SQL queries in the database are fast, but queries for slower workarounds in the program

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.