- What is an oracle instance?
- What is a view?
- What is referential integrity?
- Name the data dictionary that stores user-defined constraints?
- What is a collection of privileges?
- What is a snapshot?
- What is a synonym?
- What is a cursor?
- What is a sequence?
- What is a trigger?
- What is an exception?
- What is a partition of table?
- What are pseudo-columns in SQL? Provide examples.
- What are the Data Control statements?
- What is a schema?
- What is a type?
- What is a data model?
- What is a relation?
- Advantages of redo log files?
- What is an Archiver?
- What is a database buffer cache?
- What are the background processes in Oracle?
- %type and %rowtype are attributes for…?
- What are the steps in a two-phase commit?
- What is a union, intersect, minus?
- What is a join, explain the types of joins?
- What is a co-related sub-query?
- ODBC stands for…?
- Data-type used to work with integers is?
- Describe data models?
- Describe the Normalization principles?
- What are the types of Normalization?
- What is de-normalization?
- To see current user name
Sql> show user;
- Change SQL prompt name
SQL> set sqlprompt “Manimara > “
- Switch to DOS prompt
- How do I eliminate the duplicate rows ?
SQL> delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);
SQL> delete duplicate_values_field_name dv from table_name ta where rowid <(select min(rowid) from table_name tb where ta.dv=tb.dv);
delete ename from emp a where rowid < ( select min(rowid) from emp b where a.ename = b.ename);
The output like,
- How do I display row number with records?
To achive this use rownum pseudocolumn with query, like SQL> SQL> select rownum, ename from emp;
- Display the records between two range
select rownum, empno, ename from emp where rowid in
(select rowid from emp where rownum <=&upto
select rowid from emp where rownum<&Start);
Enter value for upto: 10
Enter value for Start: 7
- ROWNUM EMPNO ENAME
--------- --------- ----------
1 7782 CLARK
2 7788 SCOTT
3 7839 KING
4 7844 TURNER
- I know the nvl function only allows the same data type(ie. number or char or date Nvl(comm, 0)), if commission is null then the text “Not Applicable” want to display, instead of blank space. How do I write the query?
- SQL> select nvl(to_char(comm.),'NA') from emp;
- Output :
- Oracle cursor : Implicit & Explicit cursors
Oracle uses work areas called private SQL areas to create SQL statements.
PL/SQL construct to identify each and every work are used, is called as Cursor.
For SQL queries returning a single row, PL/SQL declares all implicit cursors.
For queries that returning more than one row, the cursor needs to be explicitly declared.
- Explicit Cursor attributes
There are four cursor attributes used in Oracle
cursor_name%Found, cursor_name%NOTFOUND, cursor_name%ROWCOUNT, cursor_name%ISOPEN
- Implicit Cursor attributes
Same as explicit cursor but prefixed by the word SQL
- SQL%Found, SQL%NOTFOUND, SQL%ROWCOUNT, SQL%ISOPEN
- Tips : 1. Here SQL%ISOPEN is false, because oracle automatically closed the implicit cursor after executing SQL statements.
: 2. All are Boolean attributes.
- Find out nth highest salary from emp table
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
- Enter value for n: 2
- To view installed Oracle version information
SQL> select banner from v$version;
- Display the number value in Words
SQL> select sal, (to_char(to_date(sal,'j'), 'jsp'))
the output like,
- SAL (TO_CHAR(TO_DATE(SAL,'J'),'JSP'))
800 eight hundred
1600 one thousand six hundred
1250 one thousand two hundred fifty
If you want to add some text like,
Rs. Three Thousand only.
SQL> select sal "Salary ",
(' Rs. '|| (to_char(to_date(sal,'j'), 'Jsp'))|| ' only.'))
"Sal in Words" from emp
Salary Sal in Words
800 Rs. Eight Hundred only.
1600 Rs. One Thousand Six Hundred only.
1250 Rs. One Thousand Two Hundred Fifty only.
- Display Odd/ Even number of records
Odd number of records:
select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);
Even number of records:
select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp)
- Which date function returns number value?
- Any three PL/SQL Exceptions?
Too_many_rows, No_Data_Found, Value_Error, Zero_Error, Others
- What are PL/SQL Cursor Exceptions?
- Other way to replace query result null value with a text
SQL> Set NULL ‘N/A'
to reset SQL> Set NULL ‘'
- What are the more common pseudo-columns?
SYSDATE, USER , UID, CURVAL, NEXTVAL, ROWID, ROWNUM
- What is the output of SIGN function?
1 for positive value,
0 for Zero,
-1 for Negative value.
- What is the maximum number of triggers, can apply to a single table?