微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Oracle初级指令

打开sql plus

system as sysdba
密码orcl



使用norMAL关闭数据库,使用TRANSACTIONAL方式关闭数据库,使用IMMEDIATE关闭数据库使用ABORT方式关闭数据库

shutdown normal
shutdown transactional
shutdown immediate
shutdown abort

链接scott
connect scott/tiger(认密码)
scott锁定了,解锁
conn sys as sysdba
alter user scott account unlock identified by 密码;
conn scott/密码;
或者按回车,出现输入指令字样。


表的创建,增删语句。

create table 表名
(
   列名1 numeric(总位数,小数点后的位数) not null,列名2 varchar(二进制位数) not null
)
drop table 表名      //删除表
alter table 表名 add 列名 coltype;        //添加列
alter table 表名 drop column 列名;         //删除列
alter table 表名 add primary key(主键名);         //创建一个主键
alter table 表名 add constraint pk_表名 primary key(主键名);         //创建一个主键
alter table 表名 drop primary key(主键名);        //删除主键
alter table 表名1 add constraint fk_表名1 foreign key(外键) references 表名2(外键);

数据的增删查改




(1) 数据记录筛选:

select * from 数据表 where 字段名=字段值 order by 字段名 [desc];
select * from 数据表 where 字段名 like '%字段值%' order by 字段名 [desc];
select top 10 * from 数据表 where 字段名=字段值 order by 字段名 [desc];
select top 10 * from 数据表 order by 字段名 [desc];
select * from 数据表 where 字段名 in ('值1','值2','值3');
select * from 数据表 where 字段名 between 值1 and 值2;

(2) 更新数据记录
update 数据表 set 字段名=字段值 where 条件表达式;
update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式;

(3) 删除数据记录:
delete from 数据表 where 条件表达式;
delete from 数据表;

(4) 添加数据记录:
insert into 数据表 (字段1,字段2,字段3 …) values (值1,值2,值3 …);
insert into 目标数据表 select * from 源数据表;

(5) 数据记录统计函数

AVG(字段名) 得出一个表格栏平均值 COUNT(*;字段名) 对数据行数的统计或对某一栏有值的数据行数统计 MAX(字段名) 取得一个表格栏最大的值 MIN(字段名) 取得一个表格栏最小的值 SUM(字段名) 把数据栏的值相加

原文地址:https://www.jb51.cc/oracle/211512.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐