スキップしてメイン コンテンツに移動

会心の一撃的SQL


とある特定のスキーマのテーブルのレコード数をカウントするには…
調べるとXMLなんちゃらを使うといいみたいです。

これを知るまでは、SQLで一旦スクリプトを作って対象テーブルに
select count(*)
見たいなSQLを流した結果を手で編集してたのですが、このSQLを使用すると一発で出力できます。


select
owner, table_name,
to_number(
extractvalue(
xmltype(dbms_xmlgen.getxml('select count(*) c from ' || owner || '.' || table_name))
,'/ROWSET/ROW/C')) "count"
from all_tables
where owner in ('hoge','fufu')
order by owner, table_name;

コメント

このブログの人気の投稿

MySQL NotifierがHigh Severity Errorを出して立ち上がらない…

先日、わしのPCがコンセントが抜けかけが原因で落ちて以来、MySQLのNotifierがエラーを出して立ち上がらなくなった… 1週間放置しておいたが、毎日エラーダイアログが表示されるのも目障りなので、対処してみた。 結果、 %APPDATA%\Oracle\MySQL Notifier にある settings.config が壊れていることが判り、削除し解決した。 なんでこんなものが壊れたのかは不明…

Sun Fire V120のディスクの消去

Sunの撤去が決まったので、ディスクの消去のために色々調べてた結果です ■USB光学ドライブからBoot出来るかの資料 Can I boot from a USB disk or USB CD/DVD drive? Generally speaking, booting from USB disk, CD/DVD drive is supported on x86 platforms with S10 update 1 and later if the BIOS has USB 2.0 support. Sparc systems with USB 2.0 support can boot from USB disks if the OBP(Open Boot Prom) is upgraded to version 4.27 or later. Before you can boot Solaris from USB disk, you have to install Solaris on the disk first. Installing on USB memory sticks is not recommended as the number of writes to these sticks is limited. Problems observed on some hardware platforms: -Installation from USB CD/DVD drive starts, but then fails with "not finding media" error. This is because the CD/DVD drive is not mounted under the /cdrom directory as the installation process expects. Possible workaround is to re-plug in the CD/DVD drive, and make sure the device is in the device tree and the /dev/dsk/ link is correctly created, and mount i...