Oracle數據庫,數據的增、刪、改、查


oracle數據庫中,數據的增、刪、改、查,通過SQL語句實現

SQL:結構化查詢語言;

特點:不區分大小寫;字符串用單引號引起來;語句結束用分號表示結束;

行注釋,在語句的最前面加“--”

塊注釋,分別在語句的前后加    /*  和  */

 

SQL中常用的幾類:

一、數據定義語言 DDL:創建、修改、刪除數據庫語言。

create table Student
(
  sno       varchar2(3) not null,
  sname     varchar2(8) not null,
  ssex      varchar2(2) not null,
  sbirthday date,
  sclass    varchar2(5)
)
;
-- Add comments to the table 
comment on table Student
  is '學生表';
-- Add comments to the columns 
comment on column Student.sno
  is '學號(主建)';
comment on column Student.sname
  is '學生姓名';
comment on column Student.ssex
  is '性別';
comment on column Student.sbirthday
  is '生日';
comment on column Student.sclass
  is '班級';

 

二、數據操作語言 DML:添加(insert into)、修改(update   set)、刪除表中的數據。(delete)

 1.數據的添加:insert into 表名(字段名) values(對應的數據)

--增加數據
insert into student(sno,sname,ssex) values('102','張三','男');
--或者這樣寫
insert into student values('102','張三','男',sysdate,'95033');

2.數據的修改:update 表名 set 修改的的字段 wiere 條件

--數據的修改
update student set ssex='女' where sno='102';
--如果不加where,便是修改整個表某列的屬性

--對某一列數據的加減
update student set sclass=sclass+1;
update 表名 set 列名=列名+1 where 條件
--日期的加減1為日的加減1

3.數據的刪除:

delete 表名 where 條件;
--數據的刪除
delete student where sno=102;
--不加where,即刪除整個表,但是效率低,可用truncate table 表名    來刪除(先刪表,再建表)
例:truncate table student;

 

 

三、數據查詢語言 DQL:從表中獲取數據(查詢數據)。select * from 表名;

--數據查詢
select * from student;--根據條件找字段
select sno,sname from student where sclass='95031';
select 字段名 from 表名 where 條件

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM