Oracle是一款廣泛應用于企業級軟件開發的關系型數據庫管理系統。在Oracle應用中,數據操作語句是建立數據庫和執行數據查詢的核心。以下是Oracle常用的操作語句。
創建表
create table tablename( column1 datatype [constraint], column2 datatype [constraint], ... );
例如:
create table student( id int primary key, name varchar2(50), age int, gender char(1) );
插入數據
insert into tablename (column1, column2, ...) values (value1, value2, ...);
例如:
insert into student (id, name, age, gender) values (1, '張三', 18, '男'); insert into student (id, name, age, gender) values (2, '李四', 20, '女');
更新數據
update tablename set column = value [where conditions];
例如:
update student set age = 21 where name = '張三';
刪除數據
delete from tablename where conditions;
例如:
delete from student where age< 18;
查詢數據
select column1, column2, ... from tablename [where conditions] [order by column [asc|desc]] [limit n];
例如:
select id, name from student where gender = '男' order by age desc; select * from student limit 10;
創建索引
create [unique] index indexname on tablename(column);
例如:
create index idx_age on student(age);
連接表查詢
select t1.column1, t2.column2 from table1 t1 join table2 t2 on t1.commoncolumn = t2.commoncolumn;
例如:
select s.name, c.course from student s join course c on s.id = c.student_id;
以上是Oracle常用的操作語句,熟練掌握這些語句可以提高開發效率和操作數據庫的能力。