zoukankan      html  css  js  c++  java
  • exists的用法

    -- Create table
    create table CUSTOMERS
    (
      CID    NUMBER not null,
      CNAME  VARCHAR2(50) not null
    )
    tablespace USERS
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );

    alter table CUSTOMERS
      add constraint CUSTOMERS_PK primary key (CID)
      using index
      tablespace USERS

    -- Create sequence
    create sequence SEQ_CUSTOMERS
    minvalue 1
    maxvalue 999999
    start with 1
    increment by 1
    cache 20;


    select * from customers;
    insert into customers values(seq_customers.nextval,'张三');
    insert into customers values(seq_customers.nextval,'李四');
    insert into customers values(seq_customers.nextval,'王五');


    --------------------------------------------------------------------------
    -- Create table
    create table ORDERS
    (
      OID   NUMBER not null,
      ONAME VARCHAR2(50) not null,
      CID   NUMBER
    )
    tablespace USERS
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );
    -- Create/Recreate primary, unique and foreign key constraints
    alter table ORDERS
      add constraint ORDERS_PK primary key (OID)
      using index
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );

    -- Create sequence
    create sequence SEQ_ORDERS
    minvalue 1
    maxvalue 999999
    start with 1
    increment by 1
    cache 20;

    insert into orders values(seq_orders.nextval,'订单1','1');
    insert into orders values(seq_orders.nextval,'订单2','2');
    insert into orders values(seq_orders.nextval,'订单3','2');

    ---------------------------------------------------------------------
    /* 查询图书的标题,这些图书是有出版商的,换句话 查询的是 有出版商的图书 的图书标题*/

    1.使用exists 关键字

    select title from books where exists (select 1 from publishers where pub_id = books.pub_id);

    2. 使用in

    select * from books where pub_id in (select pub_id from publishers);


    ----------------------------------------------------------------------

    not exists 和exists

    /*  查询没有出版过书的 出版商的名称 */
    select name from publishers where not exists ( select 1 from books where pub_id = publishers.pub_id)

    查询 这些 出版商的名称                          是在图书表中没有对应的记录            这些出版商的id
    /*  查询有出版过书的 出版商的名称 */
    select name from publishers where exists ( select 1 from books where pub_id = publishers.pub_id)

  • 相关阅读:
    C++ 虚函数在基类与派生类对象间的表现及其分析
    借@阿里巴巴 耍了个帅——HTML5 JavaScript实现图片文字识别与提取
    Dede(织梦) CMS SQL Injection Vulnerability
    dedecms v5.5 final getwebshell exploit(datalistcp.class.php)
    DEDECMS网站管理系统Get Shell漏洞
    织梦(Dedecms)select_soft_post.php页面变量未初始漏洞
    织梦(Dedecms) 5.1 feedback_js.php 注入漏洞
    织梦(DEDE)CMS V5.3 覆盖任意变量导致远程包含漏洞
    dedecms织梦 v5.5 两处跨站漏洞
    dedecms织梦 v5.6 两处跨站漏洞
  • 原文地址:https://www.cnblogs.com/qylbg/p/3119565.html
Copyright © 2011-2022 走看看