Oracle的数据字典技术简析
正在看的ORACLE教程是:Oracle的数据字典技术简析。数据字典是Oracle存放有关数据库信息的地方,其用途是用来描述数据的。比如一个表的创建者信息,创建时间信息,所属表空间信息,用户访问权限信息等。当用户在对数据库中的数据进行操作时遇到困难就可以访问数据字典来查看详细的信息。
Oracle中的数据字典有静态和动态之分。静态数据字典主要是在用户访问数据字典时不会发生改变的,但动态数据字典是依赖数据库运行的性能的,反映数据库运行的一些内在信息,所以在访问这类数据字典时往往不是一成不变的。以下分别就这两类数据字典来论述。
1. 静态数据字典
这类数据字典主要是由表和视图组成,应该注意的是,数据字典中的表是不能直接被访问的,但是可以访问数据字典中的视图。静态数据字典中的视图分为三类,它们分别由三个前缀够成:user_*、 all_*、 dba_*。
user_*
该视图存储了关于当前用户所拥有的对象的信息。(即所有在该用户模式下的对象)
all_*
该试图存储了当前用户能够访问的对象的信息。(与user_*相比,all_* 并不需要拥有该对象,只需要具有访问该对象的权限即可)
dba_*
该视图存储了数据库中所有对象的信息。(前提是当前用户具有访问这些数据库的权限,一般来说必须具有管理员权限)
从上面的描述可以看出,三者之间存储的数据肯定会有重叠,其实它们除了访问范围的不同以外(因为权限不一样,所以访问对象的范围不一样),其他均具有一致性。具体来说,由于数据字典视图是由SYS(系统用户)所拥有的,所以在却省情况下,只有SYS和拥有DBA系统权限的用户可以看到所有的视图。没有DBA权限的用户只能看到user_*和all_*视。如果没有被授予相关的SELECT权限的话,他们是不能看到 dba_*视图的。
由于三者具有相似性,下面以user_为例介绍几个常用的静态视图:
user_users视图
主要描述当前用户的信息,主要包括当前用户名、帐户id、帐户状态、表空间名、创建时间等。例如执行下列命令即可返回这些信息。
select * from user_users
user_tables视图
主要描述当前用户拥有的所有表的信息,主要包括表名、表空间名、簇名等。通过此视图可以清楚了解当前用户可以操作的表有哪些。执行命令为:select * from user_tables
user_objects视图
主要描述当前用户拥有的所有对象的信息,对象包括表、视图、存储过程、触发器、包、索引、序列等。该视图比user_tables视图更加全面。例如, 需要获取一个名为“package1”的对象类型和其状态的信息,可以执行下面命令:
这里需注意upper的使用,数据字典里的所有对象均为大写形式,而PL/SQL里不是大小写敏感的,所以在实际操作中一定要注意大小写匹配。
user_tab_privs视图
该视图主要是存储当前用户下对所有表的权限信息。比如,为了了解当前用户对table1的权限信息,可以执行如下命令:
了解了当前用户对该表的权限之后就可以清楚的知道,哪些操作可以执行,哪些操作不能执行。
前面的视图均为user_开头的,其实all_开头的也完全是一样的,只是列出来的信息是当前用户可以访问的对象而不是当前用户拥有的对象。对于dba_开头的需要管理员权限,其他用法也完全一样,这里就不再赘述了。
[NextPage]
2. 动态数据字典
Oracle包含了一些潜在的由系统管理员如SYS维护的表和视图,由于当数据库运行的时候它们会不断进行更新,所以称它们为动态数据字典(或者是动态性能视图)。这些视图提供了关于内存和磁盘的运行情况,所以我们只能对其进行只读访问而不能修改它们。
Oracle中这些动态性能视图都是以v$开头的视图,比如v$access。下面就几个主要的动态性能视图进行介绍。
v$access
该视图显示数据库中锁定的数据库对象以及访问这些对象的会话对象(session对象)。
运行如下命令:
结果如下:(因记录较多,故这里只是节选了部分记录)
v$session
该视图列出当前会话的详细信息。由于该视图字段较多,这里就不列详细字段,为了解详细信息,可以直接在sql*plus命令行下键入:desc v$session即可。
v$active_instance
该视图主要描述当前数据库下的活动的实例的信息。依然可以使用select语句来观察该信息。
v$context
该视图列出当前会话的属性信息。比如命名空间、属性值等。
3.小结
以上是Oracle的数据字典方面的基本内容,还有很多有用视图因为篇幅原因这里不能一一讲解,希望大家在平时使用中多留心。总之,运用好数据字典技术,可以让数据库开发人员能够更好的了解数据库的全貌,这样对于数据库优化、管理等有极大的帮助。
上一页

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

There are four main index types in MySQL: B-Tree index, hash index, full-text index and spatial index. 1.B-Tree index is suitable for range query, sorting and grouping, and is suitable for creation on the name column of the employees table. 2. Hash index is suitable for equivalent queries and is suitable for creation on the id column of the hash_table table of the MEMORY storage engine. 3. Full text index is used for text search, suitable for creation on the content column of the articles table. 4. Spatial index is used for geospatial query, suitable for creation on geom columns of locations table.

TocreateanindexinMySQL,usetheCREATEINDEXstatement.1)Forasinglecolumn,use"CREATEINDEXidx_lastnameONemployees(lastname);"2)Foracompositeindex,use"CREATEINDEXidx_nameONemployees(lastname,firstname);"3)Forauniqueindex,use"CREATEU

The main difference between MySQL and SQLite is the design concept and usage scenarios: 1. MySQL is suitable for large applications and enterprise-level solutions, supporting high performance and high concurrency; 2. SQLite is suitable for mobile applications and desktop software, lightweight and easy to embed.

Indexes in MySQL are an ordered structure of one or more columns in a database table, used to speed up data retrieval. 1) Indexes improve query speed by reducing the amount of scanned data. 2) B-Tree index uses a balanced tree structure, which is suitable for range query and sorting. 3) Use CREATEINDEX statements to create indexes, such as CREATEINDEXidx_customer_idONorders(customer_id). 4) Composite indexes can optimize multi-column queries, such as CREATEINDEXidx_customer_orderONorders(customer_id,order_date). 5) Use EXPLAIN to analyze query plans and avoid

Using transactions in MySQL ensures data consistency. 1) Start the transaction through STARTTRANSACTION, and then execute SQL operations and submit it with COMMIT or ROLLBACK. 2) Use SAVEPOINT to set a save point to allow partial rollback. 3) Performance optimization suggestions include shortening transaction time, avoiding large-scale queries and using isolation levels reasonably.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)
