Oracle题库二
1)显示"hello world"符串大写的形式
select upper('hello world') from dual;
2)显示"HELLO WORLD"符串小写的形式
select lower('HELLO WORLD') from dual;
3)显示"hello world"符串的首字母大写,其他小写的形式
select initcap('hello world') from dual;
4)将hello字符串后拼接world字符串
select concat('hello','world') from dual;
5)求hello world字符串的第三个字符到第八个字符的子字符串?
substr(str,index1,index2)第一个参数为要截取的字符,index1
为起始位,index2是从起始位开始算有多少个字符
select substr('hello world',3,6)from dual;
6) 求hello world字符串的长度
select length('hello world')from dual;
7)查询员工的全名和工资,并且全名以大写的方式
显示,并且first_name的长度大于6,最后工资降序排序?
select upper(first_name||'.'||last_name) name,salary
from s_emp
where length(first_name)>6
order by salary desc
8)执行下面的sql语句,看看执行后结果,分析
round函数的含义?
select round(45.67) from dual; 46
select round(45.67,1) from dual; 45.7
select round(45.67,2) from dual; 45.67
select round(45.67,-1) from dual; 50
select round(45.67,-2) from dual; 0
select round(55.67,-2) from dual; 100
9)执行下面的sql语句,看看执行后结果,分析
trunc函数的含义?
select trunc(45.67) from dual; 45
select trunc(45.67,1) from dual; 45.6
select trunc(45.67,2) from dual; 45.67
select trunc(45.67,-1) from dual; 40
select trunc(45.67,-2) from dual; 0
select trunc(55.67,-2) from dual; 0
10)执行下面的sql语句,看看执行后结果,分析
mod函数的含义?
select mod(1500,400) from dual; 300
题2 :
1)显示当前时间,查询当前时间是这年的第几天?是这个星期的第几天?
是这个月的第几天?
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss ddd-dd-d') from dual;
2)显示所有雇员的姓和加入公司的年份和月份,按雇员受雇日所在年、月排序
,将最早年份的雇员排在最前面,年份相同雇员再按月份入职早晚顺序排
select last_name,to_char(start_date,'yyyy-mm')
from s_emp
order by to_char(start_date,'yyyy-mm');
3)找出在(任何年份的)2月受聘的所有雇员
select last_name,to_char(start_date,'mm')
from s_emp
where to_char(start_date,'mm')=2;
4)显示所有雇员的姓以及满10年服务年限的日期
select last_name,trunc((sysdate-start_date)/365) as time
from s_emp
where trunc((sysdate-start_date)/365)>=10;
5)对于每个雇员,显示其加入公司的天数
select last_name,sysdate-start_date
from s_emp;
6)显示所有雇员的姓的前三个字符
select substr(last_name,1,3) from s_emp;
7)显示正好为6个字符的雇员姓名
select last_name
from s_emp
where length(last_name)=6;
8)显示只有首字母大写的所有雇员的姓
select last_name
from s_emp
where initcap(last_name)=last_name;
9)找出早于23年之前受雇的雇员
select last_name,trunc(((sysdate-start_date)/365)) time
from s_emp
where trunc(((sysdate-start_date)/365)) >=23
10)找出各月最后一天受雇的所有雇员
select last_name
from s_emp
where to_char(start_date,'dd')=to_char(last_day(start_date),'dd');
11)以这种2013/08/19格式来显示入职时间
select to_char(start_date,'yyyy/mm/dd') from s_emp;