{"id":447,"date":"2019-02-21T11:56:23","date_gmt":"2019-02-21T02:56:23","guid":{"rendered":"http:\/\/localhost:8000\/?p=447"},"modified":"2021-01-23T11:56:57","modified_gmt":"2021-01-23T02:56:57","slug":"oracle-tips","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/02\/oracle-tips.html","title":{"rendered":"Oracle\u306eTips"},"content":{"rendered":"

Oracle\u95a2\u4fc2\u306e\u30e1\u30e2\u3002<\/p>\n

\u518d\u8d77SQL\u3067\u30c7\u30fc\u30bf\u8907\u88fd<\/h2>\n
-- hoge\u30c6\u30fc\u30d6\u30eb\u306eid = 1\u30921000\u4ef6\u307e\u3067\u8907\u88fd\u3059\u308bSQL\ninsert into hoge (\nselect * from (\n  with hoge_cal (id, name) as (\n    select\n      id, name\n    from\n      hoge\n    where\n      id = 1 -- \u8907\u88fd\u5143\u3092\u6307\u5b9a\n    union all\n    select\n      id + 1\n      , name || id + 1\n    from\n      hoge_cal\n    where\n      id <= 1000 -- 1000\u4ef6\u307e\u3067\n  )\n  select\n    id, name\n  from\n    hoge_cal\n  where\n    id <>  1 -- \u8907\u88fd\u5143\u306f\u9664\u304f\n));<\/code><\/pre>\n

explain plan<\/h2>\n
# sqlplus\u5185\u3067\u4ee5\u4e0b\u3092\u5b9f\u884c\u3059\u308b\n-- \u307e\u305aplan table\u3092\u4f5c\u6210\u3059\u308b\n@\/apps\/oracle\/product\/10.2.0\/db_1\/rdbms\/admin\/utlxplan.sql\n\n-- explain plan\u3092\u53d6\u5f97\u3059\u308b\nset linesize 300\ntruncate table plan_table;\nexplain plan for select aaa,bbb from ccc where ddd = 'eee';\nselect operation || ' options= ' || options || ' object= '  || object_name || ' position= ' || position || ' cost= ' || cost from plan_table;\n\n-- SQL\u5b9f\u884c\u6642\u9593\u8a08\u6e2c\nset timing on\nselect * from hoge;\nElapsed: 00:00:01.23<\/code><\/pre>\n

kill session<\/h2>\n
# sqlplus\u5185\u3067\u4ee5\u4e0b\u3092\u5b9f\u884c\u3059\u308b\n\n-- sid\u3068serial#\u3092\u53d6\u5f97\nselect sid, serial#, username, program, status from v$session where username = 'hoge';\nID       SERIAL#  USERNAME  STATUS\n1256  45167      hoge              XXXX\n\nalter system kill session '1256,45167' immediate;<\/code><\/pre>\n

\u30c6\u30fc\u30d6\u30eb\u5225\u306e\u5bb9\u91cf\u78ba\u8a8d<\/h2>\n
select\n  at.table_name\n  , trunc(us.bytes\/1024\/1024,0) tablesize_m\n  from\n    all_tables \n    join user_segments us on us.segment_name = at.table_name\n  where\n    owner = 'hoge'\n  order by\n    tablesize_m desc<\/code><\/pre>\n

\u65e2\u5b58\u306e\u30c6\u30fc\u30d6\u30eb\u5c5e\u6027\u3092\u7d99\u627f\u3057\u305f\u307e\u307e\u3001\u540c\u4e00\u8868\u9818\u57df\u4e0a\u306b\u65b0\u3057\u3044\u30bb\u30b0\u30e1\u30f3\u30c8\u3092\u78ba\u4fdd<\/h2>\n