加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle初级指令

发布时间:2020-12-12 15:38:34 所属栏目:百科 来源:网络整理
导读:打开sql plus system as sysdba 密码orcl 使用NORMAL关闭数据库,使用TRANSACTIONAL方式关闭数据库,使用 IMMEDIATE关闭数据库, 使用ABORT方式关闭数据库 shutdown normal shutdown transactional shutdown immediate shutdown abort 链接scott connect sco

打开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(字段名) 把数据栏的值相加

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读