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常用的操作语句,熟练掌握这些语句可以提高开发效率和操作数据库的能力。