<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JSON 欄位排序 &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/json-%E6%AC%84%E4%BD%8D%E6%8E%92%E5%BA%8F/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Tue, 23 Jan 2024 05:07:30 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>JSON 欄位排序 &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MariaDB JSON_EXTRACT: 從 JSON 欄位取值</title>
		<link>https://noter.tw/12503/mariadb-json_extract-%e5%be%9e-json-%e6%ac%84%e4%bd%8d%e5%8f%96%e5%80%bc/</link>
					<comments>https://noter.tw/12503/mariadb-json_extract-%e5%be%9e-json-%e6%ac%84%e4%bd%8d%e5%8f%96%e5%80%bc/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 14 Jan 2024 10:56:23 +0000</pubDate>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[JSON 欄位排序]]></category>
		<category><![CDATA[搜尋 JSON]]></category>
		<category><![CDATA[JSON KEY]]></category>
		<category><![CDATA[查詢條件]]></category>
		<category><![CDATA[排序條件]]></category>
		<category><![CDATA[mariadb]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[讀取 json 欄位]]></category>
		<category><![CDATA[JSON_EXTRACT]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=12503</guid>

					<description><![CDATA[<p>根據 JSON 路徑取得儲存在 MariaDB 資料庫中的 JSON 欄位的值，JSON_EXTRACT 可以用在 SELECT 欄位、WHERE 條件及 ORDER BY 排序 &#8230; 等。&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/12503/mariadb-json_extract-%e5%be%9e-json-%e6%ac%84%e4%bd%8d%e5%8f%96%e5%80%bc/" data-wpel-link="internal">MariaDB JSON_EXTRACT: 從 JSON 欄位取值</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>根據 JSON 路徑取得儲存在 MariaDB 資料庫中的 JSON 欄位的值，JSON_EXTRACT 可以用在 SELECT 欄位、WHERE 條件及 ORDER BY 排序 &#8230; 等。</p>



<span id="more-12503"></span>



<h2 class="wp-block-heading para">JSON_EXTRACT</h2>



<h3 class="wp-block-heading para">語法</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">JSON_EXTRACT(json_doc, path[, path] ...)</pre>



<h3 class="wp-block-heading para">說明</h3>



<p>從 JSON <span style="text-decoration: underline;">欄位</span>中讀取資料，讀取的依據是<span style="text-decoration: underline;">路徑參數</span>相符的部分，函數將回傳所有符合的值；如果回傳值為多個值，則結果會按符合的順序自動包裝為陣列，如果沒有路徑匹配或任何參數為 NULL，則傳回 NULL。</p>



<p>如果<span style="text-decoration: underline;">路徑參數</span>不是有效路徑，或者 json_doc 參數不是有效的 JSON 文檔，則會發生錯誤。路徑表達式是 MariaDB 支援的 <a href="https://mariadb.com/kb/en/jsonpath-expressions/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">JSONPath 表達式<span class="wpel-icon wpel-image wpel-icon-6"></span></a>。 (<a href="https://mariadb.com/kb/en/json_extract/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">參考資料<span class="wpel-icon wpel-image wpel-icon-6"></span></a>)</p>



<h3 class="wp-block-heading para">範例</h3>



<p>用在 ORDER BY 排序</p>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">SELECT * FROM `tender` ORDER BY JSON_EXTRACT(`json`, '$.create_date') DESC;</pre>



<p>用在搜尋欄位</p>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">SELECT * FROM `tender` WHERE JSON_EXTRACT(`json`, '$.title') = '公告';</pre>



<p>用在欄位取得</p>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">SELECT `id`, JSON_EXTRACT(`json`, '$.title') AS `title` FROM `tender`;</pre>



<p>延伸閱讀：<br></p>



<p><strong>MySQL / MariaDB / Oracle 相關文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list">
<li><a href="https://noter.tw/12503/mariadb-json_extract-%e5%be%9e-json-%e6%ac%84%e4%bd%8d%e5%8f%96%e5%80%bc/" data-wpel-link="internal">MariaDB JSON_EXTRACT: 從 JSON 欄位取值</a></li>



<li><a href="https://noter.tw/12015/oracle-%e5%88%86%e7%b5%84%e7%b7%a8%e8%99%9f%e8%88%87%e5%85%a8%e6%8e%92%e5%ba%8f%e7%b7%a8%e8%99%9f-row_number-over-partition-by/" data-wpel-link="internal">Oracle, MySQL 分組編號與全排序編號 row_number, over, partition by</a></li>



<li><a href="https://noter.tw/3929/mysql-error-2003-hy000-%E7%84%A1%E6%B3%95%E9%81%A0%E7%AB%AF%E9%80%A3%E7%B7%9A/" data-wpel-link="internal">MySQL ERROR 2003 (HY000) 無法遠端連線</a></li>



<li><a href="https://noter.tw/2889/jsp-%E9%80%A3%E7%B5%90-mysql/" data-wpel-link="internal">JSP 連結 MySQL</a></li>



<li><a href="https://noter.tw/2883/java-%E9%80%A3%E7%B5%90-mysql/" data-wpel-link="internal">Java 連結 MySQL</a></li>



<li><a href="https://noter.tw/2306/mysql%E6%8E%92%E7%A8%8Bevent-scheduler/" data-wpel-link="internal">MySQL 排程(Event Scheduler)</a></li>



<li><a href="https://noter.tw/1988/java%E9%80%A3%E7%B5%90%E9%81%A0%E7%AB%AFmysql/" data-wpel-link="internal">Java 連結遠端 MySQL</a></li>



<li><a href="https://noter.tw/4508/mariadb-replication-%E8%A8%AD%E5%AE%9A/" data-wpel-link="internal">MariaDB Replication 設定</a></li>



<li><a href="https://noter.tw/122/java-php-%E6%8F%92%E5%85%A5-emoji-%E8%B3%87%E6%96%99%E5%88%B0-mariadb/" data-wpel-link="internal">Java / PHP 插入 emoji 資料到 MariaDB</a></li>
</ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/12503/mariadb-json_extract-%e5%be%9e-json-%e6%ac%84%e4%bd%8d%e5%8f%96%e5%80%bc/" data-wpel-link="internal">MariaDB JSON_EXTRACT: 從 JSON 欄位取值</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/12503/mariadb-json_extract-%e5%be%9e-json-%e6%ac%84%e4%bd%8d%e5%8f%96%e5%80%bc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
