oracle SQL 插入语句 - 缺少 select 关键字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26148382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL insert statement - missing select keyword
提问by Adrian
I am very very new to SQL language, and trying to execute the following code. It gives me an error message below.. What did I do wrong?
我对 SQL 语言非常陌生,并尝试执行以下代码。它给了我下面的错误消息..我做错了什么?
Error Message:
错误信息:
ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
Code:
代码:
WITH ABC(one,two,three)
AS(
select 25, 15,23 from dual
)
INSERT INTO ABC(one, two, three) VALUES (10,11,12)
select * from ABC;
Thank you very much in advance!
非常感谢您提前!
EDIT-- Explanation
I need to create table with more than 100 rows. I am not allowed to create new table due to sufficient privilege, so I am trying to create virtual table. The idea on my head is inserting rows to the virtual table with For-loop. But this 'missing select keyword' error occurs when I try to insert any record...
编辑——说明
我需要创建超过 100 行的表。由于足够的权限,我不允许创建新表,因此我正在尝试创建虚拟表。我的想法是使用 For 循环将行插入到虚拟表中。但是,当我尝试插入任何记录时,会发生此“缺少选择关键字”错误...
EDIT-- Regarding the word "very very new to SQL language"
I am currently a computer engineering student in University, and studied 'Database' course last year. Now, I am doing an internship. So like.. I am not like a beginner who needs w3school tutorial, but I am new to 'SQL language for real life'
编辑——关于“SQL 语言非常新”这个词,
我目前是大学计算机工程专业的学生,去年学习了“数据库”课程。现在,我正在实习。所以就像..我不像需要 w3school 教程的初学者,但我是“现实生活中的 SQL 语言”的新手
采纳答案by a_horse_with_no_name
You need another "table" that returns the number of rows you want. In Oracle this is usually done using an undocumented feature of the connect by
operator:
您需要另一个“表”来返回您想要的行数。在 Oracle 中,这通常是使用connect by
操作符的一个未记录的特性来完成的:
select level as rn
from dual
connect by level <= 100
The "undocumented" part is the fact that no real "connect" is done and no start with
is supplied. Look up the connect by
in the manual for more details on this.
“未记录”部分是这样一个事实,即没有完成真正的“连接”,也没有start with
提供。中查找connect by
手册中关于这个的更多细节。
will return 100 rows. You can combine this with your initial CTE and do a cross join to return the single row a hundred times:
将返回 100 行。您可以将其与初始 CTE 结合起来,并进行交叉连接以返回单行一百次:
WITH abc (one,two,three) AS (
select 25, 15,23 from dual
), num_rows as (
select level as rn
from dual
connect by level <= 100
)
select abc.*
from abc
cross join num_rows;
回答by Aramillo
Why don't you try with union all
like this:
你为什么不试试union all
这样:
WITH ABC(one,two,three)
AS(
select 25, 15,23 from dual union all
select 10,11,12 from dual
)
select * from ABC
回答by SubqueryCrunch
This will create a table
这将创建一个表
SELECT (21)as a,(22)as b,(23)as c
INTO #Test
SELECT * FROM #Test
This will create a table as well.
这也将创建一个表。
SELECT *
INTO #TestTable
FROM dual
Assuming that dual is a valid table in your database.
假设 dual 是数据库中的有效表。