oracle使用using關鍵字,oracleusing關鍵字

來源:互聯網
上載者:User

oracle使用using關鍵字,oracleusing關鍵字
oracle使用using關鍵字
sql/92標準可以使用using關鍵字來簡化串連查詢,但是只是在查詢滿足下面兩個條件時,才能使

用using關鍵字進行簡化。
1.查詢必須是等值串連。
2.等值串連中的列必須具有相同的名稱和資料類型。
例如:使用using關鍵字,如下:
select emptno,ename,sal,deptno,dname from emp e inner join dept d using(deptno);
SQL> select e.empno,e.ename,e.sal,deptno,d.dname from
  2  emp e inner join dept d using(deptno);


     EMPNO ENAME             SAL     DEPTNO DNAME
---------- ---------- ---------- ---------- --------------
      7369 SMITH             800         20 RESEARCH
      7499 ALLEN            1600         30 SALES
      7521 WARD             1250         30 SALES
      7566 JONES            2975         20 RESEARCH
      7654 MARTIN           1250         30 SALES
      7698 BLAKE            2850         30 SALES
      7782 CLARK            2450         10 ACCOUNTING
      7788 SCOTT            3000         20 RESEARCH
      7839 KING             5000         10 ACCOUNTING
      7844 TURNER           1500         30 SALES
      7876 ADAMS            1100         20 RESEARCH
      7900 JAMES            1800         30 SALES
      7902 FORD             3000         20 RESEARCH
      7934 MILLER           1300         10 ACCOUNTING
      7935 XIAOXUE          5000         20 RESEARCH
已選擇 15 行。
如上述的結果與自然串連的結果相同。

使用using關鍵字簡化串連時,需要注意以下幾點:
1.使用emp表和dept表中的deptno列進行串連時,在using子句和select子句中,都不能為deptno列指定表名或表別   名。
2.如果在串連查詢時使用了兩個表中相同的多個列,那麼久可以在using子句中指定多個列名,形式如下:
select... from table1 inner join table2
using(column1,column2)
上述的語句相當於下面的語句:
select... from table1 inner join table2
on table1.column1=table2.column2
and table1.column2=table2.column2;

如果對多個表進行檢索,就必須多次使用using關鍵字進行指定,形式如下:
select... from table1
inner join table2 using(column1)
inner join table3 using(column2);


上述的語句相當於下面的語句:

select... from table1,table2,table3
where table1.column1=table2.column1
and table2.column2=table3.table2;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.