有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在oracle中定义表上的默认where子句

有些查询的where子句具有相同的部分

问题一:

select [some-selected column] 
  from [TABLE_NAME]
 where [its-own-where-clause]
   and [shared-where-clause]

问题二:

select [some-selected column] 
  from [TABLE_NAME]
 where [its-own-where-clause]
   and [shared-where-clause]

问题三:

select [some-selected column] 
  from [TABLE_NAME]
 where [its-own-where-clause]
   and [shared-where-clause]


.
.
.

查询n:

select [some-selected column] 
  from [TABLE_NAME]
 where [its-own-where-clause]
   and [shared-where-clause]

正如您所看到的,where子句中有两部分,第一部分属于它自己的查询业务,第二部分在所有这些查询之间共享
显然,当[shared-where-clause]发生更改时,必须更改上述所有查询

我想把where子句的shared部分放在其中,它的更改应用于所有这些查询

在甲骨文中可能吗


共 (1) 个答案

  1. # 1 楼答案

    创建一个视图

    例如:

    create table PERSON (
        PERSON_ID    number(10, 0)  not null primary key,
        PERSON_NAME  nvarchar(100)  not null,
        AGE          number(3, 0)   not null,
        GENDER       char(1)        not null check(GENDER in ('M', 'F'))
    );
    
    create view MALES as
    select PERSON_ID, PERSON_NAME, AGE, GENDER
      from PERSON
     where GENDER = 'M';
    
    create view FEMALES as
    select PERSON_ID, PERSON_NAME, AGE, GENDER
      from PERSON
     where GENDER = 'F';
    

    现在我们可以查询不同年龄组的男性,而无需重复GENDER上的共享条件

    select *
      from MALES
     where AGE between 0 and 19;
    
    select *
      from MALES
     where AGE between 20 and 49;
    
    select *
      from MALES
     where AGE >= 50;