相关链接
Sets column-related information
设置与列相关的信息
This procedure sets column-related information. In the version of this procedure that deals with user-defined statistics, the statistics type specified is the type to store in the dictionary, in addition to the actual user-defined statistics. If this statistics type is NULL, the statistics type associated with the index or column is stored.
此过程设置与列相关的信息。
The DBMS_STATS
package uses the constants shown in Table 142-1:
Table 142-1 DBMS_STATS Constants
Name 名称 |
Type 类型 |
Value 值 |
Description 描述 |
---|---|---|---|
AUTO_CASCADE | BOOLEAN | NULL | Lets Oracle decide whether to collect statistics for indexes or not 让Oracle决定是否收集索引的统计信息 |
AUTO_DEGREE | NUMBER | 32768 | Lets Oracle select the degree of parallelism based on size of the object, number of CPUs and initialization parameters. For definition of default parallel degree, see “Degree of Parallelism” in Oracle Database VLDB and Partitioning Guide. 让Oracle根据对象的大小、cpu的数量和初始化参数选择并行度。有关默认并行度的定义,请参阅Oracle数据库VLDB和分区指南中的"并行度"。 |
AUTO_INVALIDATE | BOOLEAN | NULL | Lets Oracle decide when to invalidate dependent cursors 让Oracle决定何时使依赖游标失效 |
AUTO_SIMPLESIZE | NUMBER | 0 | Indicates that auto-sample size algorithms should be used 表示自动样本大小应该使用的算法 |
参数有default值:可以不传参,使用默认值
参数无default值:必须传参才可调用
DBMS_STATS.SET_COLUMN_STATS (
ownname VARCHAR2,
tabname VARCHAR2,
colname VARCHAR2,
partname VARCHAR2 DEFAULT NULL,
stattab VARCHAR2 DEFAULT NULL,
statid VARCHAR2 DEFAULT NULL,
distcnt NUMBER DEFAULT NULL,
density NUMBER DEFAULT NULL,
nullcnt NUMBER DEFAULT NULL,
srec StatRec DEFAULT NULL,
avgclen NUMBER DEFAULT NULL,
flags NUMBER DEFAULT NULL,
statown VARCHAR2 DEFAULT NULL,
no_invalidate BOOLEAN DEFAULT to_no_invalidate_type(
get_param('NO_INVALIDATE')),
force BOOLEAN DEFAULT FALSE);
or
DBMS_STATS.SET_COLUMN_STATS (
ownname VARCHAR2,
tabname VARCHAR2,
colname VARCHAR2,
partname VARCHAR2 DEFAULT NULL,
stattab VARCHAR2 DEFAULT NULL,
statid VARCHAR2 DEFAULT NULL,
ext_stats RAW,
stattypown VARCHAR2 DEFAULT NULL,
stattypname VARCHAR2 DEFAULT NULL,
statown VARCHAR2 DEFAULT NULL,
no_invalidate BOOLEAN DEFAULT to_no_invalidate_type(
get_param('NO_INVALIDATE')),
force BOOLEAN DEFAULT FALSE);
1.如果是命令窗口就用exec 存储过程名,举个例子:
EXEC procedure;--procedure是存储过程名
2.如果是PL/SQL窗口就用 begin 存储过程名 end; 举个例子:
begin
procedure;--procedure是存储过程名
end;
3.如果是程序中调用就用 call 存储过程名 ,举个例子:
hibernateDao.excuteSqlUpdate("{Call proc_stuInfo()}");//存储过程proc_stuInfo
declare
-- Boolean parameters are translated from/to integers:
-- 0/1/null <--> false/true/null
no_invalidate boolean := sys.diutil.int_to_bool(:no_invalidate);
force boolean := sys.diutil.int_to_bool(:force);
-- Non-scalar parameters require additional processing
srec SYS.DBMS_STATS.STATREC;
begin
-- Call the procedure
sys.dbms_stats.set_column_stats(ownname => :ownname,
tabname => :tabname,
colname => :colname,
partname => :partname,
stattab => :stattab,
statid => :statid,
distcnt => :distcnt,
density => :density,
nullcnt => :nullcnt,
srec => srec,
avgclen => :avgclen,
flags => :flags,
statown => :statown,
no_invalidate => no_invalidate,
force => force);
end;
or
declare
-- Boolean parameters are translated from/to integers:
-- 0/1/null <--> false/true/null
no_invalidate boolean := sys.diutil.int_to_bool(:no_invalidate);
force boolean := sys.diutil.int_to_bool(:force);
begin
-- Call the procedure
sys.dbms_stats.set_column_stats(ownname => :ownname,
tabname => :tabname,
colname => :colname,
partname => :partname,
stattab => :stattab,
statid => :statid,
ext_stats => :ext_stats,
stattypown => :stattypown,
stattypname => :stattypname,
statown => :statown,
no_invalidate => no_invalidate,
force => force);
end;
Table 142-87 SET_COLUMN_STATS Procedure Parameters
Ser 序号 |
Parameter 参数名称 |
Type 类型 |
Default | IO TYPE | Note 参数说明 |
Range 取值范围 |
---|---|---|---|---|---|---|
1 | ownname | VARCHAR2 | IN | name of the schema. 方案名 |
[Any Schema] | |
2 | tabname | VARCHAR2 | IN | Name of the table to which this column belongs. 此列所属的表名 |
[Any Table] | |
3 | colname | VARCHAR2 | IN | Name of the column or extension 列名或扩展名 |
[Any column or extension] | |
4 | partname | VARCHAR2 | Y | IN | Name of the table partition in which to store the statistics. If the table is partitioned and partname is NULL , then the statistics are stored at the global table level.用于存储统计信息的表分区名称。如果表是分区的,且partname=NULL,则统计信息存储在表全局级别(global level)。 |
NULL default [Any table partition] |
5 | stattab | VARCHAR2 | Y | IN | User statistics table identifier describing where to store the statistics. If stattab is NULL , then the statistics are stored directly in the dictionary.存储统计信息的目标表名。 |
NULLdefault 如果指定参数为NULL,统计信息将直接更新到数据字典。 [Any Stattab] 指定要存储统计信息的表。 |
6 | statid | VARCHAR2 | Y | IN | Identifier (optional) to associate with these statistics within stattab (Only pertinent if stattab is not NULL )statid表明stattab这个数据集的主键,可以理解为stattab的一个分区。(只有当stattab不是NULL时设置statid才有效) |
NULLdefault 不指定分区。 [Any Statid] 指定要存储统计信息的表的分区。 |
7 | ext_stats | RAW | IN | User-defined statistics 用户定义的数据 |
NULLdefault | |
8 | stattypown | VARCHAR2 | Y | IN | Schema of the statistics type 统计信息类型的方案(Schema) |
NULLdefault |
9 | stattypname | VARCHAR2 | Y | IN | Name of the statistics type 统计信息类型的名称 |
NULLdefault |
10 | distcnt | NUMBER | Y | IN | Number of distinct values 不同值的个数 |
NULLdefault [Any Number] |
11 | density | NUMBER | Y | IN | Column density. If this value is NULL and if distcnt is not NULL , then density is derived from distcnt 列密度。如果 density=NULL 且 distcnt<>NULL ,那么 density = distcnt 。 |
NULLdefault [Any Number] |
12 | nullcnt | NUMBER | Y | IN | Number of NULLs NULL值的个数 |
NULLdefault [Any Number] |
13 | srec | StatRec | Y | IN | StatRec structure filled in by a call to PREPARE_COLUMN_VALUES or GET_COLUMN_STATS 调用PREPARE_COLUMN_VALUES 或 GETCOLUMN_STATS 来填充StatRec结构 ? |
NULLdefault |
14 | avgclen | NUMBER | Y | IN | Average length for the column (in bytes) 列的平均长度(以字节为单位) |
NULLdefault [Any Number] |
15 | flags | NUMBER | Y | IN | For internal Oracle use (should be left as NULL )?? |
NULLdefault [Any Number] |
16 | statown | VARCHAR2 | Y | IN | Schema containing stattab (if different than ownname )statown表明stattab在哪个方案(schema)下,如果statown=当前schema,则可以不指定此参数。 |
NULLdefault [Any Schema] 指定要存储统计信息的方案。 |
17 | no_invalidate | BOOLEAN | Y | IN | Does not invalidate the dependent cursors if set to TRUE . The procedure invalidates the dependent cursors immediately if set to FALSE . Use DBMS_STATS .AUTO_INVALIDATE . to have Oracle decide when to invalidate dependent cursors. This is the default. The default can be changed using the SET_DATABASE_PREFS Procedure, SET_GLOBAL_PREFS Procedure, SET_SCHEMA_PREFS Procedure and SET_TABLE_PREFS Procedure. |
DBMS_STATS.AUTO_INVALIDATEdefault 默认值(取Oracle常量)。让Oracle决定何时使依赖游标失效。 TRUE 依赖游标有效。 FALSE 依赖游标失效。 |
18 | force | BOOLEAN | Y | IN | Sets the values even if statistics of the column are locked 当这个参数的值为TRUE时,即使锁表也会强制删除表的统计信息。 |
TRUE FALSE default |
Most of the DBMS_STATS procedures include the three parameters statown, stattab, and statid. These parameters allow you to store statistics in your own tables (outside of the dictionary), which does not affect the optimizer. Therefore, you can maintain and experiment with sets of statistics.
大多数DBMS_STATS过程包括三个参数statown、stattab和statid。这些参数允许您将统计信息存储在自己的表中(在字典之外),这不会影响优化器。因此,您可以维护和试验统计数据集。
The stattab parameter specifies the name of a table in which to hold statistics, and it is assumed that it resides in the same schema as the object for which statistics are collected (unless the statown parameter is specified). You can create multiple tables with different stattab identifiers to hold separate sets of statistics.
stattab参数指定用于保存统计信息的表的名称,并且假设它与为其收集统计信息的对象驻留在同一个方案(用户)中(除非指定了statown参数)。您可以使用不同的stattab标识符创建多个表,以保存不同的统计数据集。
The statown, stattab, and statid parameters instruct the package to back up current statistics in the specified table before gathering new statistics.
statown、stattab和statid参数指示包在收集新的统计信息之前备份指定表中的当前统计信息。
ORA-20000
: Object does not exist or insufficient privileges
对象不存在或权限不足
ORA-20001
: Invalid or inconsistent input values
输入值无效或不一致
ORA-20005
: Object statistics are locked
对象统计信息被锁定
To invoke this procedure you must be owner of the table, or you need the ANALYZE
ANY
privilege. For objects owned by SYS
, you need to be either the owner of the table, or you need the ANALYZE
ANY
DICTIONARY
privilege or the SYSDBA
privilege.
调用这个过程,你必须是表的所有者,或 ANALYZE ANY 权限。
对于SYS拥有的对象,你需要是表的所有者,或 ANALYZE ANY DICTIONARY 权限或 SYSDBA 权限。
20/10/30
M