[20131217]pivot應用例子.txt
[20131217]pivot應用例子.txt
PIVOT是11G的新特性,可以把列轉換為行,自己寫一個例子:
SCOTT@test> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SCOTT@test> select name from V$SEGSTAT_NAME order by statistic#;
SCOTT@test> select statistic#,name from V$SEGSTAT_NAME order by statistic#;
STATISTIC# NAME
---------- ------------------------------
0 logical reads
1 buffer busy waits
2 gc buffer busy
3 db block changes
4 physical reads
5 physical writes
6 physical read requests
7 physical write requests
8 physical reads direct
9 physical writes direct
11 optimized physical reads
12 gc cr blocks received
13 gc current blocks received
14 ITL waits
15 row lock waits
17 space used
18 space allocated
20 segment scans
18 rows selected.
--10g
STATISTIC# NAME
---------- ------------------------------
0 logical reads
1 buffer busy waits
2 gc buffer busy
3 db block changes
4 physical reads
5 physical writes
6 physical reads direct
7 physical writes direct
9 gc cr blocks received
10 gc current blocks received
11 ITL waits
12 row lock waits
14 space used
15 space allocated
17 segment scans
15 rows selected.
WITH pivot_stats
AS (SELECT owner,
object_name,
statistic_name,
VALUE
FROM v$segment_statistics)
SELECT *
FROM pivot_stats PIVOT (SUM (VALUE)
FOR statistic_name
IN (select name from V$SEGSTAT_NAME order by statistic#)
--這樣寫不行.
ERROR at line 10:
ORA-00936: missing expression
--11G
WITH pivot_stats
AS (SELECT owner,
object_name,
statistic_name,
VALUE
FROM v$segment_statistics)
SELECT *
FROM pivot_stats PIVOT (SUM (VALUE)
FOR statistic_name
IN ('logical reads',
'buffer busy waits',
'gc buffer busy',
'db block changes',
'physical reads',
'physical writes',
'physical read requests',
'physical write requests',
'physical reads direct',
'physical writes direct',
'optimized physical reads',
'gc cr blocks received',
'gc current blocks received',
'ITL waits',
'row lock waits',
'space used',
'space allocated',
'segment scans'))
--適當的選擇排序,可以定位那個object_name存在問題.
--如果使用10g寫法就比較複雜了.
SELECT owner,
object_name,
MAX (DECODE (statistic_name, 'logical reads', VALUE, 0)) "logical reads",
MAX (DECODE (statistic_name, 'buffer busy waits', VALUE, 0)) "buffer busy waits",
MAX (DECODE (statistic_name, 'gc buffer busy', VALUE, 0)) "gc buffer busy",
MAX (DECODE (statistic_name, 'db block changes', VALUE, 0)) "db block changes",
MAX (DECODE (statistic_name, 'physical reads', VALUE, 0)) "physical reads",
MAX (DECODE (statistic_name, 'physical writes', VALUE, 0)) "physical writes",
MAX (DECODE (statistic_name, 'physical read requests', VALUE, 0)) "physical read requests",
MAX (DECODE (statistic_name, 'physical write requests', VALUE, 0)) "physical write requests",
MAX (DECODE (statistic_name, 'physical reads direct', VALUE, 0)) "physical reads direct",
MAX (DECODE (statistic_name, 'physical writes direct', VALUE, 0)) "physical writes direct",
MAX (DECODE (statistic_name, 'optimized physical reads', VALUE, 0)) "optimized physical reads",
MAX (DECODE (statistic_name, 'gc cr blocks received', VALUE, 0)) "gc cr blocks received",
MAX (DECODE (statistic_name, 'gc current blocks received', VALUE, 0)) "gc current blocks received",
MAX (DECODE (statistic_name, 'ITL waits', VALUE, 0)) "ITL waits",
MAX (DECODE (statistic_name, 'row lock waits', VALUE, 0)) "row lock waits",
MAX (DECODE (statistic_name, 'space used', VALUE, 0)) "space used",
MAX (DECODE (statistic_name, 'space allocated', VALUE, 0)) "space allocated",
MAX (DECODE (statistic_name, 'segment scans', VALUE, 0)) "segment scans"
FROM v$segment_statistics
GROUP BY owner, object_name
PIVOT是11G的新特性,可以把列轉換為行,自己寫一個例子:
SCOTT@test> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SCOTT@test> select name from V$SEGSTAT_NAME order by statistic#;
SCOTT@test> select statistic#,name from V$SEGSTAT_NAME order by statistic#;
STATISTIC# NAME
---------- ------------------------------
0 logical reads
1 buffer busy waits
2 gc buffer busy
3 db block changes
4 physical reads
5 physical writes
6 physical read requests
7 physical write requests
8 physical reads direct
9 physical writes direct
11 optimized physical reads
12 gc cr blocks received
13 gc current blocks received
14 ITL waits
15 row lock waits
17 space used
18 space allocated
20 segment scans
18 rows selected.
--10g
STATISTIC# NAME
---------- ------------------------------
0 logical reads
1 buffer busy waits
2 gc buffer busy
3 db block changes
4 physical reads
5 physical writes
6 physical reads direct
7 physical writes direct
9 gc cr blocks received
10 gc current blocks received
11 ITL waits
12 row lock waits
14 space used
15 space allocated
17 segment scans
15 rows selected.
WITH pivot_stats
AS (SELECT owner,
object_name,
statistic_name,
VALUE
FROM v$segment_statistics)
SELECT *
FROM pivot_stats PIVOT (SUM (VALUE)
FOR statistic_name
IN (select name from V$SEGSTAT_NAME order by statistic#)
--這樣寫不行.
ERROR at line 10:
ORA-00936: missing expression
--11G
WITH pivot_stats
AS (SELECT owner,
object_name,
statistic_name,
VALUE
FROM v$segment_statistics)
SELECT *
FROM pivot_stats PIVOT (SUM (VALUE)
FOR statistic_name
IN ('logical reads',
'buffer busy waits',
'gc buffer busy',
'db block changes',
'physical reads',
'physical writes',
'physical read requests',
'physical write requests',
'physical reads direct',
'physical writes direct',
'optimized physical reads',
'gc cr blocks received',
'gc current blocks received',
'ITL waits',
'row lock waits',
'space used',
'space allocated',
'segment scans'))
--適當的選擇排序,可以定位那個object_name存在問題.
--如果使用10g寫法就比較複雜了.
SELECT owner,
object_name,
MAX (DECODE (statistic_name, 'logical reads', VALUE, 0)) "logical reads",
MAX (DECODE (statistic_name, 'buffer busy waits', VALUE, 0)) "buffer busy waits",
MAX (DECODE (statistic_name, 'gc buffer busy', VALUE, 0)) "gc buffer busy",
MAX (DECODE (statistic_name, 'db block changes', VALUE, 0)) "db block changes",
MAX (DECODE (statistic_name, 'physical reads', VALUE, 0)) "physical reads",
MAX (DECODE (statistic_name, 'physical writes', VALUE, 0)) "physical writes",
MAX (DECODE (statistic_name, 'physical read requests', VALUE, 0)) "physical read requests",
MAX (DECODE (statistic_name, 'physical write requests', VALUE, 0)) "physical write requests",
MAX (DECODE (statistic_name, 'physical reads direct', VALUE, 0)) "physical reads direct",
MAX (DECODE (statistic_name, 'physical writes direct', VALUE, 0)) "physical writes direct",
MAX (DECODE (statistic_name, 'optimized physical reads', VALUE, 0)) "optimized physical reads",
MAX (DECODE (statistic_name, 'gc cr blocks received', VALUE, 0)) "gc cr blocks received",
MAX (DECODE (statistic_name, 'gc current blocks received', VALUE, 0)) "gc current blocks received",
MAX (DECODE (statistic_name, 'ITL waits', VALUE, 0)) "ITL waits",
MAX (DECODE (statistic_name, 'row lock waits', VALUE, 0)) "row lock waits",
MAX (DECODE (statistic_name, 'space used', VALUE, 0)) "space used",
MAX (DECODE (statistic_name, 'space allocated', VALUE, 0)) "space allocated",
MAX (DECODE (statistic_name, 'segment scans', VALUE, 0)) "segment scans"
FROM v$segment_statistics
GROUP BY owner, object_name
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1063539/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20190312]bash IFS例子.txt
- [20200208]awk學習例子.txt
- Shell指令碼應用兩個例子指令碼
- [20231226]vim Align外掛使用例子.txt
- Laravel pivot 新增 loadLaravel
- [20020226]iptables PREROUTING POSTROUTING 應用測試.txt
- [20181219]不能使用USE_CONCAT優化例子.txt優化
- [20201209]模擬ora-04031的測試例子.txt
- [LeetCode] 724. Find Pivot IndexLeetCodeIndex
- Python非同步IO程式設計之-asyncio協程應用例子Python非同步程式設計
- Angular Ngrx Store 應用程式狀態的一些典型例子Angular
- Oracle中pivot函式詳解Oracle函式
- 面向切片程式設計(AOP)應用的一些實際例子程式設計
- Angular @Inject 註解的實際應用例子和工作原理淺析Angular
- [20190211]rac下解鎖應用出現的阻塞.txt
- SQL 行轉列 PIVOT 學習示例SQL
- 使用 ViroReact 開發增強實現應用的一個具體例子React
- Oracle行列轉換及pivot子句的用法Oracle
- Spark實現行列轉換pivot和unpivotSpark
- java呼叫window本地應用程式;讀取TXT型別檔案Java型別
- 透視表pivot_table和交叉表crosstabROS
- 用一個通俗的例子講清楚APIAPI
- 採用管道進行通訊的例子
- 一個實際的例子學習 SAP BTP Java 應用的 @Before 註解使用方式Java
- sql的行轉列(PIVOT)與列轉行(UNPIVOT)SQL
- 用一個實際例子理解Dockervolume工作原理Docker
- 用個通俗的例子講一講死鎖
- 【python小例子】小例子拾憶Python
- (三、四)Superset 1.3圖表篇——透視表-Pivot Table
- android中activity可以響應外部的action的例子(可以Android
- 用一個實際例子理解Docker volume工作原理Docker
- [譯] 用個實在例子來教你掌握 Async/AwaitAI
- awk例子
- 4.5.1.1.2 例子
- [20230225]12c Real-time materialized view 實時物化檢視的應用.txtZedView
- 例子:物件建構函式指定型別傳入引數(描述符與裝飾器的應用)物件函式型別
- [20210423]dump sga映像的對應塊.txt
- 用Pandoc生成TXT格式的目錄
- [20230307]如何知道啟用IMU.txt