OS X版のsdcliを実行するには実行権を付与する必要があります。sdcliは以下のパスにあります。かなり深いところにあります!
(OS X版は以下深いところにあるので、SQLDeveloperのアイコン上で右クリック>コンテクストメニュー>パッケージの内容を表示から辿ってパスを探してもいいですし、以下のパス直接コピペでも行けます。)


discus-mother:˜ oracle$ cd /Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin discus-mother:bin oracle$ chmod +x sdcli discus-mother:bin oracle$ ll total 672 -rw-r--r--@ 1 oracle staff 49279 5 3 02:48 SQLDeveloperIcons.icns -rw-r--r--@ 1 oracle staff 0 5 3 02:48 jdk.conf -rw-r--r--@ 1 oracle staff 440 5 3 02:48 logging-debug.conf -rw-r--r--@ 1 oracle staff 363 5 3 02:48 logging.conf -rwxrwxr-x@ 1 oracle staff 586 5 3 02:50 sdcli -rw-r--r--@ 1 oracle staff 99 5 3 02:50 sdcli-Darwin.conf -rw-r--r--@ 1 oracle staff 446 5 3 02:50 sdcli.boot -rw-r--r--@ 1 oracle staff 854 5 3 02:50 sdcli.conf -rw-r--r--@ 1 oracle staff 71205 5 3 02:48 splash.gif -rw-r--r--@ 1 oracle staff 71205 5 3 02:48 splash.png -r-xr-xr-x@ 1 oracle staff 3220 5 3 02:48 sqldeveloper -rw-r--r--@ 1 oracle staff 415 5 3 02:48 sqldeveloper-Darwin.conf -rw-r--r--@ 1 oracle staff 661 5 3 02:48 sqldeveloper-debug.conf -rw-r--r--@ 1 oracle staff 204 5 3 02:48 sqldeveloper-nondebug.conf -rw-r--r--@ 1 oracle staff 445 5 3 02:48 sqldeveloper.bat -rw-r--r--@ 1 oracle staff 340 5 3 02:48 sqldeveloper.boot -rw-r--r--@ 1 oracle staff 1175 5 3 02:48 sqldeveloper.conf -rw-r--r--@ 1 oracle staff 83456 5 3 02:48 sqldeveloper64W.exe -rw-r--r--@ 1 oracle staff 131 5 3 02:54 version.properties discus-mother:bin oracle$
|
パスは通っていないので設定する必要があります。
discus-mother:˜ oracle$ cat .bashrc alias ll='ls -lv'
#for SQLDeveloper sdcli export PATH=$PATH:/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin
discus-mother:˜ oracle$
|
Version 4.0.1では以下の状況でExceptionが発生していましたが、Version 4.0.2では解決してます!!!
discus-mother:˜ oracle$ sdcli
Oracle SQL Developer Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
使用可能な機能: cart: データベース・カート・バッチ・タスク dba: 基本バッチDBAタスク format: SQL Format Task migration: Database Migration Tasks reports: 基本バッチ・レポート・タスク unittest: ユニット・テスト・バッチ・タスク discus-mother:˜ oracle$
|
ということで、
前から試したかった SQL文の整形機能。 GUIだとSQLワークシートでSQL文整形機能が提供されているためデータベースへ接続必要だったんですよね。
機能としては素敵だったのですが、データベース接続が行えない環境では使えない機能だったんですよ。
そんな環境で読むに耐えない巨大で未整形なSQL文を渡され涙目だった日々を思い出しますw
コマンドラインならデータベース接続不要なのがいいっす!
discus-mother:˜ oracle$ sdcli format
Oracle SQL Developer Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
format input=<入力ファイルまたはディレクトリ> output=<出力ファイルまたはディレクトリ> 成功しました。 discus-mother:˜ oracle$
|
以下のようなSQL文を整形してみます。
discus-mother:˜ oracle$ cat sample_unformated.sql select a.id,a.name,b.location,b.phone_no from foo a innter join bar b on a.id = b.id order by a.name;
|
意外と地味な感じの処理終了メッセージですが、整形できたようです。整形結果を確認!
discus-mother:˜ oracle$ sdcli format input=sample_unformated.sql output=sample_formated.sql
Oracle SQL Developer Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
成功しました。 discus-mother:˜ oracle$
|
いいですね〜 :) 最後の改行がないのですは、ご愛嬌ということで.
discus-mother:˜ oracle$ cat sample_formated.sql SELECT a.id, a.name, b.location, b.phone_no FROM foo a innter JOIN bar b ON a.id = b.id ORDER BY a.name;discus-mother:˜ oracle$ discus-mother:˜ oracle$
|
では、超便利な一括整形のテスト。 以下のような未整形なSQLファイルを含むディレクトリと整形後SQLファイルを格納するディレクトリを用意して....
discus-mother:˜ oracle$ mkdir unformated_sqls discus-mother:˜ oracle$ mkdir formated_sqls discus-mother:˜ oracle$ dir=unformated_sqls; for fname in `ls $dir`; do echo -e \\n\\nfile : $fname; cat $dir/$fname; done;
file : sample1.sql select a.id,a.name,b.location,b.phone_no from foo a innter join bar b on a.id = b.id order by a.name;
file : sample2.sql select a.id,a.name,b.location,b.phone_no from foo a innter join bar b on a.id = b.id order by a.name;
|
一括整形の場合はディレクトリ名のみ指定すればOK!
おおおおおおおおお〜〜〜〜、できた〜〜〜〜SQL文の一括整形!!! 素敵!!
discus-mother:˜ oracle$ sdcli format input=unformated_sqls output=formated_sqls
Oracle SQL Developer Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
成功しました。
|
かくに〜〜〜〜〜ん!!
discus-mother:˜ oracle$ dir=formated_sqls; for fname in `ls $dir`; do echo -e \\n\\nfile : $fname; cat $dir/$fname; done;
file : sample1.sql SELECT a.id, a.name, b.location, b.phone_no FROM foo a innter JOIN bar b ON a.id = b.id ORDER BY a.name;
file : sample2.sql SELECT a.id, a.name, b.location, b.phone_no FROM foo a innter JOIN bar b ON a.id = b.id ORDER BY a.name;
|
Good job!!!!! SQL Developer Team!
最近のコメント