search
HomeDatabaseMysql TutorialOralce中的synonym同义词

设定同义词,方便使用select * from emp;等用于select * from abc;建立共有的同义词如果用户的等级不够建立public同义词,可以在

设定同义词,方便使用
select * from emp;等用于select * from abc;
建立共有的同义词
如果用户的等级不够建立public同义词,可以在system下授权:
grant create any synonym to scott;
grant create public synonym to scott;
取消授权:
revoke create any synoym from scott;
revoke create public synoym from scott;
取消同义词:
drop public synonym abc;
授权取消同义词:
grant dorp public synonym to scott;
取消授权:
revoke drop public synonym to scott;
15.9 引入同义词(Synonym)的原因
在一些商业数据库中,有时信息系统的设计或开发者为了增加易读性,故意定义一些很长的表名(也可能是其它的对象)。这样虽然增加了易读性,但在引用这些表 或对象时就不那么方便,也容易产生输入错误。另外在实际的商业公司里,一些用户觉得某一个对象名有意义也很好记,但另一些用户可能觉得另一个名字更有意 义。
Oracle系统提供的同义词(Synonym)就是用来解决以上的难题的。设想一下在您的日常工作中您每天都要使用supplier表许多次,而且您的英文打字的水平并不高。在这种情形下,您就可以借助于同义词(Synonym)来帮助您提高生产力。
15.10 怎样创建同义词(Synonym)
现在您就可以使用如下的CREATE SYNONYM语句(例15-38)为表supplier建了一个同义词(别名)s。
例15-38
SQL> CREATE SYNONYM s
2 FOR supplier;
例15-38结果
同义词已创建。
现在您就可以把同义词(别名)s当成supplier来使用。您可以使用如下的查寻语句(例15-39)来验证这一点。
例15-39
SQL> SELECT *
2 FROM s;
例15-39结果
S_CODE SNAME CONTACT PHONE FAX
---------- ------------------------- --------------- --------------- -------
2000 仙客来百货 张根发 4444944 4444844
2010 心太软小商品 石铁心 1741741 1741742
2021 食为天餐具 金元宝 1671671 1671674
2032 食为先餐具 陆合彩 1681684 1681684
那您可能会问,您怎样才能知道您到底拥有哪些同义词(Synonym)呢?
还记得数据字典user_objects吗?既然同义词(Synonym)是对象,,它们在这个数据字典中就一定有记载。因此您可以使用如下的查寻语句(例 15-41)从数据字典user_objects中得到您所拥有的全部同义词(Synonym)的信息。当然为了使SQL*PLUS的显示输出更加清晰您 应该先使用如下的SQL*PLUS格式化命令(例15-40)。
例15-40
SQL> col object_name for a20
例15-41
SQL> SELECT object_name, object_type, created, status
2 FROM user_objects
3 WHERE object_type LIKE 'SYN%';
例15-41结果
OBJECT_NAME OBJECT_TYPE CREATED STATUS
-------------------- ------------------ ---------- ------
S SYNONYM 28-4月 -03 VALID
例15-41显示的结果表明:在您的模式(用户)下只有一个同义词(Synonym),那就是您刚刚建立的同义词(Synonym)s。
但是例15-41显示的结果并没有告诉您这个同义词(Synonym)到底是基于那个表的及表的主人是谁。如果您有一个这样同义词(Synonym)时, 这方面的信息也许就显得特别重要了。您可以使用如下的查寻语句(例15-43)从数据字典user_synonyms中得到这方面的信息。当然为了使 SQL*PLUS的显示输出更加清晰您应该先使用如下的SQL*PLUS格式化命令
(例15-42)。
例15-42
SQL> col table_owner for a12
SQL> col table_name for a12
例15-43
SQL> SELECT synonym_name, table_owner, table_name
2 FROM user_synonyms;
例15-43结果
SYNONYM_NAME TABLE_OWNER TABLE_NAME
------------------------------ ------------ ----------
S SCOTT SUPPLIER
例15-43显示的结果表明:在您的模式(用户)下只有一个同义词(Synonym),那就是您刚刚建立的同义词(Synonym)s。该同义词(Synonym)是基于表supplier,而这个表的主人是SCOTT。
创建同义词(Synonym)的语句格式如下:
CREATE [PUBLIC] SYNONYM 同义词的名字
FOR 对象名;
其中:
PUBLIC: 系统中所有的用户都可以访问所创建的同义词
同义词的名字: 所创建的同义词的名字
对象名: 创建的同义词所基于的对象名
在创建同义词时要注意的事项:
所基于的对象不能包含在任何软件包中
一个私有的同义词不能与任何该用户下的其它对象重名
您刚刚创建的同义词(Synonym)s是一个私有的同义词,即只能在您的用户(SCOTT)下直接引用,如果其它用户引用它就必需冠以用户名.(既 scott.s的方式引用)。这样作很不方便。如果您所建的表supplier是一个所有用户共享并经常使用的表,您应该怎样处理这一问题呢?
15.11 创建公用同义词(Synonym)
您可以为supplier表创建一个公用同义词(Synonym)。为了演示方便,您应该从当前的SCOTT用户切换到另一个用户下,如SYSTEM。您可以使用如下的SQL*PLUS命令(例15-44)来完成用户的切换。
例15-44
SQL> CONNECT SYSTEM/MANAGER

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor