{"id":359,"date":"2023-09-16T10:44:51","date_gmt":"2023-09-16T02:44:51","guid":{"rendered":""},"modified":"2023-09-18T11:50:02","modified_gmt":"2023-09-18T03:50:02","slug":"sql%e6%88%aa%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%92%8c%e6%9b%bf%e6%8d%a2%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/359.html","title":{"rendered":"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5"},"content":{"rendered":"

1.\u8981\u64cd\u4f5c\u7684\u6570\u636e\u5e93\u7684\u8868<\/h3>\n

\"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5<\/p>\n

2. SELECT left(operateperson,2) from bus_inport<\/h3>\n

left(str,length)<\/p>\n

str\uff1a\u88ab\u622a\u53d6\u7684\u5b57\u7b26\u4e32\u3002
length\uff1a\u622a\u53d6\u7684\u957f\u5ea6<\/p>\n

\u4ece\u5de6\u8fb9\u5f00\u59cb\u622a\u53d6<\/p>\n

\u6267\u884c\u7684\u7ed3\u679c\uff1a<\/strong><\/p>\n

\"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5<\/p>\n

3. SELECT right(operateperson,1) from bus_inport<\/h3>\n

right(str,length)<\/p>\n

str\uff1a\u88ab\u622a\u53d6\u7684\u5b57\u7b26\u4e32\u3002
length\uff1a\u622a\u53d6\u7684\u957f\u5ea6<\/p>\n

\u4ece\u53f3\u8fb9\u5f00\u59cb\u622a\u53d6<\/p>\n

\u6267\u884c\u7ed3\u679c\uff1a<\/strong><\/p>\n

\"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5<\/p>\n

4.select substring(operateperson,1) as aa from bus_inport<\/h3>\n

substring(str,length)<\/p>\n

str\uff1a\u8981\u6267\u884c\u7684\u5b57\u6bb5<\/p>\n

length\uff1a\u622a\u53d6\u7684\u957f\u5ea6<\/p>\n

\u6267\u884c\u7ed3\u679c\uff1a<\/strong><\/p>\n

\"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5<\/p>\n

5. substring(str, pos, length)<\/h3>\n

str\uff1a\u88ab\u622a\u5b57\u7b26\u4e32
pos\uff1a\u5f00\u59cb\u7684\u4f4d\u7f6e
length\uff1a\u622a\u53d6\u7684 \u957f\u5ea6<\/p>\n

SELECT SUBSTRING('12345678', 3,2)<\/p>\n

    1<\/p>\n

\u7ed3\u679c\uff1a34
\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0
\u5982\u679c POS \u4e3a\u8d1f\u6570\uff0c\u5f00\u59cb\u4f4d\u7f6e\u4ece\u53f3\u4fa7\u5f00\u59cb\u6570\uff0c\u5411\u53f3\u53d6\u5b50\u4e32<\/p>\n

SELECT SUBSTRING('87654321', -3,2)<\/p>\n

    1<\/p>\n

\u7ed3\u679c\uff1a32
\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0<\/p>\n

6. \u6309\u5206\u9694\u7b26\u622a\u53d6 substring_index(str, delim, count)<\/h3>\n

str\uff1a\u88ab\u622a\u5b57\u7b26\u4e32
delim\uff1a\u5206\u9694\u7b26
count\uff1a\u7b2c\u51e0\u4e2a\u5206\u9694\u7b26\u3002\u6b63\u6570\uff1a\u53d6\u5de6\u4fa7\u7b2cN\u4e2a\u5206\u9694\u7b26\u5de6\u4fa7\u7684\u5b50\u4e32\uff1b\u8d1f\u6570\uff1a\u53d6\u53f3\u4fa7\u7b2cN\u4e2a\u5206\u9694\u7b26\u53f3\u4fa7\u7684\u5b50\u4e32\uff1b<\/p>\n

SELECT SUBSTRING_INDEX('1-2-3-4-5-6-7', '-', 2);<\/p>\n

    1<\/p>\n

\u7ed3\u679c\uff1a1-2
\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0<\/p>\n

SELECT SUBSTRING_INDEX('1-2-3-4-5-6-7', '-', -2);<\/p>\n

    1<\/p>\n

\u7ed3\u679c\uff1a6-7
\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0
\u5982\u679c\u88ab\u622a\u5b57\u7b26\u4e32\u91cc\u627e\u4e0d\u5230\u5206\u9694\u7b26\uff0c\u8fd4\u56de\u6574\u4e2a\u5b57\u7b26\u4e32<\/p>\n

SELECT SUBSTRING_INDEX('1-2-3-4-5-6-7', '%', -2);<\/p>\n

    1<\/p>\n

\u7ed3\u679c\uff1a1-2-3-4-5-6-7<\/p>\n

7.\u66ff\u6362SQL\u8bed\u53e5<\/h3>\n

\uff081\uff09\u66ff\u6362\u67e5\u8be2<\/strong><\/p>\n

select *,replace(operateperson,'\u5f20\u4e09','\u7ba1\u7406\u5458') AS operate from bus_inport<\/h3>\n

\u6267\u884c\u7ed3\u679c\uff1a<\/strong><\/p>\n

\"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5<\/p>\n

\uff082\uff09\u66ff\u6362\u4fee\u6539<\/strong><\/p>\n

update bus_inport set operateperson=replace(operateperson,'\u7ba1\u7406\u5458','\u5f20\u4e09') ,remark=replace(remark,'\u5f20\u4e09\uff0c\u6625\u5929\u6765\u4e86','\u5f20\u4e09')<\/h3>\n

 \"SQL\u622a\u53d6\u5b57\u7b26\u4e32\u548c\u66ff\u6362\u5b57\u6bb5<\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"1.\u8981\u64cd\u4f5c\u7684\u6570\u636e\u5e93\u7684\u88682.SELECTleft(operateperson,2)frombus_inportleft(str,length)str\uff1a\u88ab\u622a\u53d6\u7684\u5b57\u7b26\u4e32\u3002length\uff1a\u622a\u53d6\u7684\u957f...","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\/359"}],"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=359"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/359\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}