庆祝s

或多或少
整理的Oracle精辟问答题(2)
1.char,varchar2数据类型有什么区别?它们各自的取值范围是多少?
区别是char是1-2000个字符 空间是固定的
varchar2 的是空间是可变的
2.如何存储没有浮点数的整数?
column_name number(p,s){浮点数}
列名 数据类型是number ,p是精度(1-38之间),s是范围
3.long是什么数据类型,它的大小是多少,对于一个表对long类型的字段有何限制?
是用于存储可变长度的字符数据 最多是2GB
一个表里只能有一列是long型的
4存储日期值的数据类型是什么?
Date
5.哪个函数可以返回当前日期?--问题
select sysdate from dual
6.RAW用来存储什么数据?它有默认大小吗?
是用储存字节的 一般是2进制
没有默认的大小
7.LOB类型包含哪几种类型?
clob , blob, bfile
8.每个表中都包含字段ROWID和ROWNUM吗?
是的
9.怎么使用rowid字段?

select rowid ,列名 from 表名 where 条件
10.在查询一个结果集时,如何限制返回的行数?
select * from all_all_tables where rownum <6
11.如何删除一个表中的重复记录?--*
distinct ;
12.建立表author(auid,name(20),age,address(50),nation(20),photo)
create table author
(
 auid number,
 name varchar2(2),
 age number,
 address varchar2(50),
 national varchar2(20),
 photo blob
)
select * from author
drop table author
13.建立表titleauthor(bkid,bookname(50),auid,pub_id,isbn(10),pub_date(出版日期),pub_desc(书的介绍))

create table titleauthor
(
 bkid number,
 bookname varchar2(50),
 auid number,
 pub_id number,
 isbn varchar2(10),
 pub_date date,
 pub_desc varchar2(200)
)
select * from titleauthor
14.建立表publishers(pub_id,pub_name(20),pub_tel(5),pub_chairman(20))
create table publishers
(
pub_id number,
pub_name varchar(20),
pub_tel varchar2(5),
pub_chairman varchar2(20)
)
select * from publishers
15.修改表author,添加字段sex(1),将name字段修改为不可空,sex也不可为空
alter table author
add(sex varchar2(1) not null)
alter table author
 modify (name varchar2(20) not null)
16.修改表publishers,删除字段pub_chairman.
alter table publishers
drop column pub_chairman
17.修改表titleauthor,将字段isbn的宽度变为12.
alter table titleauthor
modify
(
isbn varchar2(12)
)
18.查看这三个表的最终结构。
desc author;
desc publishers;
desc pub_chairman;
19.truncate和delete有什么区别?
20.可利用什么语句来查看一个表A中(假如有‘国家’字段)有哪些国家,不重复?
select distinct 列名 from 表明
21.如何利用表author来创建一个相对于它的备份表。
create table sales
as select * from author

22.如何利用表author来创建一个只有两个字段(name,age)的空表
create table test1
as select name,age from author

23.如何利用一个表的数据来插入另外一个表?
create table test
(
name varchar2(20),
age int
)
insert into test select * from test1
select * from test
24.有表AAA (sn(number),pub_date(date)),如何将日期2000年5月2日,sn为2的一条记录插入。
create table aaa
(
sn number,
pub_date date
)
insert into AAA values(2,'2-5月-2000')
select * from AAA
25.我们知道这样的语句
   update student set mark=80 where stuid=123
   请问这样可以吗?
   update student set mark=(select mark from test where stuid=123) where stuid=123
  可以

26.保存点是个什么概念?
用事务 可以回滚到某一点上
27.假设有保存点s1,请问如何在后续的操作中回滚到此保存点?
roll back s1
28.如何将表account表的查询权限授予用户wwwuser.
grant select on account to wwwuser
29.如何授予用户ts111连接到数据库的权限。
grant connect to ts111
30.如何撤消用户wwwuser对表account记录的删除权限?
revoke delete on account from wwwuser
31.MINUS集合操作查询是什么意思,如select a from taba minus select a from tabb;
把taba和tabb表里的公共部分去掉
32.oracle下的连接操作符是什么?
||
33.有表person(id,name,address),此表有记录1,zhangshan,'beijing china',我现在要求在查询结构中如下显示
   1号员工,姓名是zhangshan,他住在beijing china.
   请问如何写sql语句。
select ('姓名'||name||'他'||age||'岁') a from test where name = 'aa'
select (id||'号员工,姓名是'||name||',他住在'||address) form person
34.我如何获得5个月之前的日期?
select add_months(sysdate,-5) from dual
35.我如何获得3年之后的日期?
select add_months(sysdate,+36) from dual
36.如何获得今天距奥运会开幕还有多久?
select to_date(sysdate)-trunc(to_date('2008-8-8', 'yyyy-mm-dd'), 'dd')  from dual
37.如何获得一个日期中的月数?
select extract(month from sysdate) from dual
38.dual是一个什么东西?
是个用来测试数据的表
39.initcap,lower,upper函数分别有什么用?
initcap 用来把首字母大写
lower 转换小写
upper 转换大写
40.trim,ltrim,rtrim函数?
trim 是裁剪指定的字符
ltrim 是用来裁剪左边指定的字符
rtrim 是用来裁剪左边指定的字符
41.translate,replace,decode分别是什么意思?如何使用?
translate按字符翻译
replace 支付串替换
decode 对表里的值替换
42.instr,substr各是什么意思?
instr是索引
substr是截取
43.如何获得一个字符串的长度?
select length('aaaaaaaaaaaaaaaaaaaaaaaaaaaaa') 长度 from dual
44.如何获得一个字符的ASCII值?
select ascii('a') from dual
45.trunc,round,floor,ceil,abs,sqrt,mod,power函数各是做什么用的?
select trunc(1000.2365,2) from dual
select round(1000.2365,2) from dual
select ceil(1000.2365) from dual
select abs(-1000.2365) from dual
select sqrt(1000.2365) from dual
select mod(1000,3) from dual
select power(1000.2365,2) from dual
46.如何将一个日期按指定格式转换为字符串?
select to_char(sysdate,'yyyy"年"MM"月"dd"日"') 日期 from dual
47.如何使用to_char来格式化数值。
select to_char(item,'sss9899')
48.如何将字符串转换为日期格式。
select to_date('2006-12-12','yyyy_MM-dd')  from dual
49.to_number怎么用?
select sqrt(to_number('100')) from dual
50.NVL,NVL2,NULLIF分别怎么用?请解释
select nvl (re_level,0) from 表名
select nvl2 ('列1','如果列1是空值就返回它','如果列1不是空值就返回它') from 表名
select nullif (列,比较值) from 表名 如果相等就返回值否则返回“空格”

51.row_number是如何使用的?

select * from test where rownum = 1

posted on 2008-04-30 20:10  庆祝  阅读(719)  评论(0)    收藏  举报