繁体   English   中英

具有函数调用返回值的Oracle select语句。 但是,当使用相同的查询插入表时,函数列显示为空

[英]Oracle select statement with a function call return value. But when doing insert to a table with same query, function column shows null

(查询可能没有任何意义,因为我已对其进行了简化并更改了所有列/表名)

SELECT some_id,
  (SELECT another_id
  FROM another_id_table
  WHERE some_filter2    = pkg_another.get_another_id(some_id,'X')
  ) AS another_id
FROM some_id_table;

上面的查询返回another_id列的值。

如果我尝试在下面的插入语句中使用与上面相同的查询,则another_id在id_table中变为null。

INSERT INTO id_table
SELECT some_id,
  (SELECT another_id
  FROM another_id_table
  WHERE some_filter2    = pkg_another.get_another_id(some_id,'X')
  ) AS another_id
FROM some_id_table;

一些注意事项:

我总是在开始插入语句之前截断id_table。 id_table的数据类型与我试图将another_id查询移动到视图的select语句中的数据类型相同,没有区别。

有人知道为什么我可以查询结果但不能为another_id列插入结果吗?

真奇怪

有时,当多个表中存在列并且您在不使用限定符的情况下使用它们时,Oracle会感到困惑。 (而不是报告歧义,Oracle有时使用其中一列。)

所以也许有助于添加限定词; 特别是对于get_another_id get_another_id(some_id,'X')中的get_another_id(some_id,'X') 如果我想,如果some_id属于some_id_table,那将是get_another_id(some_id_table.some_id,'X')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM