Professional Documents
Culture Documents
Interview Questions (SQL and PL/SQL) and Answers
Interview Questions (SQL and PL/SQL) and Answers
18
2. Can you change null value into not null value? Can you change not null value into null value?
No, We can not change (modify column) null value into not null. But we can change not
null value into null value.
5. Select job from emp table whose total salary are more than 50,000?
Select job from emp where sal>50000;
Ans: No rows selected
8. Suppose 10 users are using one procedure how many copy of the procedure will be there at
that time.
Ans: 10
15. Write the query identifying duplicate records from the table?
Select * from emp a where rowid not in(select min(rowid) from emp where
deptno=a.deptno);
16. How do you copy one table structure without its data?
Create table emp_temp as select * from emp where 1=2; (i.e. logic is false. 1=2)
20. Pre-defined:- Only error handled by user. Error created, error raised by oracle. Predefined
means already defined.
Non-Predefined:- Error created and handled by user. Only error raised by oracle. Non
predefined means not already defined.
User defined:- Error created, raised and handled by user. Here three events are done by user.
That is everything done by user.
23. Can you create synonyms for objects declared within package or subprograms?
No, We can not create synonyms for objects declared within package or subprograms.
24. What are the different types of constraints and explain each.
Constraints are conditions.
Domain integrity constraint-check constraint, not null constraint
Entity integrity constraint-primary key constraint, unique key constraint
Referential integrity constraint-Foreign key constraint, on delete cascade
28. Which one attribute is used to check whether the cursor is opened or not?
Ans: %isopen
34. Declare
Raise_paise exception;
Char I=10;
Char J=5;
Begin
Char I=10;
Char J=5;
If I=J then
Raise_Paise;
End if;
When raise_paise then
Message("some message");
End;
Which is wrong in the following program?
OUTPUT:
Char I=10;
*
ERROR at line 3:
ORA-06550: line 3, column 10:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
:= . ( @ % ; not null range default character
49. What is the difference between primary key and unique key?
Primary key constraint: It does not allow null value.
Unique key constraint: It allows null value.
50. How can u find out, a table is cost based optimization or rule based optimization?
Analyze table <table_name> compute statistics
57. How do you count total no of records from two tables if no relation between both tables?
Select a.b+c.d from (select count(*)b from emp)a, (select count(*)d from dept)c
Function:
create or replace function<function name> [argument]
return datatype is
(local declaration)
begin
(executable statements)
[exception]
(exception handlers)
end;
62. If any possibilities to return more than one value using sql function?
Yes, Function will return more than one value.
64. What is the different between oracle 8.0 and oracle 8i version?
(a) Cube operator is available in oracle 8i.
But cube operator is not available in oracle 8.0.
(b) Rollup operator is available in oracle 8i.
But rollup operator is not available in oracle 8.0.
(c) We can drop a column in oracle 8i.
We can not drop a column in oracle 8.0.
(d) We can use internet in oracle 8i.
We can not use internet in oracle 8.0
73. Where you can declare exception? Is declaration section or exception section?
Declaration section.
75. How many types of cursor used in pl/sql? What are they?
(1) Implicit cursor- SQL CURSOR
(2) Explicit cursor
(a) Static Cursor
(b) Dynamic cursor
(c) Ref cursor
76. What are types of REF cursor?
(1) Strong cursor.
(2) Weak cursor.
81. What is materialized view? Why are you using materialized view?
Materialized view a database object which stores results of local database table.
Advantages:-
(a) Summarizing data.
(b) Pre-computing data
(c) Replicating data.
(d) Distributing data
(e) Faster access for complex joins
(f) Transparent to end-users
Disadvantages:-
(a) Performance costs of maintaining the views. (b) Storage costs of maintaining the
views
82. Can you declare default value in IN, OUT and INOUT parameter?
Yes, We can declare default value for IN and INOUT parameters.
Example: procedure_name(p1 in varchar2(30) default ‘Testing’,
P2 inout varchar2(30) default ‘Testing’)
83. What are advantages of trigger?
(a) Replication(Disaster Recovery)
(b) General purpose.
(c) Auditing(To find who creating a trigger)
(d) Referential integrity.
84. What is pl/sql table?
PL/SQL table is like array in c.
98. Consider the function, suppose the second value is greater than the first value what will be
output?
It will return negative value
It will return positive value
It will return the correct number of month left.
Ans: It will return negative value.
105. What are the uses of last day and next day function?
Last_day function returns date corresponding to the last day of the month.
Next_day function returns date of specified day according to the sysdate.
Example:
SQL> select last_day(sysdate) from dual;
SQL> select next_day(sysdate,'monday') from dual;
110. Select first maximum salary, second maximum and third maximum of emp table
First maximum : select max(sal) from emp;
Second maximum: select max(sal) from emp where sal<(select max(sal) from emp);
Third maximum : select max(sal) from emp where sal<(select max(sal) from emp
where sal<(select max(sal) from emp))
111. Give Codd's rules.
1. The information rule.
2. The rule of guaranteed access.
3. The systematic treatment of Null values.
4. The database description rule.
5. Comprehensive data sub language.
6. The view updating rule.
7. The insert and update rule.
8. The physical independence rule.
9. The logical data independence rule.
10. The integrity independece rule.
11. The distribution rule.
12. The non-subervision rule.
112. Write a query to display all records of emp table and rowid.
Select rowid,emp.* from emp;
114. Write a query to select 5 highest paid employees from the emp table the month between jan
to march.
Select sal from(select sal from emp where hiredate between '01-jan-80' and '31-mar-80'
order by sal desc) where rownum<=5;
Note: Here (select sal from emp where hiredate between '01-jan-80' and '31-mar-80' order
by sal desc) is a inline view.
115. If you use null with any arithmetical operation what will be the output?
(a)0,(b)null,(c)1,(d)none of these.
Ans: null.
116. Write a query to display maximum salary for every department of a table.
Select * from emp where sal in(select max(sal) from emp group by deptno);
117. Write a query to display minimum salary for every dept within a table.
Select * from emp where sal in(select min(sal) from emp group by deptno);
119. Write a query to display the employee who earns a salary that is higher than the salary of
clerks. Sort the results by salary from
highest to lowest.
Select ename, deptno,job from emp where sal>all (select sal from emp where job
='CLERK')
Select ename, deptno,job from emp where sal>all (select sal from emp where job
='CLERK') order by sal desc;
121. Write a query to select details of those persons whose sal is repeated?
Select ename,sal from emp where sal in(select sal from emp group by sal having
count(sal)>1);
122. Write a query to select the name of managers who manage more than one employee.
Select mgr from emp group by mgr having count(*)>1;
124. Write a query to count the rows in two tables and display them in a single row.
Select a, b, a+b from(select count (*)a from emp),(select count(*) b from dept);
125. Write a query to select the Nth highest salary from emp table. (Using Connect by prior)
Select level, max(sal) from emp where level=1 connect by prior sal > sal group by level;
126. Write a query to display rows between nth row and mth row.
Select * from emp where rownum<&a minus select * from emp where rownum<&b;
127. At a time can u update more than one column values of a table? What query?
Yes, it is possible to update more than one columns values.
update tests set place='karaikudi',job='acct' where name='anbu';
update tests set place='unjanai',job='clerk',age=25 where name='anna';
129. Write a query to use where,group by,order by and having clauses are using at a time.
Select job,sum(sal) from emp where job not like 'SALESMAN%' group by job having
sum(sal)>5000 order by sum(sal);
133. Write a query to display the records of emp table where comm is null.
Select * from emp where comm is null.
139. Delete and truncate. Here which command to take less time to execute?
Truncate command take less time to execute.
SUBSTR(String n,m)
SUBSTR returns a substring according to specified position.
Example: Select ename,substr(ename,2,4) from emp;
ENAME SUBS
SMITH MITH
ALLEN LLEN
WARD ARD
JONES ONES
147. An emp table contains 100 records. First 40 records are columns one male and remaining 60
records are columns are female.
Using single statement can you change male to female and female to male?
(1) Update empmale a set sex = (select case sex when 'female' then 'male' else 'female' end
from empmale b
where a.empno = b.empno)
(2) Update empmale a set sex = (select decode(sex,'male','female','female','male') from
empmale b
where a.empno = b.empno)
157. Can you call cursor in stored function and stored procedure?
Yes, we can call cursor in stored function and stored procedure.
160. Can you write to display records between two dates without any error?
Yes, we can display records between two dates without any error.
Select * from emp where hiredate between '17-DEC-80' and '23-JAN-82';
169. In which modes are pass by reference and pass by value in the following parameter modes.
IN parameter – Pass by reference
OUT parameter – Pass by value.
171. If you drop the view, is it possible drop the corresponding base table at the same time?
No, Base table is not dropped only view is dropped.
173. Select empno,ename,sal from emp where sal between 2000 and 3000 and select
empno,ename,sal from emp
where sal>=2000 and sal<=3000 give same results.
Table of second;
D1 D2
---------- ----------
5 6
7 8
What is result of this query? Select e.*, d.* from first e, second d;
179. Can you create synonym for procedure, function and package?
Yes, We can create synonym for procedure, function, package and triggers.
183. How many LONG columns are allowed in a table? Is it possible to use LONG columns in
WHERE clause or ORDER BY?
Only one LONG column is allowed. It is not possible to use LONG column in WHERE
or ORDER BY clause.
184. When we created function or procedure which code is stored in the database?
(a)p-code
(b)source code
(c)p-code and source code
(d)None
Ans: Source code
205. When we add any data to the table, What happened in rowid and rownum?
When we add any data to the table, the rowid and rownum will be incremented.
207. If u create a foreign key through a master table, primary column name of master table and
foreign key column name of detail
table must be same name or not?
No, Need to be same name, they may be different name.
208. Write code for using cursor with parameter? (Parmeterized cursor)
To display the details of employees belonging to department no 10 getting
salary>5000.
declare
cursor c1(p1 number) is
select empno,ename,sal,deptno from semp where deptno=p1;
currec c1%rowtype;
begin
open c1(10);
loop
fetch c1 into currec;
if c1%found then
if currec.sal>5000 then
dbms_output.put_line(currec.empno||' '||currec.ename||' '||currec.sal||' '||currec.deptno);
end if;
else
exit;
end if;
end loop;
close c1;
end;
210. Write query list the names of employees, who are more than 5 years old in the organization.
Select ename from emp where(sysdate – hiredate)>(5*365);
211. Write all employees who have at least one person reporting to them.
Select empno,ename,job,deptno from emp e where exists(select empno from emp where
emp.mgr=e.empno)
order by empno;
212. Write a query to create a table from another table without duplicate rows.
Create table bb as select distinct * from b;
556. Can u use more than one return type in stored function?
Yes, We can use more than one return type in stored function.
222. What is output of this query? Select 1 from dual union select a from dual.
OUTPUT: ERROR at line 1:
ORA-00904: "A": invalid identifier
223. What is output of this query? Select * from emp where rownum<=10.
It will display first 10 records.
224. What is output of this query? Select * from emp where rownum<10
It will display first 9 records.
225. Number, Number (4,2),Number(6). Here Number(i.e,first one) data type can accept decimal
or not?
ANS: Yes, Number data type can accept decimal number.
226. Write a query to display three employees records are having equal salaries.
Select * from megus where sal=all(select sal from megus where sal=17500);
(OR)
Select * from megus where sal in(select sal from megus where sal=17500)
227. Write a query to display even records (All columns) from emp table.
Select empno,ename,job,mgr,hiredate,sal,comm,deptno from(select
empno,ename,job,mgr,hiredate,sal,comm,deptno,
mod(rownum,2)a from emp) where a=0;
228. Write a query to display odd records (All columns) from emp table.
Select empno,ename,job,mgr,hiredate,sal,comm,deptno from(select
empno,ename,job,mgr,hiredate,sal,comm,deptno,
mod(rownum,2)a from emp) where a=1;
234. In SQL function for emp table of hiredate column which three statements are correct.
(a)select count(hiredate) from emp
(b)select avg(hiredate) from emp
(c)select max(hiredate) from emp
(d)select sum(hiredate) from emp
(e)select min(hiredate) from emp
ANS:- a, c, e
239. Select ename from emp where ename like ‘_A%’ What is result of this query?
ENAME
----------
WARD
MARTIN
JAMES
241. How can you import from text file to database? Which command using?
We can import from text file to database through TOAD tool using IMP command.
251. We declared three procedures in the package specification section. But we used only two
procedures in the package body. Will it
show Errors? Ans: No, It will not show error.
252. How can you link two tables without foreign key?
Using join we can link two tables.
255. We declared two procedures in the package specification. But we implemented three
procedures in package body. It will show
error or not? Ans:- No, It will not show error.
262. Write a query to count all jobs and employees different data values in a column.
select deptno,sum(decode(job,'ANALYST',1,0))ANALYSTS,
sum(decode(job,'CLERK',1,0))CLERKS,
sum(decode(job,'MANAGER',1,0))MANAGERS,
sum(decode(job,'PRESIDENT',1,0))PRESIDENT,
sum(decode(job,'SALESMAN',1,0))SALESMANS,
count(decode(job,'ANALYST',1,'CLERK',1,'MANAGER',1,'PRESIDENT',1,
'SALESMAN',1)) TOTAL from emp group by deptno
266. How can you add not null constraint into a table? Say the syntax.
At first To add a column with NOT NULL constraint, the table must be empty.
Alter table <table_name> modify <column_name data type(size)> not null;
Example:- Alter table test modify no number not null;
272. How do you transfer the data from a excel table to sql table.
TOAD atmosphere is a tool. We can do all activities as such like that oracle.
273. How much maximum arguments can you pass in parameter list of procedure?
2100
277. Write syntax for creation of foreign key constraint and alteration of foreign key constraint.
Creation of foreign key constraint:-
Create table <table_name>(col1 data type references <table_name>(column_name)
Example:-
Create table test4(emp_no number(6) references test3(emp_no)
Alteration of foreign key constraint:-
Alter table <table_name> add constraint <constraint_name> foreign key<column_name>
references<table_name><column_name>;
Example:- Alter table b_detail add constraint jj foreign key(no) references
a_mast(no);
Alteration of On-Delete-Cascade constraint:-
Alter table order_master add constraint fk_code foreign key(vencode) references
vendor_master(vencode)
On delete cascade;
278. The following procedure will be executed or not? If is it not executed what error will
throw?
Declare
vname emp.ename%type;
Begin
select ename into vname from emp;
end;
ANS:- It will not executed. It will throw exact fetch returns more than requested
number of rows
288. To find the total amount of each sales person which should be more than the maximum
amount for the following table?
SNAME AMOUNT
A 4000
B 2000
A 2000
C 3000
C 2000
B 2000
Select sum(amount) from stable having sum(amount)>(select max(amount) from
stable)group by sname;
290. One table is created using create command, after we will not give commit statement. Table
is stored or not.
Table is stored. Because DDL commands are automatically committed.
294. {
{
{
{
{
}
}
}
}
}
We wrote a procedure like this. At the compile time it will show error at third loop. But third
loop is not a program, that is a
comment line. Next time the control, where it will be go.
Ans: It will go to previous loop.
318. After deleted values into a table, we give truncate. What is output? The values are available
on the table or not.
Ans: The values are not available.
319. Which of the below data dictionary views will tell you whether a given procedure valid or
not.
(a)user_procedure B)user_object (c)user_object_status (d)user_source.
333. A view is created from multiple tables. How do u know tables of this view?
Select * from user_views; (through this query)
347. You have a table in which 10 columns are there. In all the ten columns you have the index.
Which of the following is related to?
1. Insert values are faster.
2. Update values are slower.
3. Select operations can be done faster.
4. Delete operations can not be done.
Ans: Select operations can be done faster.
350. What is output of this query? Select count (1) from dual;
Ans: COUNT(1)
---------
1
351. What is output of this query? Select 1 from dual;
Ans:- 1/1
356. What is output of this query? Select 1 from dual union select 1 from dual;
Ans:- 1
----------
1
REPLACE('AMBE
-------------
Ambrrrrrrrkar
Translate:- Translate returns char with all occurrences of each character in from string replaced
by its corresponding character in to string.
SQL> select translate('ambedkar','ed','rrrrrrr') from dual;
TRANSLAT
---------------
Ambrrkar
362. Write query to display empname,comm from employee, if employee has no commission put
commission is empty.
Select ename,comm,nvl(comm,0) from emp;
363. One view is created from multiple tables, client how do you know columns of tables (Which
tables)
Select * from user_views;
364. Write a query who got more than the avg sal from emp.
Select * from emp where sal>all(select avg(sal) from emp group by deptno);
365. Write query to display employee name and empno, who are reporting to king.
Select a.empno,a.ename,b.empno,b.ename from emp a, emp b where a.mgr=b.empno and
b.ename='KING';
369. Write a query unique job for all employees in the deptno is 30 and locate loc the column.
Select distinct a.job,b.loc from emp a,dept b where a.deptno=b.deptno and a.deptno=30;
370. What is use of local and global index? Difference between local and global index?
Local and Global indexes are used in partitioned tables. Local index is partitioned index and
Global index is non-partitioned index.
376. You are used stored procedure and package in your project? Which is one is best?
Package.
1
377. What is Self-referential Integrity constraint?
If a foreign key references a parent key of the same table is called self-referential
integrity constraint.
384. A table is created. After created tables the values are inserted to it, after updated some
columns, after deleted two rows. Now we
want to give rollback. What is result?
Ans:- no rows selected
388. Two tables are there. One is emp and another one is dept. I want all records of emp table as
well as i want record of dept table of
dept no 10 only. Write the query for the above result.
Select a.*,b.* from emp a, dept b where a.deptno=10 and b.deptno=10;
389. Can you include and implement one procedure into package?
Yes, We can include and implement one procedure into package.
395. If you truncate the table, what will happen corresponding view?
Ans: No rows selected.
396. In public procedures are a1, a2, a3. Now they are series a3, a1, a2. Now can u call
procedure a2 into a1?
Yes, We can do. Create or replace procedure a1
is
begin
----
a2();
end a1;
409. After creating a table, we inserted some values into the table and then update some values. I
want commit "insert" only. How?
1. insert statement
2. using savepoint <savepoint name>
3. update statement
4. Rollback to <savepoint name>(refer to step 2)
5. commit.
Disadvantages of trigger:
1. Writing more number of codes.
2. It is easy to view table relationships, constraints, indexes, stored procedure in database
but triggers are difficult to view.
3. Triggers execute invisible to client-application. They are not visible or can be traced in
debugging code.
4. It is hard to follow their logic as it they can be fired before or after the database
insert/update happens.
5. It is easy to forget about triggers and if there is no.
6. Documentation it will be difficult to figure out for new developers for their existence.
7. Triggers run every time when the database fields are updated and it is overhead on
system. It makes system run slower.
417. What are the return values of functions SQLCODE and SQLERRM?
These are built-in functions. SQLCODE returns current error code. SQLERRM returns
current error message.
420. What is output of this query: select empno,ename from depts union select deptno,dname
from dept
EMPNO ENAME
---------- --------------
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
EMPNO ENAME
---------- --------------
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
18 rows selected.
421. What is output of this query: Select ename, empno from emp union select
dname,deptno,loc from dept.
It will not be executed because query block has incorrect number of result columns.
424. What is output of this query? Select 1 from a where 1=2; (Here a is table)
Ans: no rows selected
425. What is output of this query? Select * from emp,dept where 1=2;
Ans: no rows selected
428. Write query for the following tables use left outer join and right outer join.
T1;
C1 C2
------ -----
1 aa
2 bb
3 cc
4 dd
5 ee
6 ff
T2;
C1 C2
------- -----
1 a
3 b
5 c
7 d
C1 C2 C1 C2
---------- ---------- -----
1 aa 1a
3 cc 3b
5 ee 5c
6 ff
4 dd
2 bb
430. Write a query to get the sum of salary of each department for each job. By using table emp.
TABLE: EMP
----------------------
EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
---------- -----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3500
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
SAMPLE OUTPUT
------------------------
-- JOB SUM_DEPT10 SUM_DEPT20 SUM_DEPT30 SUM_DEPT40
-- --------- ---------- ---------- ----------
--------------------------------------------------------------------------------------------------
-- ANALYST 6000
-- CLERK 1300 1900 950
-- MANAGER 2450 2975 2850
-- PRESIDENT 5000
-- SALESMAN 5600
ANSWER:
SELECT job, sum(decode(deptno,10,sal)) DEPT10,
sum(decode(deptno,20,sal)) DEPT20,
sum(decode(deptno,30,sal)) DEPT30,
sum(decode(deptno,40,sal)) DEPT40
FROM scott.emp GROUP BY job
Table: Store_Information
------------------------------------
store_name Sales Date
---------------------------------------------------
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-08-1999
Table: Geography
------------------------
region_name store_name
----------------------------------------
East Boston
East New York
West Los Angeles
West San Diego
Answer 1.1:
SELECT store_name, SUM(Sales)FROM Store_Information GROUP BY store_name
Result1:
-------
store_name Sales
----------------------------------
Los Angeles 1800
San Diego 250
Boston 700
Answer 1.2:
SELECT A1.region_name REGION, SUM(A2.Sales) SALES FROM Geography A1,
Store_Information A2
WHERE A1.store_name = A2.store_name GROUP BY A1.region_name
Result2:
--------
REGION SALES
----------------------------------
East 700
West 2050
Answer 1.3:
SELECT A1.store_name, SUM(A2.Sales) SALES FROM Geography A1,
Store_Information A2
WHERE A1.store_name = A2.store_name (+) GROUP BY A1.store_name
Result3:
--------
store_name SALES
----------------------------------
Boston 700
New York
Los Angeles 1800
San Diego 250
Answer 1.1:
CREATE INDEX IDX_CUSTOMER_LAST_NAME on CUSTOMER (Last_Name)
Answer 1.2:
CREATE INDEX IDX_CUSTOMER_LOCATION on CUSTOMER (City, Country)
433. Write pl/sql coding for updating emp table using cursor?
declare
Cursor for_cur is select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp where
empno=7369
cust_no for_cur%rowtype;
begin
for cust_no in for_cur loop
update emp_emp set comm=1000 where empno=cust_no.empno;
end loop;
end;
434. Wrtie a stored procedure gets the employee code as parameter, check the value is exists in
the table. Should write exception the
value is there or not.
Create or replace procedure test_proc(emp_no in number)
is
emp_name varchar2(20);
emp_job varchar2(20);
emp_mgr number;
emp_hiredate date;
emp_sal number;
emp_comm number;
emp_deptno number;
begin
select ename,job,mgr,hiredate,sal,comm,deptno into
emp_name,emp_job,emp_mgr,emp_hiredate,
emp_sal,emp_comm,emp_deptno from emp where empno=emp_no;
exception
when no_data_found then
dbms_output.put_line('This record is not available here');
end;
TRUNC(1049,-3)
--------------
1000
443. Select * from(select ename from emp)a where---this query execute or it will throw
any error.
Yes, This query will be executed.
Example:- Select * from(select ename from emp)where rownum<=3;
444. Write query to find more than 5 employees from two tables?
SQL> select a.ename,a.empno,b.deptno,b.dname from emp a, dept b where
a.deptno=b.deptno;
445. What result in count(*) and count(empno) from emp will give same result?
Count(*) count all including null. But count(empno) count except nullable value.
447. The following program, after executing exception, control will go to procedure or
not?
declare
emp_name emp.ename%type;
begin
select ename into emp_name from emp where empno=7399;
test(20);
exception
when no_data_found then
dbms_output.put_line('record not found');
end;
Ans: After executing exception control will come out this program.
453. A table has no data; i want insert data to that table. How can u insert data into that
table through pl/sql?
begin
insert into a1 values(2,'ravi');
end;
454. Now u delete a table sample. After deleting this table a new table sample1 is created and
values are also inserted. Now u want
give rollback. Now sample table have data values or not.
No, Sample table have no data values. (After applying ddl commands previous work
autocomitted)
455. Now u delete a table sample. After deleting this table, insert values for another one table
sample1 (Already created table, but it
has no data). Now u want give rollback. Now sample table have values or not.
Yes, Sample table have data values. But Sample1 table have no data values.
456. How do u populate data, from one table to another table using pl/sql table?
declare
valueinsert table1%rowtype;
type itemtype is table of table1%rowtype index by binary_integer;
item_tab itemtype;
i binary_integer:=0;
begin
for valueinsert in (select * from table1)
loop
i:=i+1;
item_tab(i).id:=valueinsert.id;
item_tab(i).name:=valueinsert.name;
insert into table2 values(item_tab(i).id,item_tab(i).name);
end loop;
end;
457. Program:-
Declare
i_number number not null:=200;
begin
i_number:=100;
dbms_output.put_line(‘The value of i_number’||i_number);
end;
Output of Program:-
1. 1 2. 100 3. No output 4. Error 5. Can not determined
Ans: 100
458. Create sequence test increment by 1 start with 1 maxvalue 10 minvalue 1 cycle cache 4;
Here what is mean of ‘cache’? What is use of ‘cache’?
Ans:- Cache means buffer memory. The cache pre-allocates a set of sequence numbers
and retains them in memory.
Example(2):-
declare
i number(10):=null;
j number(10):=null;
begin
if i=j then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
INSTR('AMBEDKAR','E',1,2)
-------------------------
0
465. What is output of this query?
SQL> select substr('this is the',6) from dual;
SUBSTR
------
is the
Ans:
SQL> select * from a;
A
----------
1
2
3
4
5
6
7
8
9
469. What is output of this query?
declare
i number;
begin
i:=i+1;
for i in 1..100 loop
exit when i>100;
end loop;
i:=i+1;
end;
Ans: NULL
472. What is difference between on commit delete rows and on commit preserve rows?
After creation of both tables we apply commit statement, on commit delete rows data are deleted.
But on commit preserve rows data are not deleted.
476. Can u create referential constraint for not null column of parent table?
No, We can not create referential constraint for not null column of parent table.
478. What are physical database structure objects and logical database structure objects?
Physical database structure objects are data file, control file and redo log file. Logical database
structure objects are tables, views, sequences, indexes, procedure, function and packages.
489. Write names for Date function, Numeric function, Character function, Conversion function
and Miscellaneous function.
Date functions:
Add_months,Last_day,Months_between,Round,Next_day,Truncate,Greatest and New_time.
Character functions: Initcap, Lower, Upper, Ltrim, Rtrim, Translate, Replace, Length,
Decode and Concatenation operator.
Numeric functions: Abs, Ceil, Cos, Cosh, Exp, Floor, Power, Mod, Round, Trunc, Sign
and Sqrt.
Conversion functions: To_Char, To_date and To_number.
Miscellaneous functions: Uid,User,NVL and Vsize.
Group functions: Average, Minimum, Maximum, Sum, Count, Group by and Having
clause.
490. Create a package specification and package body called PROD_PACK that contains
ADD_PROD, UPD_PROD,DEL_PROD
procedures and Q_PROD function.
begin
happyfamily(2020202020):='ELI';
happyfamily(-15070):='Steven';
happyfamily(-90900):='Chris';
happyfamily(88):='Veva';
l_row:=happyfamily.first;
while(l_row is not null)
loop
dbms_output.put_line(happyfamily(l_row));
l_row:=happyfamily.next(l_row);
end loop;
end;
517. What is difference between column level constraint and table level constraint?
In the column level constraints, constraints names are given by system. But table level
constraitns, constraint names are given by user.
526. We created a sequence for a table. We inserted more records that table. Now we want give
rollback. Now sequence is rollbacked
or not?
Only records are rollbacked. But sequence not rollbacked.
529. How many indexes can you create for a single table?
We can create maximum 255 indexes for a single table.
531. When will you write procedure? And When will you write a function?
If you want perform a task write procedure. If you want computer a value write function.
Note: The coalesce function will compare each value, one by one.
546. What is difference between anonymous block and non anonymous block?
1. Anonymous blocks are unnamed PL/SQL blocks. Non Anonymous blocks are named
PL/SQL blocks. Ex. Subprograms.
2. Anonymous blocks can not be called from other pl/sql blocks. But Non Anonymous
blocks can be called from other pl/sql
block.
3. Anonymous blocks are not stored in database. But Non Anonymous blocks are stored in
database.
4. Anonymous blocks are beginning with keyword is DECLARE or BEGIN. But Non
Anonymous blocks are started with
keyword is CREATE.
547. What are the pre-requisites to modify column and data type of table?
To modify data type of a column the column must be empty. To add a column with NOT NULL
constraint, table
must be empty.
548. Can you write having clause without using group by function?
No, We can not write having function without using group by function.
554. As applications can develop to include increasingly richer semantics, they encounter the
need to deal with the
following kinds of data:
(a) Simple structured data - It can be fit into simple tables.
(b) Complex structured data-collections, references, user-defined types.
(c) Semi-structured data-Advanced Queueing, deal with Messages.
(d) Unstructured data -text, graphic images, still video clips, full motion video, and sound
waveforms .
555. Can you declare or define more than one cursor in a procedure?
Yes, We can declare or define more than one cursor in a procedure.
Add a comment
Classic
Flipcard
Magazine
Mosaic
Sidebar
Snapshot
Timeslide
Recent
Date
Label
Author
Cluster Definition
Cluster Definition
Jan 29th
Normalization with Example
Normalization with Example
Jan 29th
Ref Cursor Example
Ref Cursor Example
Jan 28th
RAISE_APPLICATION_ERROR
RAISE_APPLICATION_ERROR
Jan 28th
Wrapping - PL/SQL
Wrapping - PL/SQL
Jan 28th
Procedure - PL/SQL
Procedure - PL/SQL
Jan 26th
Cursor - PL/SQL
Cursor - PL/SQL
Jan 26th
Nested Blocks - Pl/SQL
Nested Blocks - Pl/SQL
Jan 26th
Function - Pl/SQL
Function - Pl/SQL
Jan 25th
EXECUTE IMMEDIATE in PL/SQL
EXECUTE IMMEDIATE in PL/SQL
Jan 25th
DataGuard General Questions
DataGuard General Questions
Nov 21st
Creating a duplicate database with different name using RMAN
Creating a duplicate database with different name using RMAN
Nov 17th
ORA-01031: INSUFFICIENT PRIVILEGES
ORA-01031: INSUFFICIENT PRIVILEGES
Nov 17th
ORA-00845: MEMORY_TARGET not supported on this system
ORA-00845: MEMORY_TARGET not supported on this system
Nov 17th
RMAN INCREMENTAL BACKUP
RMAN INCREMENTAL BACKUP
Nov 16th
changing the hostname Solaris 11
changing the hostname Solaris 11
Nov 16th
Simple Backup and Recovery using RMAN
Simple Backup and Recovery using RMAN
Nov 16th
ORA-00205: error in identifying controlfile
ORA-00205: error in identifying controlfile
Nov 15th
Configuring Network Adapter in Solaris 11
Configuring Network Adapter in Solaris 11
Nov 15th
How to enable SSH Root Login In Solaris 11
How to enable SSH Root Login In Solaris 11
Nov 15th
Manually Cloning an Existing Oracle Database on Linux
Manually Cloning an Existing Oracle Database on Linux
Nov 15th
E-mail Address Validation and Domain Name Extraction
E-mail Address Validation and Domain Name Extraction
May 23rd
SQL join types
SQL join types
May 22nd
1Z0-146 Exam Guide
1Z0-146 Exam Guide
May 22nd 1
The SQLJ loadjava Utility
The SQLJ loadjava Utility
May 21st
SecureFiles: The New LOBs
SecureFiles: The New LOBs
May 21st
Oracle PL/SQL Interview Question and Answers
Oracle PL/SQL Interview Question and Answers
May 18th
Zend Core for Oracle v2
Zend Core for Oracle v2
May 14th
Transportable Tablespaces
Transportable Tablespaces
May 14th
SQL Developer 3.1 Scheduler (DBMS_SCHEDULER) Support
SQL Developer 3.1 Scheduler (DBMS_SCHEDULER) Support
May 14th
SQL Developer 3.1 Data Pump Wizards
SQL Developer 3.1 Data Pump Wizards
May 14th
Schema Owners and Application Users
Schema Owners and Application Users
May 14th
Stored Outlines and Plan Stability
Stored Outlines and Plan Stability
May 14th
Renaming or Moving Oracle Files
Renaming or Moving Oracle Files
May 14th
Recompiling Invalid Schema Objects
Recompiling Invalid Schema Objects
May 14th
Reclaiming Unused Space in Datafiles
Reclaiming Unused Space in Datafiles
May 14th
Partitioning an Existing Table using DBMS_REDEFINITION
Partitioning an Existing Table using DBMS_REDEFINITION
May 13th
Partitioning an Existing Table using EXCHANGE PARTITION
Partitioning an Existing Table using EXCHANGE PARTITION
May 13th
OS Authentication
OS Authentication
May 13th
OS Backup Commands
OS Backup Commands
May 13th
Oracle Shell Scripting
Oracle Shell Scripting
May 13th
Oracle Network Configuration
Oracle Network Configuration
May 13th
Oracle Naming Conventions
Oracle Naming Conventions
May 13th
Measuring Storage Performance For Oracle Systems
Measuring Storage Performance For Oracle Systems
May 13th
Identifying Host Names and IP Addresses
Identifying Host Names and IP Addresses
May 13th
Direct and Asynchronous I/O
Direct and Asynchronous I/O
May 13th
Killing Oracle Sessions
Killing Oracle Sessions
May 12th
Deadlocks
Deadlocks
May 12th
CBO and DBMS_STATS
CBO and DBMS_STATS
May 12th
Basic Security Measures for Oracle
Basic Security Measures for Oracle
May 12th
Loading