How to work with database objects

本文介绍了数据库的基本操作,包括创建用户、授予权限、建立表格、添加字段、创建索引及序列等关键步骤。

A statement that creates a new user for a database

 

CREATE USER ap IDENTIFIED BY ap;

 

 

A statement that grants privileges to a user

 

GRANT ALL PRIVILEGES TO ap;

 

 

A statement that creates a new table

 

CREATE TABLE invoices
(
	invoice_id            NUMBER, 
	vendor_id             NUMBER          NOT NULL,
	invoice_number        VARCHAR2(50)    NOT NULL,
	invoice_date          DATE            NOT NULL,
	invoice_total         NUMBER(9,2)     NOT NULL,
	payment_total         NUMBER(9,2)                 DEFAULT 0,
	credit_total          NUMBER(9,2)                 DEFAULT 0,
	terms_id              NUMBER          NOT NULL,
	invoice_due_date      DATE            NOT NULL,
	payment_date          DATE,
	CONSTRAINT invoices_pk 
		PRIMARY KEY (invoice_id),
	CONSTRAINT invoices_fk_vendors
		FOREIGN KEY (vendor_id) 
		REFERENCES vendors (vendor_id),
	CONSTRAINT invoices_fk_terms
		FOREIGN KEY (terms_id) 
		REFERENCES terms (terms_id)
);

 

A statement that adds a new column to a table

 

ALTER TABLE invoices
ADD balance_due NUMBER(9,2);

 

A statement that deletes the new column

 

ALTER TABLE invoices
DROP COLUMN balance_due;

 

 

A statement that creates an index on the table

 

CREATE INDEX invoices_vendor_id_index
ON invoices(vendor_id);

 

A statement that deletes the new index

 

DROP INDEX invoices_vendor_id_index;

 

A statement that creates a sequence for generating invoice_id values

 

CREATE SEQUENCE invoice_id_seq START WITH 115 INCREMENT BY 1;
<think>Hmm, the user is reporting that the "dba_objects" table doesn't exist in their Oracle database. That's a common issue, especially for less experienced DBAs. First, I need to consider who this user might be. They're probably a junior DBA or developer working with Oracle, possibly struggling with permissions. The phrasing "表不存在" (table doesn't exist) suggests they might be executing SQL directly and getting errors. The core issue here is almost certainly about privileges, not the table's actual existence. DBA_OBJECTS is a fundamental data dictionary view that always exists in Oracle. The real problem is likely that: - The user lacks SELECT_CATALOG_ROLE - Or hasn't been granted direct SELECT on DBA_OBJECTS - Or is connecting with a basic user account I should explain this clearly but gently - no need to make them feel bad about missing privilege concepts. The solution path is straightforward: verify privileges first, then request elevation if needed. For the follow-up questions, I'll focus on natural next steps: - How to check privileges (crucial for self-sufficiency) - Alternative views they CAN access (practical workaround) - Grant syntax (for when they get DBA help) - Permission differences between DBA/ALL/USER_ views (core concept) The tone should be helpful but precise - they're likely frustrated seeing "table not exist" errors when googling shows DBA_OBJECTS as standard. I'll emphasize this is normal permission design, not a system error. </think>关于 Oracle 中 `DBA_OBJECTS` 表不存在的错误,以下是关键解释和解决方案: ### 原因分析 1. **权限问题**(最常见原因): - `DBA_OBJECTS` 是数据字典视图,需要 **SELECT_CATALOG_ROLE** 权限或显式的 `SELECT ANY DICTIONARY` 权限 - 普通用户默认无权限访问,需 DBA 授权: ```sql GRANT SELECT ON dba_objects TO your_username; ``` 2. **连接身份错误**: - 必须以 **SYSDBA** 或具有 DBA 权限的用户登录: ```sql CONNECT sys/password@db_alias AS SYSDBA ``` 3. **视图名称错误**: - 确认拼写:`DBA_OBJECTS`(Oracle 数据字典视图均为大写) - 尝试查询同义词: ```sql SELECT * FROM dict WHERE table_name LIKE '%OBJECTS%'; ``` ### 权限验证步骤 1. 检查当前用户权限: ```sql SELECT * FROM session_privs; ``` 2. 若返回无结果,需切换用户: ```sql CONNECT / AS SYSDBA; SELECT COUNT(*) FROM dba_objects; -- 验证访问能力 ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值