⑴ 濡備綍鐢∕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