熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

Oracle數據庫刪除語句DELETE的一般性用法

2022-06-13   來源: Oracle 

  語法與其它的sql數據庫教程是一樣的如下
DELETE FROM COURSES
WHERE  COURSE_DESIGNATER = Java

  按條件比較復雜的操作方法

  DELETE FROM CLASSCONVENINGS
WHERE      CLASSES_NUM_FK      >  
  AND CLASS_CONVENE_DATE = TO_DATE( ::
                                   YYYYMMDD HH:MI:SS)
  AND CLASS_LOCATION_FK   = SeattleTraining Room
 

  下面來看個詳細的實例

  SQL> create demo table
SQL> create table Employee(
      ID                 VARCHAR( BYTE)         NOT NULL
      First_Name         VARCHAR( BYTE)
      Last_Name          VARCHAR( BYTE)
      Start_Date         DATE
      End_Date           DATE
      Salary             Number()
      City               VARCHAR( BYTE)
      Description        VARCHAR( BYTE)
   )
   /

  Table created

  SQL>
SQL> prepare data
SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary  City       Description)
                 values (Jason    Martin  to_date(YYYYMMDD) to_date(YYYYMMDD) Toronto  Programmer)
    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary  City       Description)
                  values(Alison   Mathews to_date(YYYYMMDD) to_date(YYYYMMDD) VancouverTester)
    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary  City       Description)
                  values(James    Smith   to_date(YYYYMMDD) to_date(YYYYMMDD) VancouverTester)
    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary  City       Description)
                  values(Celia    Rice    to_date(YYYYMMDD) to_date(YYYYMMDD) VancouverManager)
    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary  City       Description)

                  values(Robert   Black   to_date(YYYYMMDD) to_date(YYYYMMDD) VancouverTester)


    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary City        Description)
                  values(Linda    Green   to_date(YYYYMMDD) to_date(YYYYMMDD) New York  Tester)
    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary City        Description)
                  values(David    Larry   to_date(YYYYMMDD) to_date(YYYYMMDD) New York  Manager)
    /

   row created

  SQL> insert into Employee(ID  First_Name Last_Name Start_Date                     End_Date                       Salary City        Description)
                  values(James    Cat     to_date(YYYYMMDD) to_date(YYYYMMDD) Vancouver Tester)
    /

   row created

  SQL>
SQL>
SQL>
SQL> display data in the table
SQL> select * from Employee
    /

  ID   FIRST_NAME LAST_NAME  START_DAT END_DATE      SALARY CITY       DESCRIPTION

   Jason      Martin     JUL JUL    Toronto    Programmer
   Alison     Mathews    MAR FEB    Vancouver  Tester
   James      Smith      DEC MAR    Vancouver  Tester
   Celia      Rice       OCT APR    Vancouver  Manager
   Robert     Black      JAN AUG    Vancouver  Tester
   Linda      Green      JUL JAN    New York   Tester
   David      Larry      DEC FEB    New York   Manager

  ID   FIRST_NAME LAST_NAME  START_DAT END_DATE      SALARY CITY       DESCRIPTION

   James      Cat        SEP APR    Vancouver  Tester

   rows selected

  SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> delete command with conditions
SQL>
SQL> delete from Employee where Salary > ;

   rows deleted

  SQL>
SQL> select * from Employee;

  ID   FIRST_NAME LAST_NAME  START_DAT END_DATE      SALARY CITY       DESCRIPTION

   Jason      Martin     JUL JUL    Toronto    Programmer   Celia      Rice       OCT APR    Vancouver  Manager
   Robert     Black      JAN AUG    Vancouver  Tester
   James      Cat        SEP APR    Vancouver  Tester

   rows selected

  刪除指定的內容

  SQL> CREATE TABLE project (
      pro_id              NUMBER()
      pro_name            VARCHAR()
      budget          NUMBER()
      CONSTRAINT project_pk   PRIMARY KEY (pro_id)
    );

  Table created

  SQL>
SQL>
SQL> INSERT INTO project(pro_id pro_name budget)VALUES ( A);

   row created

  SQL> INSERT INTO project(pro_id pro_name budget)VALUES ( ERP);

   row created

  SQL> INSERT INTO project(pro_id pro_name budget)VALUES ( SQL);

   row created

  SQL> INSERT INTO project(pro_id pro_name budget)VALUES ( CRM);

   row created

  SQL> INSERT INTO project(pro_id pro_name budget)VALUES ( VPN);

   row created

  SQL>
SQL>
SQL> SET ECHO ON
SQL> DELETE
    FROM project
    WHERE pro_id =
 


From:http://tw.wingwit.com/Article/program/Oracle/201311/19072.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.