oracle資料庫中,數據的增、刪、改、查,通過SQL語句實現 SQL:結構化查詢語言; 特點:不區分大小寫;字元串用單引號引起來;語句結束用分號表示結束; 行註釋,在語句的最前面加“--” 塊註釋,分別在語句的前後加 /* 和 */ SQL中常用的幾類: 一、數據定義語言 DDL:創建、修改、刪除 ...
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 student(sno,sname,ssex) values('102','張三','男'); --或者這樣寫 insert into student values('102','張三','男',sysdate,'95033'); select * from student
2.數據的修改:
--數據的修改 update student set ssex='女' where sno='102'; --如果不加where,便是修改整個表某列的屬性 --對某一列數據的加減 update student set sclass=sclass+1; update 表名 set 列名=列名+1 where 條件 --日期的加減1為日的加減1
3.數據的刪除:
--數據的刪除 delete student where sno=102; delete 表名 where 條件; --不加where,即刪除整個表,但是效率低,可用truncate table 表名來刪除(先刪表,再建表) 例:truncate table student;
三、數據查詢語言 DQL:從表中獲取數據(查詢數據)。
--數據查詢 select * from student; select * from 表名; --根據條件找欄位 select sno,sname from student where sclass='95031'; select 欄位名 from 表名 where 條件