$ sqlite3 ~/demo.db -- 於Home下執行SQLite、建立DB sqlite> create table employee ...> (emp_no, ...> emp_name, ...> dept_no, ...> mgr_no, ...> salary, ...> job); sqlite> .tables employee sqlite> .schema employee -- 查詢table架構 CREATE TABLE employee (emp_no, emp_name, dept_no, mgr_no, salary, job); sqlite> .help sqlite> .exit
2013年5月16日 星期四
SQLite
於OSX 10.8.3打開終端機即可開始使用SQLite
2013年5月10日 星期五
Note about OSX
環境: 2013 MBPR 15" - OS X 10.8.3 (Mountain Lion)
SSH遠端連線
找套件(pkg)
更改截圖類型、預設名稱及存放路徑
啟動 Apache Web Server, 啟動後在瀏覽器輸入http://localhost可看到"It Works!"字樣
SSH遠端連線
$ ssh user@hostname
找套件(pkg)
$ pkgutil --pkgs | grep pkg_name
更改截圖類型、預設名稱及存放路徑
$ defaults write com.apple.screencapture type jpg # jpg $ defaults write com.apple.screencapture type png # png $ defaults write com.apple.screencapture name "Snapshot" # 預設檔名含中文,改為英文 $ defaults write com.apple.screencapture location Full_Path # 存放路徑 $ killall SystemUIServer #清除系統設定暫存
啟動 Apache Web Server, 啟動後在瀏覽器輸入http://localhost可看到"It Works!"字樣
$sudo apachectl start $sudo apachectl stop.
2013年5月9日 星期四
2013年4月29日 星期一
Oracle SQL Developer
由於在OS X 10.8.3下語言設為繁體中文
安裝Oracle SQL Developer 3.2.2後介面就以中文顯示
要改回英文介面的方式如下
於SQL Developer下找出sqldeveloper.conf文件
/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin
自用快速切換中英文
a.中英文用的config各存一份放在HOME下
檔名:sqldeveloperen.conf, sqldeveloperzh.conf
b.建立切換英文介面執行檔:sqldeven.command
註:升級至 OSX Mavericks 10.9 後,需以下步驟以正常執行 Oracle SQL Developer(https://community.oracle.com/message/11246638)
安裝Oracle SQL Developer 3.2.2後介面就以中文顯示
要改回英文介面的方式如下
於SQL Developer下找出sqldeveloper.conf文件
/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin
自用快速切換中英文
a.中英文用的config各存一份放在HOME下
檔名:sqldeveloperen.conf, sqldeveloperzh.conf
b.建立切換英文介面執行檔:sqldeven.command
cp ~/sqldeveloperen.conf /Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sqldeveloper.confc.建立切換中文介面執行檔:sqldevzh.command
cp ~/sqldeveloperzh.conf /Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sqldeveloper.confd.打開終端機更改檔案權限
chmod 744 ~/sqldeven.command chmod 744 ~/sqldevzh.commande.雙擊sqldeven.command及sqldevzh.command即可切換中英介面
註:升級至 OSX Mavericks 10.9 後,需以下步驟以正常執行 Oracle SQL Developer(https://community.oracle.com/message/11246638)
$ cd ~/.sqldeveloper $ vi jdk -- 新增檔案"jdk"檔案內容只需一行字
/usr存檔離開後即可
2013年1月25日 星期五
2012年9月19日 星期三
SQL 輸出 UTF8 的 csv 檔
檔案開頭寫入 nchr(to_number('EFBBBF','XXXXXX')) + 第一行字串
因 Excel 以檔案開頭為 EFBBBF 來判斷是否為 utf8 文件
如直接寫入第一行字串則會以 Big5 文件來開啟 csv 檔而變成亂碼
特別要注意的是如果檔案是要餵給其他系統
則必須要考慮前三個 Byte 是否為 EFBBBF 而排除
因 Excel 以檔案開頭為 EFBBBF 來判斷是否為 utf8 文件
如直接寫入第一行字串則會以 Big5 文件來開啟 csv 檔而變成亂碼
特別要注意的是如果檔案是要餵給其他系統
則必須要考慮前三個 Byte 是否為 EFBBBF 而排除
2012年8月25日 星期六
Array insert table
DECLARE
-----------------------------------------------------------------------------
-- NAME: Array Insert Table
-- NOTE: 1. Declare
-- 1.1 .Declare array for cursor
-- 1.2. Declare array for insert table
-- 1.3. Declare record for keep initial value
-- 2. Begin
-- 2.1. open cursor
-- 2.2. default value
-- 2.3. array loop
-- 2.4. insert table
-----------------------------------------------------------------------------
cursor c_cursor is
select 1 rec_id,
'ABC' rec_value
from dual;
TYPE cursor_rec_type IS TABLE OF c_cursor%rowtype INDEX BY PLS_INTEGER;
cursor_rec_temp cursor_rec_type;
TYPE rec_type IS TABLE OF table_name%rowtype INDEX BY PLS_INTEGER;
rec_temp rec_type;
rec_dummy table_name%rowtype;
ii number := 1 ;
BEGIN
-----------------------------------------------------------------------------
-- 2.1. open cursor
-----------------------------------------------------------------------------
open c_cursor;
fetch c_cursor bulk collect into cursor_rec_temp;
close c_cursor;
-----------------------------------------------------------------------------
-- 2.2. default value
-----------------------------------------------------------------------------
rec_dummy.created_by := 'User';
rec_dummy.creation_date := sysdate;
-----------------------------------------------------------------------------
-- 2.3. array loop
-----------------------------------------------------------------------------
for i in 1 .. cursor_rec_temp.count loop
-- initial record value
rec_temp(ii) := rec_dummy;
rec_temp(ii).rec_value := cursor_rec_temp(i).rec_value;
-- validate SQL
begin
null;
end;
-- add count or delete record
if validate success then
ii := ii + 1 ;
else
rec_temp.delete(ii); -- delete record when validate fail
end if;
end loop;
-----------------------------------------------------------------------------
-- 2.4. insert table
-----------------------------------------------------------------------------
forall p in 1 .. rec_temp.count
insert into table_name values rec_temp(p);
EXCEPTION
when others then
rollback;
END;
/
-----------------------------------------------------------------------------
-- NAME: Array Insert Table
-- NOTE: 1. Declare
-- 1.1 .Declare array for cursor
-- 1.2. Declare array for insert table
-- 1.3. Declare record for keep initial value
-- 2. Begin
-- 2.1. open cursor
-- 2.2. default value
-- 2.3. array loop
-- 2.4. insert table
-----------------------------------------------------------------------------
cursor c_cursor is
select 1 rec_id,
'ABC' rec_value
from dual;
TYPE cursor_rec_type IS TABLE OF c_cursor%rowtype INDEX BY PLS_INTEGER;
cursor_rec_temp cursor_rec_type;
TYPE rec_type IS TABLE OF table_name%rowtype INDEX BY PLS_INTEGER;
rec_temp rec_type;
rec_dummy table_name%rowtype;
ii number := 1 ;
BEGIN
-----------------------------------------------------------------------------
-- 2.1. open cursor
-----------------------------------------------------------------------------
open c_cursor;
fetch c_cursor bulk collect into cursor_rec_temp;
close c_cursor;
-----------------------------------------------------------------------------
-- 2.2. default value
-----------------------------------------------------------------------------
rec_dummy.created_by := 'User';
rec_dummy.creation_date := sysdate;
-----------------------------------------------------------------------------
-- 2.3. array loop
-----------------------------------------------------------------------------
for i in 1 .. cursor_rec_temp.count loop
-- initial record value
rec_temp(ii) := rec_dummy;
rec_temp(ii).rec_value := cursor_rec_temp(i).rec_value;
-- validate SQL
begin
null;
end;
-- add count or delete record
if validate success then
ii := ii + 1 ;
else
rec_temp.delete(ii); -- delete record when validate fail
end if;
end loop;
-----------------------------------------------------------------------------
-- 2.4. insert table
-----------------------------------------------------------------------------
forall p in 1 .. rec_temp.count
insert into table_name values rec_temp(p);
EXCEPTION
when others then
rollback;
END;
/
訂閱:
文章 (Atom)


