<?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>查詢結果 &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/%E6%9F%A5%E8%A9%A2%E7%B5%90%E6%9E%9C/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Fri, 21 Apr 2023 06:07:24 +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>查詢結果 &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>使用 Oracle sqlplus 將查詢結果匯出到檔案</title>
		<link>https://noter.tw/9109/oracle-sqlplus-export-results-to-file/</link>
					<comments>https://noter.tw/9109/oracle-sqlplus-export-results-to-file/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Wed, 11 Aug 2021 11:54:28 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技術相關]]></category>
		<category><![CDATA[資料庫]]></category>
		<category><![CDATA[另存檔案]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[spool]]></category>
		<category><![CDATA[sqlplus]]></category>
		<category><![CDATA[匯出搜尋結果]]></category>
		<category><![CDATA[匯出檔案]]></category>
		<category><![CDATA[查詢結果]]></category>
		<category><![CDATA[colsep]]></category>
		<category><![CDATA[linesize]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=9109</guid>

					<description><![CDATA[<p>小蛙又遇到不能用 GUI 來管理 Oracle 的專案了，其實跟 2012 年的時候遇到的這個是相同的專案（Oracle 使用 sqlplus 匯入 SQL 檔案），該篇記錄了怎麼把一堆要執行的 SQ&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/9109/oracle-sqlplus-export-results-to-file/" data-wpel-link="internal">使用 Oracle sqlplus 將查詢結果匯出到檔案</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>小蛙又遇到不能用 GUI 來管理 Oracle 的專案了，其實跟 2012 年的時候遇到的這個是相同的專案（<a href="https://noter.tw/2371/oracle-sqlplus-import-sql-file/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">Oracle 使用 sqlplus 匯入 SQL 檔案</a>），該篇記錄了怎麼把一堆要執行的 SQL 指令存入檔案中，並於 Oracle sqlplus 載入檔案執行，這篇文章為反向動作，將查詢的結果輸出到檔案內。</p>



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



<p>這個專案的環境很麻煩，在一個需要透過 VPN 連進去的內部環境，連上 VPN 之後就 &#8230; 斷網了，完全沒辦法對外，沒辦法 Google 查資料，對小蛙這種不專精的半調子來說存在一定難度，幸好有強大的同仁用 VM 的特殊大絕解決這問題，不過 VM 裡面連上 VPN 還是不能上網，但總算可以在本機 Google 資料，再手動把指令或語法手動輸入進去，對，沒錯，沒辦法複製貼上 Orz &#8230;</p>



<p>囉嗦一堆，進正題</p>



<pre class="wp-block-preformatted withcode">set colsep ,
set headsep off
set pagesize 0
set linesize 10000
set trimspool on
set echo off

spool /home/hans/output

select * from image;

spool off</pre>



<p class="withcode">上面那些指令是參考 <a href="https://stackoverflow.com/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">StackOverflow<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 多個答案來的，有些實際上在做什麼小蛙也不是很了解，但還是可以猜出大概是什麼，例如：<code>colset</code> 是設定欄位間的分隔符號(其他詳細設定請自行 Google)。小蛙遇到有問題的地方是 <code>linesize</code> 沒有設定，導致匯出的每一行都被切斷在莫名其妙的地方。其他 <code>spool 輸出檔案路徑</code>、<code>select * from image;</code> 要匯出結果的查詢 &#8230; 等等。</p>



<p>這指令已符合小蛙的需求，先備存，之後有其他需求再去查詳細的資料。以下是小蛙自己留存用的</p>



<pre class="wp-block-preformatted withcode">// 相當於 mysql show tables;
select table_name from user_tables;

// 查找排序過的前 10 筆 (Top 10)
select rownum, t.* from ( 實際要運作的 SQL ) t where rownum &lt; 10;

// 列出表格的所有欄位
select * from user_tab_columns A where A.table_name = 'IMAGE';
// 列出名稱、類型及長度
select column_name, data_type, default_length from user_tab_columns A where A.table_name = 'IMAGE';

// 複製 table 內所有資料
create table image_backup as select * from image;

// 表格建立的時間
select object_name, created, TIMESTAMP from user_objects where object_name = 'IMAGE';

// 修改表格
alter table IMAGE modify (file_name varchar2(300), index_term varchar2(1000));

// 格式變動完成
commit;</pre>



<p><strong>Oracle 系列文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/11178/%e4%bf%ae%e6%94%b9-oracle-sequence/" data-wpel-link="internal">修改 Oracle Sequence</a><a href="https://noter.tw/2371/oracle-%e5%8c%af%e5%85%a5-sql-%e6%aa%94%e6%a1%88/" data-wpel-link="internal"></a></li><li><a href="https://noter.tw/2371/oracle-sqlplus-import-sql-file/" data-wpel-link="internal">Oracle 使用 sqlplus 匯入 SQL 檔案</a></li><li><a href="https://noter.tw/9109/oracle-sqlplus-export-results-to-file/" data-wpel-link="internal">使用 Oracle sqlplus 將查詢結果匯出到檔案</a></li><li><a href="https://noter.tw/2714/%e5%ae%98%e6%96%b9-client-oracle-sql-developer-%e5%ae%89%e8%a3%9d%e6%95%99%e5%ad%b8/" data-wpel-link="internal">官方 Client – Oracle SQL Developer 安裝教學</a></li><li><a href="https://noter.tw/2711/oracle-%e5%8c%af%e5%85%a5%e5%8c%af%e5%87%ba-excel-%e9%80%8f%e9%81%8e-sql-developer/" data-wpel-link="internal">Oracle 匯入/匯出 Excel (透過 SQL Developer)</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/9109/oracle-sqlplus-export-results-to-file/" data-wpel-link="internal">使用 Oracle sqlplus 將查詢結果匯出到檔案</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/9109/oracle-sqlplus-export-results-to-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
