Oracle Notes
Oracle Notes
CREATE TRIGGER comm_change BEFORE UPDATE ON emp FOR EACH ROW WHEN (NEW.job NOT IN (‘MANAGER’,
’PRESIDENT’ ))
BEGIN IF (:new.comm < 5000 ) THEN raise_application_error(-20300,‘check commission’);END IF;END;
DELETE FROM emp WHERE deptno = (SELECT MAX(deptno)+1 FROM dept ); IF SQL%NOTFOUND THEN
RAISE_APPLICATION_ERROR(-20345,’No candidate with such department number’);
TYPE type_name IS TABLE OF [NOT NULL] { column_type | variable%TYPE | table.column % TYPE } [ INDEX BY
BINARY_INTEGER ] ;
identifier type_name ;
EXISTS(n) true if nth element in a PL/SQL table exists COUNT the number of elements of table
FIRST smallest index number in a table LAST largest index number in a table
PRIOR(n) index number that precedes index n NEXT(n) index number that succeeds index n
TRIM removes one element from the end of table TRIM (n) n elements from end of table are removed
DELETE removes all elements from table DELETE(m) mth element is removed from table
DELETE(m,n) all elements in range m..n are removed from table
Procedure/Function
Execute as a PL/SQL statement Invoke as part of an expression
Do not contain RETURN clause in the header Must contain a RETURN clause in the header
Can contain a RETURN statement Must contain at least one RETURN statement
Can return none, one, or more values Must return a single value
• Top-n-anlysis SELECT ROWNUM as Rank, last_name, salary FROM ( SELECT last_name,salary FROM employees ORDER BY salary DESC) WHERE
ROWNUM <=3;
select * from emp e where 1 = (select count(distinct salary) from emp e1 where e1.salary >=e.salary)
External table
CREATE TABLE emp_ext
( empcode NUMBER(4), empname VARCHAR2(25),
job VARCHAR2(25))
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY personnel
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ‘,’)
LOCATION ('emp.txt') )
REJECT LIMIT UNLIMITED;
• ADD_MONTHS(dt, n)
• LAST_DAY(d)
• MONTHS_BETWEEN(d1, d2)
• NEW_TIME(d, z1, z2) -- PST, AST, etc.
• NEXT_DAY(d, dayname)
• ROUND(d, fmt) -- century, year etc.
• SYSDATE
• TRUNC(d, fmt) -- century, year, etc.
LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE
• NVL( expr1, expr2)
• NVL2(expr1, expr2, expr3)
• NULLIF(expr1, expr2)
• COALESCE(expr1, expr2,…..,exprn)
• SELECT CASE ‘a’ WHEN ‘b’ THEN ‘hello b’ WHEN ‘a’ THEN ‘hello a’ ELSE ‘hello somebody’ END hello FROM DUAL;
• SELECT DECODE(‘A’,’B’,’HELLO B’,’A’,’HELLO A’,’HELLO X’) HELLO FROM DUAL;
• LOB s are used to store large unstructured data such as text, graphic images, films, and sound waveforms.
• There are four large object data types :
- BLOB Binary large object video clip
- CLOB Character large object large text
- NCLOB Multi byte character large object
- BFILE Binary file Movie
• They are characterized
- According to interpretation character, binary
- According to storage aspects internal, external
http://www.100webspace.com/ http://www.10
0webspace.com/
Oracle Concepts and Architecture Database Structures.
1. What are the components of Physical database structure of Oracle Database?.
ORACLE database is comprised of three types of files. One or more Data files, two are more Redo Log files, and one or
more Control files.
2. What are the components of Logical database structure of ORACLE database?
Tablespaces and the Database's Schema Objects.
3. What is a Tablespace?
A database is divided into Logical Storage Unit called tablespaces. A tablespace is used to grouped related logical
structures together.
4. What is SYSTEM tablespace and When is it Created?
Every ORACLE database contains a tablespace named SYSTEM, which is automatically created when the database is
created. The SYSTEM tablespace always contains the data dictionary tables for the entire database.
5. Explain the relationship among Database, Tablespace and Data file.
Each databases logically divided into one or more tablespaces One or more data files are explicitly created for each
tablespace.
6. What is schema?
A schema is collection of database objects of a User.
7. What are Schema Objects ?
Schema objects are the logical structures that directly refer to the database's data. Schema objects include tables, views,
sequences, synonyms, indexes, clusters, database triggers, procedures, functions packages anddatabase links.
8. Can objects of the same Schema reside in different tablespaces.?
Yes.
9. Can a Tablespace hold objects from different Schemes ?
Yes.
10. what is Table ?
A table is the basic unit of data storage in an ORACLE database. The tables of a database hold all of the user accessible
data. Table data is stored in rows and columns.
11. What is a View ?
A view is a virtual table. Every view has a Query attached to it. (The Query is a SELECT statement that identifies the
columns and rows of the table(s) the view uses.)
12. Do View contain Data ?
Views do not contain or store data.
13. Can a View based on another View ?
Yes.
14. What are the advantages of Views ?
Provide an additional level of table security, by restricting access to a predetermined set of rows and columns of a table.
Hide data complexity.
Simplify commands for the user.
Present the data in a different perpecetive from that of the base table.
Store complex queries.
15. What is a Sequence ?
A sequence generates a serial list of unique numbers for numerical columns of a database's tables.
16. What is a Synonym ?
A synonym is an alias for a table, view, sequence or program unit.
17. What are the type of Synonyms?
There are two types of Synonyms Private and Public.
18. What is a Private Synonyms ?
A Private Synonyms can be accessed only by the owner.
19. What is a Public Synonyms ?
A Public synonyms can be accessed by any user on the database.
20. What are synonyms used for ?
Synonyms are used to : Mask the real name and owner of an object.
Provide public access to an object
Provide location transparency for tables,views or program units of a remote database.
Simplify the SQL statements for database users.
select empno,ename,sal,rownum from (select empno,ename,sal from emp order by sal desc)
where rownum < 5;