1、连接数据库
srvmgrl
connect internal/oracle as sysdba
显示结果为 connected
srvmgrl>
2、查看数据库参数
srvmgrl
srvmgrl>show parameters
srvmgrl>show parameters buffers(查看参数的设定值)
3、查看当前的SGA大小
srvmgrl
srvmgrl>show sga
srvmgrl>spool off(结束本次执行结果的记录)
4、启动数据库
srvmgrl
srvmgrl>connect internal/oracle as sysdba
srvmgrl>startup normal(immediate)
oracle instance started
tatol system global area    8030448 bytes
fixed size                    44584 bytes
variable size                7510728 bytes
database buffers              409600 bytes
redo buffers                  65536 bytes
database mounted.
database opened.
srvmgrl>
5、加载启动
srvmgrl>connect internal/internal
srvmgrl>startup mount
oracle instance started
tatol system global area    8030448 bytes
fixed size                    44584 bytes
variable size                7510728 bytes
database buffers              409600 bytes
redo buffers                  65536 bytes
database mounted.
srvmgrl>
srvmgrl>exit
退出服务器管理器,数据库处于加载状态时,用户不能进行登录。
6、非加载启动
srvmgrl>connect internal/oracle
srvmgrl>startup nomount
oracle instance started
tatol system global area    8030448 bytes
fixed size                    44584 bytes
variable size                7510728 bytes
database buffers              409600 bytes
redo buffers                  65536 bytes
srvmgrl>
srvmgrl>exit
7、约束启动
srvmgrl>connect internal/oracle
srvmgrl>startup restrict
只允许具有一定权限的用户进行访问
8、从约束启动到非约束启动
srvmgrl>connect internal/oracle
srvmgrl>alter system disable restricted session
或者
srvmgrl>connect internal/oracle
srvmgrl>startup
还有就是把现有的数据库shutdown之后重新启动后都是非约束状态。
9、强制启动
srvmgrl>connect internal/oracle
srvmgrl>startup force
10、关闭数据库
srvmgrl>connect internal/oracle
srvmgrl>shutdown normal(immediate)
11、oracle表中的每一行都具有唯一的行标识(rowid)
select rowid,substr(rowid,1,8) "block",substr(rowid,15,4)"file"sub
str(rowid,10,4)"row" from tablex;
12、创建表
create table customer
(customer_id number(10) not null,
surname varchar2(30) not null,
first_name varchar2(20),
sales_region char(2),
ytd_sales number(10,2),
total_sales number(14,2));
13、表中增加列,以上为例,
alter table customer
add tax_exempt_ind varchar2(1);
************************************
显示table空间
describle customer就显示customer的表空间
****************************************
14、删除一列还是以上为例,
alter table customer
drop column tax_exempt_ind;
15、用户自定义数据类型
SQl>create type indiv_details as object
(name varchar2(40),
phone varchar2(20),
height number(3),
weight num
ber(4)
/
type created!新建的类型已经建立,在新建的类型上进行简单的应用,
sql> create table vendors
(vendor_name indiv_details,
create_date date,
company_name varchar2(30),
postal_zip_code varchar2(9),
/
table created.
16、创建视图
sql> create view v_customer_sales_rgn
as
select surname,sales_regiom
from customer;
view created.
17、创建索引
sql>create table sample_3
(a varchar2(30),
b varchar2(30),
c varchar2(30),
......
table created.
索引特点
1)索引保证数据的唯一;
2)索引有顺序;
3)两列比一列好;
4)where子句和索引。
创建索引主要是为了减轻数据库的访问负担。
18、同义词
同义词的用途:
隐藏表的拥有者或表名
隐藏表的具体位置
给用户的一个相对简单的表名称
create synonym toast for ops$coreymj.sample_3;
19、授权访问
1)授权语句的组成部分
A、关键字权限部分由grant后跟一种或多种权限组成
B、表名部分由关键字ON起头并列出准备在其上授权的表
C、接受授权的部分是准备获得权限的一个或多个权限
2)四种对象授权限授予用户
A、select
grant select on sample_3 to public给所有用户
grant select on sample_3 to opr$cys,opr$yy;给cys与yy用户查询权限。
B、insert
grant insert on sample_3 to public
grant insert on sample_3 to opr$cys,opr$yy;给cys与yy用户授权插入权限。
C、update
grant update on sample_3 to opr$yy给YY用户授更换的权限。
D、delete
grant delete on sample_3 to opr$YY 给用户YY授删除权限。
delete from sample_3删除表中所有的数据,还有一种命令truncate table sample_3,这是种不能恢复的命令,在确认的情况下才可以用,用时一定要小心。
综合性操作:
grant select,update,delete,insert on sample_3 to public;或者进行限制性授权处理也可。
20、创建角——成给管理用户的方法
create role nurse
grant insert on tableA to nurse;
grant insert on tableB to nurse;
grant insert on tableC to nurse;
grant update on tableA to nurse;
grant update on tableB to nurse;
grant delete on tableB to nurse;
grant select on tableA to nurse;
grant select on tableB to nurse;
把角NURSE赋予下面几个用户
grant nurse to ops$skl;
grant nurse to opr$cys;
grant nurse to opr$yy;
在给用户修改权限只需要修改角的权限就可以
grant delete on tableB to nurse;
21、查看数据字典中的对象
sql> desc user_dependencies进行查询;
22、数据类型的定义
char(size) 存放定长字符数据,最长2000个字符
nchar(size) 与char型类似,不过最大长度由数据库所用的字符集
varchar2(size) 存放可变长字符数据,最大长度为4000字符
nvarchar(size) 类似于varchar2
varchar日前等于char
number(1,d) 存放数值型数据,1代表总位数,d代表小数点后位数
blob二进制大对象,其最大长度为4GB
raw(size) 纯(RAW)二进制数据,最大长度为2000字节date 存放日期,范围从公元前4712年的1月1日到公元后9999年前的12月31日
long 存放可变长字符数据,最大为2GB(gigabytes)
23、where子句的使用方法
1) 没有了限制的情况
select * from sample_3 where last_name='skl'
2) 并AND
select * from sample_3 where last_name='skl' and first_name='yy'
3) 不并 not and
select * from sample_3 where last_name!='skl' and first_name!='yy'
oracle四舍五入4)限定范围
select * from sample_3 where tel (not)between 3180000 and 3189999;
5)根据查询条件列表中的项目进行查询
select * from sample_3 where last_name in('yy','skl');
6)后模糊查询
select * from sample_3 where last_name like 's%';
7)前后模糊查询
select * from sample_3 where last_name like '%y%'; 查询到是含有Y所有last_name的行
24、order by子句
select * from sample_3 order by last_name desc(按降序排序);
25、数值型数据
操作方法:
select ytd_sales+current_sales from customer;
select ytd_sales-current_sales from customer where state_cd='NJ';
select ytd_sales*commission from customer;
select ytd_sales/12 from customer;
数据型常用函数:
ceil(n) 大于等于数值N的最小整数
select ceil(10.6) from dual;
floor(n) 小于等于数值N的最大整数
select floor(10.6) from dual;
mod(m,n) m除以N的余数,若N=0,则返回M
select mod(7,5) from dual;
power(n,m) m的N次方
select power(3,2) from dual;
round(n,m)将四舍五入,保留小数点后M位
select round(1234.4567,2) from dual; 结果是1234.57
sign(n) 若n=0,返回0;否则N>0,则返回1;N<0,返回-1
select sign(12) from dual;
sqrt(n) N的平方根
select sqrt(25) from dual;
26、字符型数据
字符型函数:
initcap(char) 把每一个字符串的第一个字符换成大写
select initcap('mr.teplow') from dual;
lower(char) 整个字符串变成小写
select lower('Mr.Frank Townson') from dual;
replace(char,strl,strl2) 字符串中所有STR1换成STR2
select replace('Scott','s','boy') from dual;
soundex(char) 字符串的语音表示,常用于名字的模糊查询,可查发音相似拼写不同的字符串
select last_name from employee where soundex(last_name)=soundex('smythe');
substr(char,m,n)取出从M字符开始的N个字符的子串
select substr('abcdef',2,1) from dual;
length(char)求字符串的长度
select length('andersom') from dual;
27、日期型数据
常用函数类型:
sysdate 当前的日期与时间
select sysdate from dual;
last_day 本月最后一天
select last_day(sysdate) from dual;
add_months(d,N) 当前日期d后推N个月
select add_months(sysdate,2) from dual;
months_between(f,s) 日期F与S间相差月数
select months_between(sysdate,'12_mar,-02') from dual;
next_day(d,day) D后第一周指定的DAY日期
select next_day(sysdate,'monday') from dual;
28、表列数据类型转换
to_char将任意类
型的数据转换成字符类型
select to_char(8897) from dual;
to_number将一组合法的数字字字符转换成数值
select to_number('8897') from dual;
to_date 将适合格式的字符串数据转换成日期型数据
select to_date('12-dec-02') from dual;
注意如果格式不正确将不能成功的转换
select to_date(dad,date) from dual;就会转换失败
而select to_date('20020202','yyyymmdd') from dual;就可以成功的转换,而
select to_date('20021236','YYYYMMDD') from dual;就不可以。
29、常见的DML语句
update语句
update table set name=''null';
delete语句
delete from table
alter语句增加表列时就用此语句
alter table customer add(sale_date date);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。