⑴ 濡備綍鐢∕YSQL妯$硦鏌ヨ⒙仿仿
SQL妯$硦鏌ヨ㈢殑璇娉曚负
鈥淪ELECT column FROM table WHERE column LIKE ';pattern';鈥濄
SQL鎻愪緵浜嗗洓绉嶅尮閰嶆ā寮忥細
1. % 琛ㄧず浠绘剰0涓鎴栧氫釜瀛楃︺傚備笅璇鍙ワ細
SELECT * FROM user WHERE name LIKE ';%涓%';
灏嗕細鎶妌ame涓衡滃紶涓夆濓紝鈥滀笁鑴氱尗鈥濓紝鈥滃攼涓夎棌鈥濈瓑绛夋湁鈥滀笁鈥濈殑鍏ㄦ壘鍑烘潵锛
2. _ 琛ㄧず浠绘剰鍗曚釜瀛楃︺傝鍙ワ細
SELECT * FROM user WHERE name LIKE ';_涓塤';
鍙鎵惧嚭鈥滃攼涓夎棌鈥濊繖鏍穘ame涓轰笁涓瀛椾笖涓闂翠竴涓瀛楁槸鈥滀笁鈥濈殑锛
SELECT * FROM user WHERE name LIKE ';涓塤_';
鍙鎵惧嚭鈥滀笁鑴氱尗鈥濊繖鏍穘ame涓轰笁涓瀛椾笖绗涓涓瀛楁槸鈥滀笁鈥濈殑锛
3. [ ] 琛ㄧず鎷鍙峰唴鎵鍒楀瓧绗︿腑鐨勪竴涓锛堢被浼间笌姝e垯琛ㄨ揪寮忥級銆傝鍙ワ細
SELECT * FROM user WHERE name LIKE ';[寮犳潕鐜媇涓';
灏嗘壘鍑衡滃紶涓夆濄佲滄潕涓夆濄佲滅帇涓夆濓紙鑰屼笉鏄鈥滃紶鏉庣帇涓夆濓級锛
濡 [ ] 鍐呮湁涓绯诲垪瀛楃︼紙01234銆乤bcde涔嬬被鐨勶級鍒欏彲鐣ュ啓涓衡0-4鈥濄佲渁-e鈥
SELECT * FROM user WHERE name LIKE ';鑰乕1-9]';
灏嗘壘鍑衡滆1鈥濄佲滆2鈥濄佲︹︺佲滆9鈥濓紱
濡傝佹壘鈥-鈥濆瓧绗﹁峰皢鍏舵斁鍦ㄩ栦綅锛';寮犱笁[-1-9]';
4. [^ ] 琛ㄧず涓嶅湪鎷鍙锋墍鍒椾箣鍐呯殑鍗曚釜瀛楃︺傝鍙ワ細
SELECT * FROM user WHERE name LIKE ';[^寮犳潕鐜媇涓';
灏嗘壘鍑轰笉濮撯滃紶鈥濄佲滄潕鈥濄佲滅帇鈥濈殑鈥滆档涓夆濄佲滃瓩涓夆濈瓑锛
SELECT * FROM user WHERE name LIKE ';鑰乕^1-4]';
灏嗘帓闄も滆1鈥濆埌鈥滆4鈥濆绘壘鈥滆5鈥濄佲滆6鈥濄佲︹︺佲滆9鈥濄
锛佹渶鍚庢槸閲嶇偣锛
鐢变簬閫氶厤绗︾殑缂樻晠锛屽艰嚧鎴戜滑鏌ヨ㈢壒娈婂瓧绗︹%鈥濄佲淿鈥濄佲淸鈥濄佲';鈥濈殑璇鍙ユ棤娉曟e父瀹炵幇锛岃屾妸鐗规畩瀛楃︾敤鈥淸 ]鈥濇嫭璧蜂究鍙姝e父鏌ヨ銆傛嵁姝ゆ垜浠鍐欏嚭浠ヤ笅鍑芥暟锛
function sqlencode(str)
str=replace(str,"';","';';")
str=replace(str,"[","[[]") ';姝ゅ彞涓瀹氳佸湪鏈鍏
str=replace(str,"_","[_]")
str=replace(str,"%","[%]")
sqlencode=str
end function