SQL Notes I.Data Definition Language
SQL Notes I.Data Definition Language
13. How to see the permission list received by user from others?
A. desc all_privs_recd
IV.TRANSACTION CONTROL LANGUAGE
It is used to get the data from data base objects for read only purpose
(A) SELECT
2. How to retrieve the data from the table using between condition?
A. select * from emp where salary between 3000 and 7000;
select * from emp where salary not between 3000 and 7000;
4. How to retrieve selected row more than one from the table?
A. select * from emp where empno in(100,105,110);
select * from emp where empno not in(100,105,110);
5. How to retrieve names which is starting with ‘S’ from the table?
A. select * from emp where ename like’s%’;
select * from emp where ename not like’s%’;
8. How to retrieve names which is ending with ‘S’ from the table?
A. select * from emp where ename like’%s’;
select * from emp where ename not like’%s’;
9. How to retreive names which is the second letter ‘S’ from the table?
A. select * from emp where ename like’_s%’;
select * from emp where ename not like’_s%’;
11. How to retrieve data belonging two column conditions from the table?
A. select * from emp where job_id=’marketing’ or salary>5000;
select * from emp where ename like’s%’ or salary>5000;
ARITHEMATIC OPERATIONS
ARITHEMATIC FUNCTIONS
CHARACTER FUNCTIONS
9. How to display the right space with & in the select statement?
A. select empno,ename,rpad(sal,6,’*’) from emp;
14. How to display the first five letter of the string in the table?
A. select empno,ename,substr(ename,1,5) from emp;
DATE FUNCTIONS
TIME FUNCTIONS
1. How to see the fractional seconds with date & time of server?
A. select systimestamp from dual;
2. How to see the fractional seconds with date & time of client system?
A. select current_timestamp from dual;
CHARACTER FORMATS
GENERAL FUNCTIONS
SPECIAL OPERATORS
OREDER BY CLAUSE
1. How to retreive the data in the ascending order from the table?
A. select * from emp order by deptno;
GROUP FUNCTIONS
Group functions operate on sets of rows to give one result per group
2. Display all the employees name in their relation hierarchy output should be formatted?
A. select lpad(ename,length(ename)+level) from emp start with mgr is null connect by prior
empno=mgr;
1. How to display data from two tables using ‘cross join’ or ‘cartesian join’?
A. select * from emp,dept;
2. How to display data from two tables using ‘equi join’ or ‘natural join’ condition?
A. select e.empno,e.ename,e.deptno,d.dname from emp e,dept d where e.deptno=d.deptno;
select e.empno,e.ename,e.deptno,d.dname from emp e,dept d where e.deptno=d.deptno
and ename=’hari’;
SUB QUERY
Simple Subquery
Correlated Subquery
2. How to display the employees who joined the company before their employees?
A. select * from emp e where e.hiredate>(select m.hiredate from emp m where e.mgr=m.empno);
LOCKS
CONSTRAINTS
VIEWS
ROWNUM
4. How to delete the duplicate records which is having the same data,empno & ename?
A. delete from emp where rowid not in(select min(rowid) from emp group by empno);
SEQUENCE
INDEX
It is mainly used to improve performance which retrieving (or) manipulating data by using indexed
columns in where clause. It is a pointer to locate the address of data.
SYNONYM
SPOOL
DATABASE UTILITIES
D:\oracle\ora90\bin> IMP
Username : hari
Password : hari
Import file:EXP.DMP.DMP> D:\hari.DMP
Enter insert buffer size(minimum is 8192)) 30720> (enter)
List contents of import file only(yes/no) no> (enter)
Ignore create error due to object existence (yes/no) no> (enter)
Import grants(yes/no) yes>
Import table data (yes/no): yes> (enter)
Import entire export file (yes/no): no> (enter)
Username: scott
Enter table(T) or partition(T:P)name or . If done: (enter)
SQL*LOADER
1. How to insert data from the file.txt into the database using fixed method?
A. sql>conn hp/hp
sql>create table vtest(name varchar2(10),code varchar2(5));
HARIHYD100
RAVISEC200
CONTROL_FXD.txt
LOAD DATA
INFILE HARI_TXT.TXT
REPLACE
INTO TABLE VTEST
(
NAME POSITION (1:4) CHAR,
ADR POSITION (5:7) CHAR,
CODE POSITION (8:10) CHAR
)
2. How to insert data from the file.txt into the database using variable method?
A. sql>conn hp/hp
sql>create table sqld(name varchar2(10),code varchar2(5));
PRA_TXT.txt
Hari,hyderabad,100
Prasad,secunderabad,200
Teja,bangalore,300
Seshu,vigaz,400
CONTROL_VAR .txt
LOAD DATA
INFILE PRA_TXT.TXT
INTO TABLE SQLD
FIELDS TERMINATED BY ','
(NAME,CODE)
UTL_FILE R Mode
UTL_FILE W Mode
1. How to send data into file.txt from the database using W mode?
A. sql> create or replace procedure proc1 is
vfileID UTL_FILE.file_type;
vstring varchar2(2000);
cursor c1 is select empno from emp;
c1empno number(4);
begin
vstring:='empno,ename,job,mgr,hiredate,sal,comm,deptno';
vfileID:=UTL_FILE.fopen('D:\','HARI1.DAT','W');
UTL_FILE.Put(vfileid, vstring);
UTL_FILE.New_Line(vfileid);
open c1;
loop
fetch c1 into c1empno;
exit when c1%notfound;
select
EMPNO||','||
ENAME||','||
JOB||','||
MGR||','||
HIREDATE||','||
SAL||','||
NVL(COMM,0)||','||
DEPTNO
INTO
vstring
FROM EMP
WHERE EMPNO=c1empno;
UTL_FILE.Put(vfileid, vstring);
UTL_FILE.New_Line(vfileid);
end loop;
close c1;
UTL_FILE.fclose(vfileID);
exception
when others then
DBMS_OUTPUT.PUT_LINE('SYSTEM ERROR');
end;
/
sql> exec proc1;
PRA1.DAT
10 Hari
20 Prasad
30 Kiran