select * from user_all_tables sample(10) --这个不好用
--但是,可但是,但可是,可是
select * from user_all_tables --这个好用
select * from test sample(10) --这个好用为什么呢???select * from user_all_tables sample(10) 为什么不好用呢??
--但是,可但是,但可是,可是
select * from user_all_tables --这个好用
select * from test sample(10) --这个好用为什么呢???select * from user_all_tables sample(10) 为什么不好用呢??
Error:
ORA-01446: cannot select ROWID from view with DISTINCT, GROUP BY, etc.Cause:
You tried to create a view that included a ROWID in the SELECT statement as well as a clause such as DISTINCT or GROUP BY. This is not allowed.Action:
The options to resolve this Oracle error are: 1. Since the DISTINCT or GROUP BY causes the records in the view to not correspond directly to the underlying physical records, the ROWID values can not be returned. Either remove the DISTINCT or GROUP BY clause, OR Remove the ROWID column from the the SELECT statement.
----------
10
20OPER@tl>select * from test2; AAA
----------
10
20OPER@tl>create view v_t1 as select * from test;视图已创建。OPER@tl>select * from v_t1 sample(50); AAA
----------
10
20OPER@tl>create view v_t2 as select * from test union select * from test2;视图已创建。OPER@tl>select * from v_t2 sample(50);
select * from v_t2 sample(50)
*
第 1 行出现错误:
ORA-01446: 无法使用 DISTINCT, GROUP BY 等子句从视图中选择 ROWID 或采样
OPER@tl>
-------------------------------------------------------------------------------- CREATE OR REPLACE FORCE VIEW "SYS"."USER_ALL_TABLES" ("TABLE_NAME", "TABLESPACE_NAME", "CLUSTER_NA
TATUS", "PCT_FREE", "PCT_USED", "INI_TRANS", "MAX_TRANS", "INITIAL_EXTENT", "NEX
T_EXTENT", "MIN_EXTENTS", "MAX_EXTENTS", "PCT_INCREASE", "FREELISTS", "FREELIST_
GROUPS", "LOGGING", "BACKED_UP", "NUM_ROWS", "BLOCKS", "EMPTY_BLOCKS", "AVG_SPAC
E", "CHAIN_CNT", "AVG_ROW_LEN", "AVG_SPACE_FREELIST_BLOCKS", "NUM_FREELIST_BLOCK
S", "DEGREE", "INSTANCES", "CACHE", "TABLE_LOCK", "SAMPLE_SIZE", "LAST_ANALYZED"
, "PARTITIONED", "IOT_TYPE", "OBJECT_ID_TYPE", "TABLE_TYPE_OWNER", "TABLE_TYPE",
"TEMPORARY", "SECONDARY", "NESTED", "BUFFER_POOL", "ROW_MOVEMENT", "GLOBAL_STAT
S", "USER_STATS", "DURATION", "SKIP_CORRUPT", "MONITORING", "CLUSTER_OWNER", "DE
PENDENCIES", "COMPRESSION", "DROPPED") AS
select TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS,
PCT_FREE, PCT_USED,
INI_TRANS, MAX_TRANS,
INITIAL_EXTENT, NEXT_EXTENT,
MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,
FREELISTS, FREELIST_GROUPS, LOGGING,
BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,
AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,
AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,
DEGREE, INSTANCES, CACHE, TABLE_LOCK,
SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,
IOT_TYPE,
NULL, NULL, NULL, TEMPORARY, SECONDARY, NESTED,
BUFFER_POOL, ROW_MOVEMENT,
GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,
CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED
from user_tables
union all
select TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS,
PCT_FREE, PCT_USED,
INI_TRANS, MAX_TRANS,
INITIAL_EXTENT, NEXT_EXTENT,
MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,
FREELISTS, FREELIST_GROUPS, LOGGING,
BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,
AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,
AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,
DEGREE, INSTANCES, CACHE, TABLE_LOCK,
SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,
IOT_TYPE, OBJECT_ID_TYPE,
TABLE_TYPE_OWNER, TABLE_TYPE, TEMPORARY, SECONDARY, NESTED,
BUFFER_POOL, ROW_MOVEMENT,
GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,
CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED
from user_object_tablesOPER@tl>
可以看到,在user_all_tables这个视图中用到了union all,所以也不能用sample()