__oracle of the char matching problem in Oracle

Source: Internet
Author: User

Background:

String sql = "SELECT * from Atm_user where username=?" and password=? ";

A very common SQL statement where username and password are char (20) and char (32) in Oracle if the query in MySQL is not a problem, the key is that the query in Oracle is, Oracle is supplemented by a space by default when char is not full, typically 3XN length. It's depressing.

The internet has found some processing methods, for reference only:

1. Properties are treated with the trim function: Trim (t.user_id) =?
2. Char changed to VARCHAR2 type
If the char type has a specified number of digits, after filling in the data will automatically add a space after the low bit, VVARCHAR2 will not, so you query the char type, "a" and "a" can not match

So just change the above SQL to the following

String sql = "SELECT * from Atm_user where trim (username) =?" and trim (password) =? ";

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.