Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于在运行时创建新列的SQL查询_Sql_Oracle - Fatal编程技术网

用于在运行时创建新列的SQL查询

用于在运行时创建新列的SQL查询,sql,oracle,Sql,Oracle,我们有一个小需求,需要比较主表和辅助表。查询将返回结果并包含一个额外的列“STATUS”,它将告诉用户第一个表中的数据是否逐行出现在第二个表中。 我无法计算如何获得所需的结果。您没有向我们展示这两个表的结构,因此我假设(至少)两个表之间有一个公共列,允许您将它们连接起来 select t1.*, t2.*, case when t1.id is null then 'not present in TABLE_1' when t2.id is

我们有一个小需求,需要比较主表和辅助表。查询将返回结果并包含一个额外的列“STATUS”,它将告诉用户第一个表中的数据是否逐行出现在第二个表中。
我无法计算如何获得所需的结果。

您没有向我们展示这两个表的结构,因此我假设(至少)两个表之间有一个公共列,允许您将它们连接起来

select t1.*, t2.*,
       case 
         when t1.id is null then 'not present in TABLE_1'  
         when t2.id is null then 'not present in TABLE_2'
         else 'present in both tables'
       end as status
from table_1 t1 
  full outer join table_2 t2 on t1.some_id = t2.some_id

您需要使用真实的列名,而不是
某些\u id
。这还假设列
some_id
在两个表中的任何一个表中都不包含
NULL

欢迎来到SO。在这里,您可以找到一些关于如何构建一个有助于改进您的question@MaheswaranRavisankar:你说得对,谢谢(我总是忘记甲骨文有这个限制)