Sie sind auf Seite 1von 3

CS457L(A)_Lab5

1. select ename, lower(ename), upper(ename), initcap(ename) from emp;


2. select 'The job title for ' || initcap(ename) || ' is ' || lower(job) job_detail from
emp;
3.select substr('ABCDEFG',0) S1 ,substr('ABCDEFG',1) S2 ,substr('ABCDEFG',4)
S3 ,substr('ABCDEFG',4,3) S4 ,substr('ABCDEFG',-5) S5 ,substr('ABCDEFG',5,4) S6 ,substr('ABCDEFG',-5,10) S7 ,substr('ABCDEFG',-5,-1) S8 from dual;
4. INSTR(string, pattern, position, occurrence) returns the location(numeric value)
of the pattern inside the string starting from position and after occurrence times.
select instr('CORPORATE FLOOR','OR') I1 ,instr('CORPORATE FLOOR','OR',3)
I2 ,instr('CORPORATE FLOOR','OR',3,2) I3 ,instr('CORPORATE FLOOR','OR',1) I4 ,instr('CORPORATE FLOOR','OR',-1,2) I5 from dual;
5. LTRIM(string1,n,string2) returns string1 left padded to length n with sequence
of string2
select ltrim('xyxy1234','xy') L1 ,ltrim(' 1234') L2 ,ltrim('00001234','0') L3 from
dual;
6. LPAD(string1,n,string2) returns string1 left padded to length n with sequence of
string2 (default blank space)
select 'The salary of ' || rpad(ename,10) || ': ' || lpad(sal,8) salary from emp;
7. Date Functions:
A. select sysdate+1, sysdate-365 from dual;
B. select sysdate, add_months(sysdate,6) from dual;
C. select sysdate ,last_day(sysdate) "last date of month" ,last_day(sysdate)-sysdate
"days left in month" from dual;
D. select next_day(sysdate, 'Tuesday') next_tuesday ,next_day(sysdate, 'Tue')
next_tuesday ,next_day(sysdate, 1) nx_wk_1st_day from dual;
E. select sysdate, trunc(sysdate) ,trunc(sysdate,'month') ,trunc(sysdate,'year') from
dual;
F. select sysdate, round(sysdate) ,round(sysdate+15,'month') ,round(sysdate,'year')
from dual;

8.CEIL(n) returns the smallest integer >= n


select ceil(12.3), ceil(-12.3) from dual;
FLOOR(n) returns the largest integer <= n
select floor(12.3), floor(-12.3) from dual;
9.Display the names of employees who are working in the company for the past5
years(Hint: Use sysdate)
10.Display the names of employees whose name is exactly five characters in
length.(Hint: use length)
11.Display the total number of employees working in the company.
12.Display department numbers and total number of employees within each group.
(Hint: Use count)
13.select round(12.738),round(12.738,2),round(12.738,-1) from dual
select trunc(12.738),trunc(12.738,2),trunc(12.738,-1) from dual;
14.Display the ascii value of character G
TRIM() can trim both side. Or specify which side

15.select trim(' 1234 ') T1 , trim('0' from '000012340000') T2, trim(leading '0'
from '000012340000') T3, trim(trailing '0' from '000012340000') T4,trim(both '0'
from '000012340000') T5 from dual;
16.REPLACE(string1, string2, string3), returns string2 replaced by string3 inside
string1
Display the empno,ename from emp table. Wherever job manager is found it
should be displayed as boss
17.NVL & NVL2
NVL(value1, value2) converts all null value1 to an actual value2.
select ename, nvl(comm,0) comm,
nvl(hiredate,to_date('01/01/1980','mm/dd/yyyy'), nvl(job, 'UNKNOWN JOB') from
emp;
NVL2(value1, value2, value3), if value1 is not null,then return value2, if its null,
return value3.
select ename, nvl2(comm, comm*1.1, 100) new_comm from emp;
18.Syntax - decode(col/expression, --decode(col/expression, case1, result1,
[,case2,result2?] [,default])
Write a query to display the total number of employees and the total number of
employees hired in 1980, 1981, 1982, 1983.

Das könnte Ihnen auch gefallen