尝试使用select和join将记录插入表中

时间:2012-07-17 18:19:20

标签: sql oracle

我目前正在写一个插入语句,它给了我“ORA-00923:来自关键字未找到预期的位置。有什么办法可以实现这个目标吗?谢谢。以下是声明:

Insert into seda_owner.seda_lookup(table_name,description,sequence,value)
Select 'DEFAULT_CATE_CHG_ITEMS_DOCS','Software Requirements Specification', '1', 
  (select **value** from seda_owner.seda_document a 
   join seda_owner.seda_lookup b 
    on b.value = a.guid and description = 'Software Requirements Specification');

我尝试做的是将3个字符串table_name,description和sequence以及一个变量值传递给表seda_lookup。

2 个答案:

答案 0 :(得分:1)

在Oracle中,select语句总是需要from tableName。您查询的外部选择没有这样的from子句。

Insert into seda_owner.seda_lookup(table_name,description,sequence,value)
Select 'DEFAULT_CATE_CHG_ITEMS_DOCS','Software Requirements Specification', '1', 
  (select **value** from seda_owner.seda_document a 
   inner join seda_owner.seda_lookup b 
    on b.value = a.guid and description = 'Software Requirements Specification')
from dual;

更好:

Insert into seda_owner.seda_lookup(table_name,description,sequence,value)
Select 'DEFAULT_CATE_CHG_ITEMS_DOCS','Software Requirements Specification', 
    '1', **value** 
from seda_owner.seda_document a 
inner join seda_owner.seda_lookup b 
    on b.value = a.guid and description = 'Software Requirements Specification'

第一个解决方案需要通过子查询返回一行且只返回一行。

第二个解决方案将插入由内连接定义的多个记录。

答案 1 :(得分:0)

  1. 围绕的星号是否是代码的一部分?或者你只是想大胆那个词?
  2. 也许您的嵌套选择返回多行
  3. 仅在b中?您没有在选择中对其进行限定,但您确实在加入条件(b.value)中对其进行了限定