use database name in oracle like in sybase

Unlike mysql or SQLServer, Oracle does not have a "use database" command that allows you to switch your default schema to something other than your own.

Why would you want to do this? Well, in oracle each database user is assigned a schema with the same name as the name of the database user.

So, if user Ralph creates a table called Food and user Chuck creates a table called Food, the database will store the tables names as Ralph.Food and Chuck.Food. If Ralph logs in and wants to select from his Food table he simply types:

connect ralph/password
SELECT *
FROM   food;

If Ralph needs to see what is in Chuck's Food table he could access that table by using the fully qualified name of that table "Chuck.Food":

connect ralph/password
SELECT *
FROM   chuck.food;

Now if Ralph was using MySQL or MSSQL he could just type "use chuck" and then "select * from food" to see the data in the chuck food table. Oracle doesn't have a "use" command that allows this type of functionality, but there is a way to accomplish this using an "alter session" command.

So, if Ralph would like to access the chuck tables without using the fully qualified names for his tables he could use the following commands:

connect ralph/password
ALTER SESSION SET CURRENT_SCHEMA = chuck;
SELECT *
FROM   food;

Cool! So, it's not quite as elegant as a command like "use chuck" but it does accomplish the same task. Very handy for developers and DBA's used to this type of functionality from other databases.

Note: quotes are not needed around the schema name, if a schema has special characters or spaces, you can enclose the schema name in double quotes.

转载于:https://www.cnblogs.com/peng-fei/p/3520034.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值