{"id":103,"date":"2024-12-08T10:43:25","date_gmt":"2024-12-08T02:43:25","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=103"},"modified":"2024-12-08T10:59:53","modified_gmt":"2024-12-08T02:59:53","slug":"sql%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e6%8b%bc%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/08\/sql%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e6%8b%bc%e6%8e%a5\/","title":{"rendered":"sql\u4e2d\u5982\u4f55\u8fdb\u884c\u62fc\u63a5"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5728 SQL \u4e2d\uff0c\u5b57\u7b26\u4e32\u62fc\u63a5\u662f\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c\uff0c\u5177\u4f53\u65b9\u6cd5\u56e0\u6570\u636e\u5e93\u800c\u5f02\u3002\u4ee5\u4e0b\u603b\u7ed3\u4e86\u4e0d\u540c\u6570\u636e\u5e93\u4e2d\u5e38\u7528\u7684\u62fc\u63a5\u65b9\u6cd5\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. MySQL<\/strong><\/h3>\n\n\n\n<p>\u4f7f\u7528 <code>CONCAT<\/code> \u51fd\u6570\u8fdb\u884c\u5b57\u7b26\u4e32\u62fc\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CONCAT('Hello', ', ', 'World!') AS greeting;<\/code><\/pre>\n\n\n\n<p><strong>\u62fc\u63a5\u5217\u7684\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CONCAT(first_name, ' ', last_name) AS full_name\nFROM employees;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u53ef\u80fd\u6709 <code>NULL<\/code> \u503c\uff0c<code>CONCAT<\/code> \u4f1a\u5ffd\u7565\u8be5\u5217\u4e3a <code>NULL<\/code> \u7684\u503c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. SQL Server<\/strong><\/h3>\n\n\n\n<p>\u4f7f\u7528 <code>+<\/code> \u8fd0\u7b97\u7b26\u8fdb\u884c\u5b57\u7b26\u4e32\u62fc\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT 'Hello' + ', ' + 'World!' AS greeting;<\/code><\/pre>\n\n\n\n<p><strong>\u62fc\u63a5\u5217\u7684\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT first_name + ' ' + last_name AS full_name\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>\u5904\u7406 <code>NULL<\/code> \u503c\uff1a<\/strong><br><code>+<\/code> \u64cd\u4f5c\u5982\u679c\u67d0\u5217\u4e3a <code>NULL<\/code>\uff0c\u62fc\u63a5\u7ed3\u679c\u4e5f\u4e3a <code>NULL<\/code>\uff0c\u53ef\u4ee5\u7528 <code>ISNULL<\/code> \u6216 <code>COALESCE<\/code> \u66ff\u4ee3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT ISNULL(first_name, '') + ' ' + ISNULL(last_name, '') AS full_name;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. PostgreSQL<\/strong><\/h3>\n\n\n\n<p>\u652f\u6301 <code>||<\/code> \u8fd0\u7b97\u7b26\u6216 <code>CONCAT<\/code> \u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528 ||\nSELECT 'Hello' || ', ' || 'World!' AS greeting;\n\n-- \u6216\u4f7f\u7528 CONCAT \u51fd\u6570\nSELECT CONCAT('Hello', ', ', 'World!') AS greeting;<\/code><\/pre>\n\n\n\n<p><strong>\u62fc\u63a5\u5217\u7684\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528 ||\nSELECT first_name || ' ' || last_name AS full_name\nFROM employees;\n\n-- \u4f7f\u7528 CONCAT\nSELECT CONCAT(first_name, ' ', last_name) AS full_name\nFROM employees;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Oracle<\/strong><\/h3>\n\n\n\n<p>\u4f7f\u7528 <code>||<\/code> \u8fd0\u7b97\u7b26\u8fdb\u884c\u5b57\u7b26\u4e32\u62fc\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT 'Hello' || ', ' || 'World!' AS greeting\nFROM dual;<\/code><\/pre>\n\n\n\n<p><strong>\u62fc\u63a5\u5217\u7684\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT first_name || ' ' || last_name AS full_name\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>\u5904\u7406 <code>NULL<\/code> \u503c\uff1a<\/strong><br>\u4f7f\u7528 <code>NVL<\/code> \u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT NVL(first_name, '') || ' ' || NVL(last_name, '') AS full_name\nFROM employees;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. SQLite<\/strong><\/h3>\n\n\n\n<p>\u4f7f\u7528 <code>||<\/code> \u8fd0\u7b97\u7b26\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT 'Hello' || ', ' || 'World!' AS greeting;<\/code><\/pre>\n\n\n\n<p><strong>\u62fc\u63a5\u5217\u7684\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT first_name || ' ' || last_name AS full_name\nFROM employees;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>NULL \u7684\u5f71\u54cd<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u62fc\u63a5\u4e2d\uff0c<code>NULL<\/code> \u53ef\u80fd\u5bfc\u81f4\u7ed3\u679c\u4e3a <code>NULL<\/code>\uff0c\u5404\u6570\u636e\u5e93\u63d0\u4f9b\u76f8\u5e94\u7684\u5904\u7406\u51fd\u6570\uff1a<\/li>\n\n\n\n<li>MySQL\uff1a<code>IFNULL(column, '')<\/code><\/li>\n\n\n\n<li>SQL Server\uff1a<code>ISNULL(column, '')<\/code> \u6216 <code>COALESCE(column, '')<\/code><\/li>\n\n\n\n<li>PostgreSQL\uff1a<code>COALESCE(column, '')<\/code><\/li>\n\n\n\n<li>Oracle\uff1a<code>NVL(column, '')<\/code><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u6027\u80fd\u548c\u53ef\u8bfb\u6027<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u9700\u8981\u62fc\u63a5\u8f83\u591a\u5b57\u6bb5\uff0c<code>CONCAT<\/code> \u51fd\u6570\u53ef\u80fd\u66f4\u6e05\u6670\u6613\u8bfb\u3002<\/li>\n\n\n\n<li>\u5728\u52a8\u6001 SQL \u6216\u590d\u6742\u67e5\u8be2\u4e2d\uff0c\u6ce8\u610f\u5408\u7406\u5904\u7406 <code>NULL<\/code> \u548c\u5206\u9694\u7b26\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6839\u636e\u4f60\u7684\u6570\u636e\u5e93\u73af\u5883\uff0c\u9009\u62e9\u9002\u5408\u7684\u62fc\u63a5\u65b9\u5f0f\u5373\u53ef\u3002\u9700\u8981\u66f4\u591a\u793a\u4f8b\uff0c\u968f\u65f6\u544a\u8bc9\u6211\uff01<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 SQL \u4e2d\uff0c\u5b57\u7b26\u4e32\u62fc\u63a5\u662f\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c\uff0c\u5177\u4f53\u65b9\u6cd5\u56e0\u6570\u636e\u5e93\u800c\u5f02\u3002\u4ee5\u4e0b\u603b\u7ed3\u4e86\u4e0d\u540c\u6570\u636e\u5e93\u4e2d\u5e38 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[39],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-sql","tag-39"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":3,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}