在涉及数据库操作的工作中,我们常会遇到对2个字符串进行等值比较而非模糊查询:例如比较2个姓名是否相等?但操作人员在将字符串
在涉及数据库操作的工作中,我们常会遇到对2个字符串进行等值比较而非模糊查询:例如比较2个姓名是否相等?但操作人员在将字符串录入系统的时候,可能会录入空格,或者是TAB健(我把这样的看起来像空格,可能实际上并不是空格的字符称为类空格字符),这样在比较的时候肯定是不等的。怎么办?
1.首先是去除空格在进行比较(比如,把姓名中的所有空格去除):
Update table_name set xm=replace(xm , ' ') ;
如果要查找哪些记录含有' ',可用相关的语句查找。
然后可进行比较。
2.但是我们可能会发现,有些姓名中间或末尾还有类似空格的字符没被去掉,但它们显然已经不是一般的空格了,那么怀疑是Tab健作怪。于是参照网上说的去掉TAB键的办法来处理,用chr(9)来替代空格键(TAB键的ASCII值为9)。先取一条带有类空格字符的记录来做实验:
SELECT replace(xm, chr(9) ) from table_name where bh=’xxx’;
用这个办法会去掉一些真正的Tab键空格,然后采取批量更新的办法。
3.但我遇到的情况没有这么幸运,没能去掉类空格键。怎么办呢?我决定尝试先取得这个类空格键的ASCII码值,,然后再用chr(ASCII码值)的方法来处理。
①.取得含类空格键整个字符串的长度 length(),从而确定出类空格键在字符串中的起始位置、类空格键的长度。
②.求出类空格键的ASCII码值:ascii(substr(xm,n,m)); n为类空格键的起始位置;m为长度。
③.SELECT replace(xm, chr(第②步求得的ASCII码值) ) from table_name where bh=’xxx’;
问题得以解决。但我发现,上述第②步求得的ASCII码值为41377,这应该是一个汉字的ASCII码值,看起来又像空格,于是我怀疑,会不会是中文状态下的空格键、TAB键?尝试之后发现不是。我又怀疑,是不是全角、半角的区别?因为我们一般输入字符,是在半角下输入的。我按照第一步“1.首先是去除空格在进行比较……”尝试,输入全角下的空格,进行查找,结果惊喜出现,原来所有未剔除掉的类空格,是全角状态下输入的空格,并接证实了全角下输入的空格,其ASCII码值为41377。
最后发现,杀鸡用了牛刀,因为问题很简单。但采用第3.提到的先取得ASCII码值再来进行剔除的方法,具有通用性!

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),