\n\u5b57\u7b26\u4e32\u622a\u53d6\u51fd\u6570\uff0c\u4e5f\u662f\u6211\u4eec\u5728\u6570\u636e\u5f00\u53d1\u5206\u6790\u7684\u8fc7\u7a0b\u4e2d\u6bd4\u8f83\u5e38\u7528\u7684\u51fd\u6570\uff0c\u6bd4\u8f83\u5e38\u7528\u7684\u51fd\u6570\uff0c\u6709\u56db\u4e2a left()\u3001right()\u3001substr()\u3001substring_index() \u51fd\u6570\u3002<\/p>\n<\/blockquote>\n
\u4e00\u3001left()\u51fd\u6570<\/h1>\n
\u542b\u4e49\uff1a\u8fd4\u56de\u4ece\u5b57\u7b26\u4e32\u5de6\u8fb9\u5f00\u59cb\u6307\u5b9a\u4e2a\u6570\u7684\u5b57\u7b26
\u8bed\u6cd5\u683c\u5f0f\uff1aleft(column,n)
\u91ca\u4e49\uff1a\u4ece\u5b57\u6bb5column\u7684\u5b57\u7b26\u4e32\u5185\u5bb9\u7684\u5de6\u9762\u5f00\u59cb\u622a\u53d6\uff0c\u603b\u5171\u622a\u53d6 n \u7684\u4f4d\u7f6e\u3002
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT office_name,LEFT(office_name,2) FROM database.table
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
\u4e8c\u3001right()\u51fd\u6570<\/h1>\n
\u542b\u4e49\uff1a\u8fd4\u56de\u4ece\u5b57\u7b26\u4e32\u53f3\u8fb9\u5f00\u59cb\u6307\u5b9a\u4e2a\u6570\u7684\u5b57\u7b26
\u8bed\u6cd5\u683c\u5f0f\uff1aright(column,n)
\u91ca\u4e49\uff1a\u4ece\u5b57\u6bb5column\u7684\u5b57\u7b26\u4e32\u5185\u5bb9\u7684\u53f3\u9762\u5f00\u59cb\u622a\u53d6\uff0c\u603b\u5171\u622a\u53d6 n \u7684\u4f4d\u7f6e
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT office_name,right(office_name,1) FROM database.table
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
\u4e09\u3001substr()\u51fd\u6570<\/h1>\n
substr()\u51fd\u6570\u662f\u6211\u4eec\u5728\u505a\u5b57\u7b26\u4e32\u622a\u53d6\u7684\u65f6\u5019\uff0c\u7528\u7684\u76f8\u5bf9\u6bd4\u8f83\u5bf9\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u6bd4\u8f83\u7075\u6d3b\uff0c\u53c2\u6570\u6bd4\u8f83\u4e30\u5bcc\uff0c\u53ef\u4ee5\u5b9e\u73b0\u76f8\u5bf9\u590d\u6742\u4e00\u70b9\u7684\u5b57\u7b26\u4e32\u622a\u53d6\u9700\u6c42\u3002
\u683c\u5f0f\uff1asubstr( expression , start , length )
\u91ca\u4e49\uff1a
\uff081\uff09expression\uff1a\u9700\u8981\u88ab\u622a\u53d6\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u3001\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u3001text\u3001image\u3001\u5217\u6216\u5305\u542b\u5217\u7684\u8868\u8fbe\u5f0f\u3002
\uff082\uff09start \uff1a\u5f00\u59cb\u622a\u53d6\u7684\u4f4d\u7f6e\u3002
\uff083\uff09length \uff1a\u9700\u8981\u622a\u53d6\u7684\u957f\u5ea6\uff0c\uff08\u8fd9\u4e2a\u53c2\u6570\u53ef\u4ee5\u7701\u7565\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u622a\u53d6\u957f\u5ea6\uff0c\u9ed8\u8ba4\u622a\u53d6\u540e\u9762\u7684\u6240\u6709\u5b57\u7b26\uff09\u3002<\/p>\n
1\uff0c\u4ece\u6307\u5b9a\u4f4d\u7f6e\u5f00\u59cb\u622a\u53d6\u5230\u5b57\u7b26\u4e32\u7ed3\u675f<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstr(column,2)
\u91ca\u4e49\uff1a\u4ececolumn\u7684\u7b2c\u4e8c\u4f4d\u5f00\u59cb\u622a\u53d6\uff0c\u5230\u5b57\u7b26\u4e32\u7ed3\u675f
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT office_name,SUBSTR(office_name,2) FROM database.table \uff1b
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
2\uff0c\u4ece\u6307\u5b9a\u4f4d\u7f6e\u622a\u53d6\uff0c\u5e76\u6307\u5b9a\u622a\u53d6\u4f4d\u6570<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstr(column,2,1)
\u91ca\u4e49\uff1a\u4ececolumn\u7684\u7b2c\u4e8c\u4f4d\u5f00\u59cb\u622a\u53d6\uff0c\u622a\u53d6\u4e00\u4f4d
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT office_name,SUBSTR(office_name,2,1) FROM database.table \uff1b
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
3\uff0c\u4ece\u5b57\u7b26\u4e32\u672b\u5c3e\u7b2c\u4e00\u4f4d\u5f00\u59cb\u622a\u53d6<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstr(column,-1)
\u91ca\u4e49\uff1a\u4ece\u5b57\u7b26\u4e32\u672b\u5c3e\u7b2c\u4e00\u4f4d\u5f00\u59cb\u622a\u53d6\uff0c\u7701\u7565\u7b2c\u4e09\u4e2a\u51fd\u6570\uff0c\u8868\u793a\u622a\u53d6\u6574\u4e2a\u5b57\u7b26\u4e32
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT office_name,SUBSTR(office_name,-1) FROM database.table
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
4\uff0c\u4ece\u5b57\u7b26\u4e32\u5012\u6570\u51e0\u4f4d\u5f00\u59cb\u622a\u53d6\uff0c\u6307\u5b9a\u4e2a\u6570\u7684\u5b57\u7b26<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstr(column,-2,1)
\u91ca\u4e49\uff1a\u4ececolumn\u5012\u6570\u7b2c\u4e8c\u4f4d\u5f00\u59cb\u622a\u53d6\uff0c\u622a\u53d6\u4e00\u4f4d
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT office_name,SUBSTR(office_name,-2,1) FROM database.table
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
\u56db\u3001substring_index() \u51fd\u6570<\/h1>\n1\uff0c\u6307\u5b9a\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e2d\u4ece\u524d\u5f80\u540e\u6570\u51fa\u73b0\u6b21\u6570\u4f4d\u7f6e\uff0c\u622a\u53d6\u8be5\u4f4d\u7f6e\u4e4b\u524d\u7684\u6240\u6709\u5b57\u7b26<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstring_index(column,str,count)
\u91ca\u4e49\uff1a\u622a\u53d6\u5b57\u7b26\u4e32column\uff0cstr\u51fa\u73b0\u4ece\u524d\u5f80\u540e\u6570\u7b2ccount\u6b21\uff0c\u4e4b\u524d\u7684\u6240\u6709\u5b57\u7b26
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT substring_index(\u2018www.baidu.com\u2019,\u2018.\u2019,2)
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
2\uff0c\u6307\u5b9a\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e2d\u4ece\u540e\u5f80\u524d\u6570\u51fa\u73b0\u6b21\u6570\u4f4d\u7f6e\uff0c\u622a\u53d6\u8be5\u4f4d\u7f6e\u4e4b\u540e\u7684\u6240\u6709\u5b57\u7b26<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstring_index(column,str,-count)
\u91ca\u4e49\uff1a\u622a\u53d6\u5b57\u7b26\u4e32column\uff0cstr\u51fa\u73b0\u4ece\u540e\u5f80\u524d\u6570\u7b2ccount\u6b21\uff0c\u4e4b\u540e\u7684\u6240\u6709\u5b57\u7b26
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT substring_index(\u2018www.baidu.com\u2019,\u2018.\u2019,-2)
\u7ed3\u679c\u5c55\u793a\uff1a
<\/p>\n
3\uff0c\u6307\u5b9a\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e0d\u5b58\u5728<\/h2>\n
\u8868\u8fbe\u5f0f\uff1asubstring_index(column,str,count)
\u793a\u4f8b\u8bed\u53e5\uff1aSELECT substring_index(\u2018www.baidu.com\u2019,\u2018Goole\u2019,2)
\u7ed3\u679c\u5c55\u793a\uff1a
\u4ee5\u4e0a\u5c31\u662f\u6211\u5728\u5de5\u4f5c\u4e2d\u5e38\u7528\u7684\uff0c\u5206\u4eab\u51fa\u6765\uff0c\u5e0c\u671b\u53ef\u4ee5\u548c\u5927\u5bb6\u4e00\u8d77\u4ea4\u6d41~~<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b57\u7b26\u4e32\u622a\u53d6\u51fd\u6570\uff1aleft()\u3001right()\u3001substr()\u3001substring_index()\u51fd\u6570_sql\u622a\u53d6\u5b57\u7b26\u4e32","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/361"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}