如何在sqlplus(Oracle)中完成CREATE TYPE的输入?
我正在尝试在终端中输入 CREATE TYPE,但我不知道如何完成它。这是我的具体查询:
CREATE TYPE testtype AS OBJECT (
id int
);
/
然后它拒绝执行任何操作,而是等待更多输入。我可以毫无障碍地输入几乎所有其他查询类型。到底是怎么回事?我需要执行一些最终步骤才能完成它吗?
I'm trying to input a CREATE TYPE in my terminal, what I can't figure out how to finish it. Here is my specific query:
CREATE TYPE testtype AS OBJECT (
id int
);
/
It then refuses to perform any operation, but instead sits waiting for more input. I can input just about every other query type without a hitch. What is going on? Is there some finalizing step I need to do to make it finish?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您说它“而是等待更多输入”时,您的意思是 SQL*Plus 正在要求另一行输入,还是数据库显然没有响应?
换句话说,您是否得到了这样的信息:(
5
表明 SQL*Plus 认为还有更多内容即将到来),或者您是否得到了类似的信息:(在它运行了几秒钟后我中断了它没有成功完成。)
对于这个答案的其余部分,我将假设后者。老实说,我无法相信 SQL*Plus 无法识别您输入的结尾。单独一行上的单个
/
(即使其一侧或两侧有空格)被解释为输入的明确结束,即使输入不是有效的 SQL。请注意,如果您使用的是 bash 等 shell,即使您正在运行的程序当前没有请求用户输入,您也可以输入文本。例如:
在本例中,
hello
和is 有人吗?
行被 SQL*Plus 忽略,因为当我输入它们时它正忙。(它可能会选择稍后读入它们 - 它们将可以从标准输入中读取 - 但在本例中它选择不这样做。)为了让
create type
语句运行几秒钟而不是完成,我创建了以下(适当命名的)触发器:如果您尝试创建名为“TESTTYPE”的对象,则此触发器会导致无限循环。
我并不是说您的数据库中有一个像这个一样愚蠢的触发器,但您可能想查看一下以下任何
BEFORE CREATE
或AFTER CREATE
触发器你的数据库。另一种可能性可能是 AFTER SERVERERROR ON DATABASE 触发器。也许您的
create type
语句触发了错误,并导致这些触发器之一触发。您的数据库中有这些吗?看似挂起的会话通常是由锁定引起的。如果另一个用户对您尝试更新的行或表有锁定,您的会话将阻塞,直到他们释放锁定。但很难看出什么可能会单独阻止
create type
语句,这就是我建议使用触发器的原因。您还可以尝试阅读这篇有关 Oracle 中的锁定和阻塞的文章。我不敢相信问题是由于类型已经存在或者您没有创建类型的权限造成的。在这两种情况下,您都应该立即收到错误消息。
When you say that it 'instead sits waiting for more input', do you mean that SQL*Plus is asking for another line of input, or that the database apparently isn't responding?
In other words, are you getting this:
(the
5
indicating that SQL*Plus thinks there's more to come), or are you getting something like this:(I interrupted this after it ran for a few seconds without successfully completing.)
For the rest of this answer, I'll assume the latter. I can't honestly believe that SQL*Plus would fail to recognise the end of your input. A single
/
on a line on its own (even with spaces on either or both sides of it) is interpreted as a definite end of input, even if the input isn't valid SQL.Note that if you're using a shell such as bash, you can type in text even if the program you're running isn't currently requesting user input. For example:
In this case, the lines
hello
andis anybody there?
were ignored by SQL*Plus since it was busy when I typed them in. (It may choose to later read them in - they will be available to read from its standard input - but in this case it chose not to.)To get the
create type
statement to run for a few seconds and not complete, I created the following (appropriately-named) trigger:This trigger causes an infinite loop if you attempt to create an object called 'TESTTYPE'.
I'm not saying that you have a trigger that's as stupid as this in your database, but you may want to take a look at any
BEFORE CREATE
orAFTER CREATE
triggers in your database.Another possibility may be an
AFTER SERVERERROR ON DATABASE
trigger. Perhaps yourcreate type
statement is triggering an error, and causing one of these triggers to fire. Are there any of these in your database?A session that appears to hang is usually caused by locking. If another user has a lock on a row or a table that you're trying to update, your session will block until they release their lock. But it's difficult to see what could be blocking a
create type
statement on its own, which is why I suggested triggers. You can also try reading this article on locking and blocking in Oracle.I can't believe the problem is due to the type already existing or you not having permission to create a type. In both cases you should get an error straight away.
一定有什么事情你没有告诉我们:
There must be something you are not telling us:
当表上有未完成的事务(因此有锁)时,A 会看到这样和那样的行为。
sqlplus 命令行将愉快地开始执行,然后永远等待。
解决方案:提交/回滚并关闭其他会话
A saw a behaviour like this and that when there were open transactions (and hence locks) on a table.
The sqlplus commandline will happily start executing and then wait forever.
Solution: commit/rollback and close other sessions