Posted 涔﹀湀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。
鐐瑰嚮涓婂浘鏌ョ湅鏁欏澶х翰
馃嵑鐭ヤ箣涓虹煡涔嬶紝涓嶇煡涓轰笉鐭ワ紝鏄煡涔熴€傗€斺€斻€婅璇€?
浠婂ぉ鎴戜滑鏉ヨ亰鑱?MySQL 涓瓨鍦ㄧ殑闅愬紡鏁版嵁绫诲瀷杞崲浠ュ強鍙兘甯︽潵鐨勯棶棰樸€?/span>
褰撲袱涓笉鍚岀被鍨嬬殑鏁版嵁杩涜杩愮畻鏃讹紝涓轰簡浣垮緱瀹冧滑鑳藉鍏煎锛孧ySQL 鍙兘浼氭墽琛岄殣寮忕殑鏁版嵁绫诲瀷杞崲銆備緥濡傦紝MySQL 鍦ㄩ渶瑕佹椂浼氳嚜鍔ㄥ皢瀛楃涓茶浆鎹负鏁板瓧锛屽弽涔嬩害鐒躲€?/span>
'1'; SELECT 1+
-> 2
' test'); SELECT CONCAT(2,
-> '2 test'
鎴戜滑涔熷彲浣跨敤 CAST() 鍑芥暟灏嗘暟瀛楁樉寮忚浆鎹负瀛楃涓层€?/span>CONCAT() 鍑芥暟涓殑闅愬紡绫诲瀷杞崲鏄洜涓哄畠鍙兘鎺ユ敹瀛楃涓茬被鍨嬬殑鍙傛暟銆?/span>
mysql> SELECT 38.8, CAST(38.8 AS CHAR);
-> 38.8, '38.8'
mysql> SELECT 38.8, CONCAT(38.8);
-> 38.8, '38.8'
浠ヤ笅鏄瘮杈冭繍绠椾腑鐨勭被鍨嬭浆鎹㈣鍒欙細
濡傛灉浠绘剰涓€涓弬鏁颁负 NULL锛屾瘮杈冪殑缁撴灉涓?NULL锛?lt;=> 鐩哥瓑姣旇緝杩愮畻绗﹂櫎澶栥€侼ULL <=> NULL 鐨勮繍绠楃粨鏋滀负 true锛屼笉闇€瑕佽繘琛岀被鍨嬭浆鎹€?/span>
濡傛灉涓や釜鍙傛暟閮芥槸瀛楃涓诧紝鎵ц瀛楃涓叉瘮杈冦€?/span>
濡傛灉涓や釜鍙傛暟閮芥槸鏁存暟锛屾墽琛屾暣鏁版瘮杈冦€?/span>
濡傛灉涓嶆槸鍜屾暟瀛楄繘琛屾瘮杈冿紝鍗佸叚杩涘埗鏁板€煎皢琚湅浣滀簩杩涘埗瀛楃涓层€?/span>
濡傛灉涓€涓弬鏁版槸 TIMESTAMP 鎴栬€?DATETIME 瀛楁锛屽彟涓€涓弬鏁版槸甯搁噺锛岃甯搁噺灏嗕細鍦ㄦ瘮杈冧箣鍓嶈浆鎹负鏃堕棿鎴崇被鍨嬨€傝繖涓€瑙勫垯鏄负浜嗘洿濂藉湴鏀寔 ODBC 瑙勮寖銆侷N() 杩愮畻绗︿腑鐨勫弬鏁颁笉浼氭墽琛岃繖涓€杞崲銆備负浜嗕繚闄╄捣瑙侊紝璁板緱鍦ㄦ墽琛屾瘮杈冭繍绠楁椂浣跨敤瀹屾暣鐨勬棩鏈熸椂闂淬€佹棩鏈熸垨鑰呮椂闂村瓧绗︿覆銆備緥濡傦紝鍦ㄤ娇鐢?BTWEEN 杩愮畻绗﹀垽鏂棩鏈熸垨鑰呮椂闂存暟鎹椂锛屽埄鐢?CAST() 鍑芥暟灏嗘暟鎹殑绫诲瀷鏄剧ず杞崲鎴愮浉搴旂殑绫诲瀷銆?/span>
杩斿洖鍗曡缁撴灉鐨勫瓙鏌ヨ涓嶄細琚綋浣滃父閲忋€備緥濡傦紝褰撲竴涓繑鍥炴暣鏁扮殑瀛愭煡璇㈠拰 DATETIME 鏁版嵁杩涜姣旇緝鏃讹紝DATETIME 灏嗕細琚浆鎹负鏁存暟绫诲瀷锛岃€屼笉浼氬皢瀛愭煡璇㈢殑缁撴灉杞崲涓烘椂闂寸被鍨嬨€傚鏋滄兂瑕佹墽琛屾棩鏈熸椂闂存瘮杈冿紝鍙互浣跨敤 CAST() 鍑芥暟鏄惧紡灏嗗瓙鏌ヨ鐨勭粨鏋滆浆鎹负 DATETIME 绫诲瀷銆?/span>
濡傛灉涓€涓弬鏁颁负绮剧‘鏁板瓧绫诲瀷锛坉ecimal锛夛紝姣旇緝鐨勬柟娉曞彇鍐充簬鍙︿竴涓弬鏁扮殑绫诲瀷銆傚鏋滃彟涓€涓弬鏁版槸绮剧‘鏁板瓧鎴栬€呮暣鏁扮被鍨嬶紝浣跨敤绮剧‘鏁板瓧姣旇緝锛涘鏋滃彟涓€涓弬鏁版槸娴偣鏁扮被鍨嬶紝浣跨敤娴偣鏁版瘮杈冦€?/span>
鍏朵粬鎯呭喌涓嬶紝浣跨敤娴偣鏁版瘮杈冦€備緥濡傦紝瀛楃涓插拰绮剧‘鏁板瓧鐨勬瘮杈冧娇鐢ㄦ诞鐐规暟姣旇緝鏂规硶銆?/span>
鍏充簬鏃堕棿绫诲瀷涔嬮棿鐨勮浆鎹㈣鍒欙紝鍙互鍙傝€冨畼鏂规枃妗c€?/span>
浠ヤ笅绀轰緥婕旂ず浜嗗皢瀛楃涓茶浆鎹负鏁板瓧鐨勬瘮杈冩搷浣滐細
'6x'; SELECT 1 >
-> 0
'6x'; SELECT 7 >
-> 1
'x6'; SELECT 0 >
-> 0
'x6'; SELECT 0 =
-> 1
濡傛灉灏嗗瓧绗︿覆绫诲瀷鐨勫瓧娈靛拰鏁板瓧杩涜姣旇緝锛孧ySQL 鏃犳硶浣跨敤璇ュ瓧娈典笂鐨勭储寮曞揩閫熸煡鎵炬暟鎹€備緥濡傦紝str_col 鏄竴涓储寮曞瓧娈碉紝璇ョ储寮曟棤娉曠敤浜庝互涓嬭鍙ワ細
SELECT * FROM tbl_name WHERE str_col=1;
闂鐨勫師鍥犲湪浜庡緢澶氫笉鍚岀殑瀛楃涓查兘鍙互杞崲涓烘暟瀛?1锛屼緥濡傗€?鈥欍€佲€?1鈥?鎴栬€?鈥?a鈥欍€?/span>
娴偣鏁板拰 INTEGER 绫诲瀷鐨勮秴澶ф暟鍊间箣闂寸殑姣旇緝鏄繎浼兼瘮杈冿紝鍥犱负鏁存暟鍦ㄦ瘮杈冧箣鍓嶉渶瑕佽浆鎹负鍙岀簿搴︽诞鐐规暟锛屽弻绮惧害娴偣鏁版棤娉曠簿纭湴琛ㄧず鎵€鏈夌殑 64 浣嶆暣鏁般€備緥濡傦紝鏁存暟 253 + 1 鏃犳硶浣跨敤娴偣鏁拌繘琛岃〃绀猴紝鍙兘杩戜技涓?253 鎴栬€?253 + 2銆?/span>
涓句緥鏉ヨ锛屼互涓嬪彧鏈夌涓€涓瘮杈冭繍绠椾腑鐨勪袱涓€肩浉绛夛紝浣嗘槸涓や釜姣旇緝杩愮畻閮借繑鍥炰簡 true锛?锛夛細
'9223372036854775807' = 9223372036854775807; SELECT
-> 1
'9223372036854775807' = 9223372036854775806; SELECT
-> 1
瀛楃涓茶浆鎹负娴偣鏁颁笌鏁存暟杞崲涓烘诞鐐规暟鐨勬柟寮忓彲鑳戒笉鍚屻€傛暣鏁板彲鑳戒娇鐢?CPU 杞崲涓烘诞鐐规暟锛岃€屽瓧绗︿覆鍙兘浣跨敤娴偣鏁颁箻娉曡繘琛岄€愪綅杞崲銆傚彟澶栵紝杞崲缁撴灉鍙兘鍙楀埌鍚勭鍥犵礌鐨勫奖鍝嶏紝渚嬪璁$畻鏈虹殑鏋舵瀯銆佺紪璇戝櫒鐗堟湰鎴栬€呬紭鍖栫骇鍒瓑銆傞伩鍏嶈繖绉嶉棶棰樼殑鏂规硶涔嬩竴灏辨槸浣跨敤 CAST() 鍑芥暟锛岃繖鏍锋暟鎹氨涓嶄細琚殣寮忚浆鎹负娴偣鏁般€?/span>
'9223372036854775807' AS UNSIGNED) = 9223372036854775806; SELECT CAST(
-> 0
鍏充簬娴偣鏁版瘮杈冪殑鏇村淇℃伅锛屽彲浠ュ弬鑰冨畼鏂规枃妗c€?
MySQL 鏈嶅姟鍣ㄦ彁渚涗簡涓€涓浆鎹㈠簱 dtoa锛屽彲浠ユ敮鎸佸瓧绗︿覆鎴栬€?DECIMAL 鏁版嵁鍜岃繎浼兼暟瀛楋紙FLOAT/DOUBLE锛変箣闂寸殑鍩烘湰杞崲鍔熻兘锛?/span>
璺ㄥ钩鍙扮殑涓€鑷存€ц浆鎹㈢粨鏋滐紝渚嬪锛屽彲浠ユ秷闄?Unix 鍜?Windows 涔嬮棿鐨勫樊寮傘€?/span>
鍙互绮剧‘琛ㄧず涔嬪墠鏃犳硶鎻愪緵瓒冲绮惧害鐨勬暟鎹紝渚嬪鎺ヨ繎 IEEE 闄愬埗鐨勬暟鎹€?/span>
浠ュ敖鍙兘楂樼殑绮惧害灏嗘暟瀛楄浆鎹㈡垚瀛楃涓叉牸寮忋€俤toa 鐨勭簿搴︽€绘槸绛変簬鎴栬€呴珮浜庢爣鍑?C 浠g爜搴撳嚱鏁般€?/span>
鏁板瓧鎴栬€呮椂闂寸被鍨嬪埌瀛楃涓茬殑闅愬紡杞崲缁撴灉鐨勫瓧绗﹂泦鍜屾帓搴忚鍒欏彇鍐充簬 character_set_connection 鍜?collation_connection 绯荤粺鍙橀噺銆傦紙杩欎簺鍙橀噺閫氬父浣跨敤 SET NAMES 杩涜璁剧疆銆傚叧浜庤繛鎺ョ殑瀛楃闆嗙殑淇℃伅锛屽彲浠ュ弬鑰冨畼鏂规枃妗c€傦級
杩欐剰鍛崇潃杩欑杞崲鐨勭粨鏋滄槸涓€涓潪浜岃繘鍒剁殑瀛楃涓诧紙CHAR銆乂ARCHAR 鎴栬€?LONGTEXT锛夛紝闄ら潪杩炴帴瀛楃闆嗚璁剧疆涓?binary銆傛鏃讹紝杞崲缁撴灉鏄竴涓簩杩涘埗瀛楃涓诧紙BINARY銆乂ARBINARY 鎴栬€?LONGBLOB锛夈€?/span>
瀵逛簬鏁存暟绫诲瀷鐨勮〃杈惧紡锛屽墠鏂囨墍杩扮殑琛ㄨ揪寮忔眰鍊煎拰琛ㄨ揪寮忚祴鍊兼湁鎵€涓嶅悓銆備緥濡備互涓嬭鍙ワ細
CREATE TABLE t SELECT integer_expr;
杩欑鎯呭喌涓嬶紝琛?t 鐨勫瓧娈电被鍨嬪彇鍐充簬鏁存暟琛ㄨ揪寮忕殑闀垮害锛屽彲鑳芥槸 INT 鎴栬€?BIGINT銆傚鏋滆〃杈惧紡鐨勬渶澶ч暱搴﹁秴杩囦簡 INT锛屼娇鐢?BIGINT 绫诲瀷銆傝繖灏辨剰鍛崇潃鎴戜滑鍙互閫氳繃涓€涓冻澶熼暱鐨勮〃杈惧紡鍒涘缓 BIGINT 绫诲瀷鐨勫瓧娈碉細
CREATE TABLE t SELECT 000000000000000000000 AS col;
DESC t;
Field|Type |Null|Key|Default|Extra|
-----+------+----+---+-------+-----+
col |bigint|NO | |0 | |
JSON 鏁版嵁鐨勬瘮杈冨垎涓轰袱绉嶆儏鍐点€傜涓€灞傛鐨勬瘮杈冨熀浜庤姣旇緝鏁版嵁鐨?JSON 绫诲瀷锛屽鏋滀袱涓被鍨嬩笉鍚岋紝姣旇緝鐨勭粨鏋滃彇鍐充簬鍏锋湁鏇撮珮浼樺厛绾х殑绫诲瀷锛涘鏋滀袱涓暟鎹殑 JSON 绫诲瀷鐩稿悓锛屼娇鐢ㄥ叿浣撶殑绫诲瀷瑙勫垯杩涜绗簩灞傛鐨勬瘮杈冦€傚浜?JSON 鍜岄潪 JSON 鏁版嵁鐨勬瘮杈冿紝鍏堝皢闈?JSON 鏁版嵁杞崲涓?JSON 绫诲瀷锛岀劧鍚庤繘琛屾瘮杈冦€傝缁嗕俊鎭彲浠ュ弬鑰冨畼鏂规枃妗c€?/span>
鍏ㄤ功涓昏璁鸿堪浜嗘暟鎹簱鐩稿叧鍩烘湰姒傚康銆佸熀鏈悊璁哄拰鍩烘湰鎶€鏈紝鍏辫9绔狅紝鍐呭鍖呮嫭鏁版嵁搴撶郴缁熺殑浜х敓涓庡彂灞曘€佹暟鎹簱绯荤粺鐗圭偣銆佹暟鎹簱绯荤粺鐨勬暟鎹ā鍨嬨€佹暟鎹簱绯荤粺浣撶郴缁撴瀯銆佸叧绯绘暟鎹簱鏂规硶銆佸叧绯绘暟鎹簱鏍囧噯璇█SQL銆佸叧绯昏鑼冨寲鐞嗚銆佹暟鎹簱璁捐銆佹暟鎹簱淇濇姢銆佹暟鎹簱璁捐瀹炰緥鍜屾暟鎹簱鎶€鏈柊鍙戝睍绛夈€?/span>
鏈功鏃粙缁嶄簡缁忓吀鐨勬暟鎹簱鐞嗚鍙婅璁℃柟娉曪紝鍙堝睍绀轰簡鐩墠骞挎硾搴旂敤鐨勫紑婧愭暟鎹簱绠$悊绯荤粺MySQL鐨勫疄闄呮搷浣滄楠わ紝鍚屾椂杩樼粰鍑轰簡涓€涓晶閲嶆暟鎹簱璁捐杩囩▼鐨勫簲鐢ㄧ郴缁熷紑鍙戝疄渚嬶紝鎵撻€氫簡浠庣悊璁哄埌鍏蜂綋DBMS搴旂敤鍐嶅埌瀹炰緥寮€鍙戜笁涓噸瑕佺幆鑺傘€備负鍒濆鑰呮墦鐗㈢悊璁哄熀纭€鐨勫悓鏃讹紝鍙堟⒊鐞嗕簡鏁版嵁搴撳簲鐢ㄧ▼搴忓紑鍙戠殑閲嶈鐜妭锛屽仛鍒板浠ヨ嚧鐢ㄣ€?/span>
鏈功鍙互浣滀负楂樼瓑闄㈡牎璁$畻鏈轰笓涓氭暟鎹簱鍘熺悊涓庡簲鐢ㄨ绋嬬殑鏁欏鐢ㄤ功銆佽绠楁満鐩稿叧涓撲笟鐨勬暀瀛︾敤涔︼紝涔熷彲浠ヤ綔涓轰粠浜嬭绠楁満銆佺鐞嗙瀛﹀伐浣滅殑璇昏€咃紝浠ュ強绉戞妧浜哄憳鍜屽鏁版嵁搴撴妧鏈劅鍏磋叮鐨勫垵瀛﹁€呯瓑鐨勫涔犵敤涔︽垨鍙傝€冧功銆?/span>
鐞嗚&瀹炴垬锛岄」鐩渚嬬簿璁?/span>
渚嬮銆佷範棰橀€夋潗绮捐壇
閰嶅璧勬簮涓板瘜锛氳浠禤PT銆佷範棰樼瓟妗堛€佹暀瀛﹀ぇ绾?/span>