Oracle 创建表为 select with count max 条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5817177/
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
Oracle create table as select with count max condition
提问by ivy
I've got an Oracle problem, here is my select:
我有一个 Oracle 问题,这是我的选择:
create table new_table as
select
idprod as product_id, descr as description
from old_table p where updateNum = (select max(updateNum) from old_table pp where pp.idprod = p.idprod);
this query gives me one generic error with no explanation. SQL Developer say me:
这个查询给了我一个没有解释的通用错误。SQL 开发人员说我:
"Error starting at line 7 in command: [...] Error report:
SQL Command: create table
Failed: Warning: execution completed with warning"
“在命令中从第 7 行开始出错:[...] 错误报告:
SQL 命令:创建表
失败:警告:执行已完成并出现警告”
but create the table and the data inside seems to be correct.
但是创建表和里面的数据似乎是正确的。
Some hints?
一些提示?
回答by user1134616
Oracle issues the "Failed: Warning: execution completed with warning" in a CREATE TABLE statement whenever you use a function on a column with NULLs. This often happens when you use a CASE WHEN or DECODE and don't use a default to take care of the NULLs (e.g., ELSE 0). This is also the solution to the same problem stated on https://forums.oracle.com/forums/thread.jspa?threadID=723332.
每当您在具有 NULL 的列上使用函数时,Oracle 都会在 CREATE TABLE 语句中发出“失败:警告:执行完成并带有警告”。当您使用 CASE WHEN 或 DECODE 并且不使用默认值来处理 NULL(例如 ELSE 0)时,通常会发生这种情况。这也是https://forums.oracle.com/forums/thread.jspa?threadID=723332上所述相同问题的解决方案。
To avoid problems: make sure you don't use a function (e.g., max, sum) on a column with NULLs in a CREATE TABLE AS.
为避免出现问题:确保您不在 CREATE TABLE AS 中对具有 NULL 的列使用函数(例如,max、sum)。
回答by Danilo Piazzalunga
Older versions of SQL Developer have a bug which makes them issue a similar warning after a CREATE TABLE
: see this OTN Forums post.
旧版本的 SQL Developer 有一个错误,这使得它们在发出类似警告后发出类似警告CREATE TABLE
:请参阅此 OTN 论坛帖子。
Since the table is created and populated with the correct data, the CREATE TABLE
statement is correct. If you want to be sure, try executing the statement from SQL*Plus.
由于该表是用正确的数据创建和填充的,所以该CREATE TABLE
语句是正确的。如果您想确定,请尝试从 SQL*Plus 执行语句。