Você está na página 1de 24

Loose Questions

What is Mutating Trigger?

Mutating Table: A mutating table is a table that is currently being modified by an UPDATE DELETE or INSERT
statement or a table that might need to be updated by the effects of a declarative DELETE CASCADE referential
integrity action. A table is not considered mutating for STATEMENT triggers.

The triggered table itself is a mutating table as well as any table referencing it with the FOREIGN KEY constraint.
This restriction prevents a row trigger from seeing an inconsistent set of data.

The Oracle mutating trigger error occurs when a trigger references the table that owns the trigger.
The best way to avoid this error is use autonomous transaction in triggers so that the child
transaction will be independent of the parent transaction.

Why we use PL/SQL array rather than cursor?

PL/SQL array is a collection through which we can iterate just the way we can through cursor. But in case
of Cursor the context switching is for every row fetched while for associative array the context switching
will be once (using bulk collect). It's the performance which is different.

How to calculate Retirement Date in Oracle?

create table test(empno number,dob date,hiredate date)

insert into test values(1001,to_date('15-Aug-1947','dd-mon-yyyy'),to_date('15-Aug-1972','dd-mon-yyyy'))

retirement '15-Aug-2007'

select * from test

EMPNO DOB HIREDATE


-------------------------------------- ------------------ ------------------
1001 1957-08-15 1982-08-15

select round(((sysdate-dob)/365),2) Years from test

YEARS
--------------------------------------
58.56

select 60-round(((sysdate-dob)/365),2)Years from test

YEARS
--------------------------------------
1.44
If query is running slow on Production Database, what are the steps needed to be checked?

Indexes need to be checked. If Indexes are being used or not. Or if indexes are not present then need to create
index.

Check if Hint is used or not.


Check Statistics
Check if Sudden Bulk Volume of Data is there.
Check AWR Report for details

How to Improve Performance?


==> This can be done by using Bulk Collection, ForAll which avoids context switching. Using
Materialized Views as data can be accessed from local database.

How Materialized View is affecting Performance?

a. Earlier Query was hitting Remote Database, after using Materialized View, it is hitting local database only. This
helps to Improve Performance.

b. Dynamic Query converted to static query.

When should one rebuild an index?

You can run the ANALYZE INDEX <index> VALIDATE STRUCTURE command on the affected indexes - each
invocation of this command creates a single row in the INDEX_STATS view. This row is overwritten by the next
ANALYZE INDEX command, so copy the contents of the view into a local table after each ANALYZE. The
'badness' of the index can then be judged by the ratio of 'DEL_LF_ROWS' to 'LF_ROWS'.

For example, you may decide that index should be rebuilt if more than 20% of its rows are deleted:

select del_lf_rows * 100 / decode(lf_rows,0,1,lf_rows) from index_stats


where name = 'index_ name';

However, generally speaking, indexes should not be rebuilt because performance will be degraded for a
considerable time afterwards. The issue is that after rebuild, all blocks are full up to the percent free setting.
Subsequent DML will therefore cause many block splits, until the index stabilizes with an appropriate amount of
free space.

What is Cartesian product?

http://www.tutorialspoint.com/sql/sql-cartesian-joins.htm

The CARTESIAN JOIN or CROSS JOIN returns the Cartesian product of the sets of records from the two or more
joined tables. Thus, it equates to an inner join where the join-condition always evaluates to True or where the join-
condition is absent from the statement.

How to Wrap a Package on Command Prompt?


Run a command Prompt from start Button. Go to the Path where your Package exists.

e.g. cd C:\Laxman\Daily_Work\2015\Feb-15\10Feb15\04.05.04.03_Hot_fix_05_Local_Copy\DB

Write following command

wrap iname=EC_ITEM_CLEARING_PKG.PKB oname=EC_ITEM_CLEARING_PKG.plb

http://javarevisited.blogspot.in/2012/12/top-10-oracle-interview-questions-and-answers-database-sql.html

Question 1: Oracle version 9.2.0.4.0 what does each number refers to?

Answer: oracle version number refers

9-Major database release number


2-Database Maintenance release number
0-Application server release number
4-Component Specific release number
0-Platform specific release number
Question 2: How do you find current date and time in oracle?

Answer: This is one of the frequently asked Oracle Interview questions. I have seen this question every now and
then. By the way SYSDATE function is used in oracle to find current date and time of operating system on which
the database is running return type of function is DATE

Syntax: SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "Current_Date" FROM DUAL.

Question 3: Write the syntax to find current date and time in format “YYYY-MM-DD”.

Answer: SELECT TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS') "Current_Date" FROM DUAL

Question 4: How will you convert a date to char in Oracle give one example?

Answer :. to_char() function is used to convert date to character we can specify format also in which we want the
output.

SELECT to_char( to_date('11-01-2012', 'DD-MM-YYYY') , 'YYYY-MM-DD') FROM dual;

or

SELECT to_char( to_date('11-01-2012, 'DD-MM-YYYY') , 'DD-MM-YYYY') FROM dual;

Question 5: What is bulk copy or BCP in oracle?

Answer: BCP or bulk copy tool is one type of command line tool for unload data from database came into
existence after oracle 8. It is used to import or export data from tables and views but it will not copy structure of
data same. Main advantage is fast mechanism for copying data and we can take backup of important data
easily.

Question 6: What are the extensions used by oracle reports?

Answer: Oracle reports are used to make business enable to provide information of all level within or outside in
secure way. REP file and RDF file extensions are used by oracle report.

Question 7: What is Save Points in Oracle database?

Answer: SAVE POINTS are used to divide a transaction into smaller parts. It enables rolling back part of a
transaction. Maximum of five save points are allowed. Whenever we encounter error we can rollback from the
point where we set our SAVEPOINT. This is useful for multistage transaction and conditional transaction where
commit and rollback depend on certain condition.

Question 7: a) How many save points can be used in oracle?


https://in.answers.yahoo.com/question/index?qid=20111215194917AALe2hm

 I don't know. I assume there must be some sort of limit: just check out the Oracle manuals.

I have two remarks however:


- save points have nothing to do with stored procedures.
- I don't know of anyone using save points. It is one of those rarely used features that are in the product
but have little use.

You can create unlimited savepoints in your transaction. There is no fix limit. Do you
have any fix limitation on number of transactions? No. Just like this there is also no
limit to create savepoints between transactions.

Question 8: How will you convert string to a date in oracle database?

Answer: to_ date function is used to convert string to a date function.

Syntax : to_date(string, format)

Example: to_date('2012/06/12', 'yyyy/mm/dd') It will return June 12, 2012

Question 9: What is hash cluster in Oracle?

Answer: Hash cluster is one of the techniques to store the table in a hash cluster to improve the performance
of data retrieval .We apply hash function on the table row’s cluster key value and store in the hash cluster. All
rows with the same hash key value are stores together on disk. Key value is same like key of index cluster, for
data retrieval Oracle applies the hash function to the row's cluster key value.

Question 10: What is Snap shot in Oracle database?


Answer: Snapshots are read-only copies of a master table located on a remote node
which is periodically refreshed to reflect changes made to the master table.
How to find second highest salary in SQL or

How to find duplicate records in table


http://javarevisited.blogspot.com/2012/12/top-10-oracle-interview-questions-and-answers-database-
sql.html#ixzz41jFCJri3

http://java67.blogspot.in/2012/10/difference-between-clustered-vs-nonclustered-index-sql-database.html

What is difference between Clustered and Nonclustered Indexes in SQL - Database?

Indexes are very important concept, it makes your queries to run fast and if you compare a SELECT
query which uses an indexed column to one who doesn't, you will see big difference in performance.
There can be two kinds of indexes in relational database Clustered and Nonclustered
indexes.

Clustered index determines physical sorting order of rows in a table similar to entries on yellow
pages which are sorted on alphabetical order. Suppose you have a table Employee, which contains
emp_id as primary key then clustered index which is created on primary key will sort the
Employee table as per emp_id.Nonclustered index involves one extra step which point
to physical location of record.

1) Clustered Index physically sort all rows while Nonclustered Index doesn't.

2) In SQL one table can only have one Clustered Index but there is no such restriction
on NonClustered Index.

3) In many relational databases Clustered Index is automatically created on primary


key column.

Read more: http://java67.blogspot.com/2012/10/difference-between-clustered-vs-nonclustered-index-sql-


database.html#ixzz41jJva0bT

What is the difference between Replace and Translate?

Translate does character by character substitution, where as replace can substitute a single character with a
word.

Write a query to display alternate records from the employee table?

To Display even row numbers


---------------------------
select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp )

To Display odd row numbers


---------------------------
select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp )

http://career.guru99.com/top-50-oracle-interview-questions-and-answers/

Top 50 Oracle Interview Questions and Answers


http://career.guru99.com/top-50-oracle-interview-questions-and-answers/ -
respondhttp://career.guru99.com/category/database/http://career.guru99.com/author/admin/

/top-50-oracle-interview-questions-and-answers/?format=pdfDownload PDF

1. Difference between varchar and varchar2 data types?

Varchar can store upto 2000 bytes and varchar2 can store upto 4000 bytes. Varchar will occupy space for NULL
values and Varchar2 will not occupy any space. Both are differed with respect to space.

2. In which language Oracle has been developed?

Oracle has been developed using C Language.

3. What is RAW datatype?

RAW datatype is used to store values in binary data format. The maximum size for a raw in a table in 32767 bytes.

4. What is the use of NVL function?

The NVL function is used to replace NULL values with another or given value. Example is –

NVL(Value, replace value)

5. Whether any commands are used for Months calculation? If so, what are they?

In Oracle, months_between function is used to find number of months between the given dates. Example is –

Months_between(Date 1, Date 2)

6. What are nested tables?

Nested table is a data type in Oracle which is used to support columns containing multi valued attributes. It also
hold entire sub table.

7. What is COALESCE function?

COALESCE function is used to return the value which is set to be not null in the list. If all values in the list are null,
then the coalesce function will return NULL.
Coalesce(value1, value2,value3,…)

8. What is BLOB datatype?

A BLOB data type is a varying length binary string which is used to store two gigabytes memory. Length should be
specified in Bytes for BLOB.

9. How do we represent comments in Oracle?

Comments in Oracle can be represented in two ways –

1. Two dashes(–) before beginning of the line – Single statement


2. /*—— */ is used to represent it as comments for block of statement
10. What is DML?

Data Manipulation Language (DML) is used to access and manipulate data in the existing objects. DML
statements are insert, select, update and delete and it won’t implicitly commit the current transaction.

11. What is the difference between TRANSLATE and REPLACE?

Translate is used for character by character substitution and

Replace is used to substitute a single character with a word.

12. How do we display rows from the table without duplicates?

Duplicate rows can be removed by using the keyword DISTINCT in the select statement.

13. What is the usage of Merge Statement?

Merge statement is used to select rows from one or more data source for updating and insertion into a table or a
view. It is used to combine multiple operations.

14. What is NULL value in oracle?

NULL value represents missing or unknown data. This is used as a place holder or represented it in as default
entry to indicate that there is no actual data present.

15. What is USING Clause and give example?

The USING clause is used to specify with the column to test for equality when two tables are joined.

Select * from employee join salary using employee ID

Employee tables join with the Salary tables with the Employee ID.

16. What is key preserved table?


A table is set to be key preserved table if every key of the table can also be the key of the result of the join. It
guarantees to return only one copy of each row from the base table.

17. What is WITH CHECK OPTION?

The WITH CHECK option clause specifies check level to be done in DML statements. It is used to prevent changes
to a view that would produce results that are not included in the sub query.

18. What is the use of Aggregate functions in Oracle?

Aggregate function is a function where values of multiple rows or records are joined together to get a single value
output. Common aggregate functions are –

 Average

 Count

 Sum

19. What do you mean by GROUP BY Clause?

A GROUP BY clause can be used in select statement where it will collect data across multiple records and group
the results by one or more columns.

20. What is a sub query and what are the different types of subqueries?

Sub Query is also called as Nested Query or Inner Query which is used to get data from multiple tables. A sub
query is added in the where clause of the main query.

There are two different types of subqueries:

 Correlated sub query

A Correlated sub query cannot be as independent query but can reference column in a table listed in the from list
of the outer query.

 Non-Correlated sub query

This can be evaluated as if it were an independent query. Results of the sub query are submitted to the main
query or parent query.

21. What is cross join?

Cross join is defined as the Cartesian product of records from the tables present in the join. Cross join will
produce result which combines each row from the first table with the each row from the second table.

22. What are temporal data types in Oracle?


Oracle provides following temporal data types:

 Date Data Type – Different formats of Dates

 TimeStamp Data Type – Different formats of Time Stamp

 Interval Data Type – Interval between dates and time

23. How do we create privileges in Oracle?

A privilege is nothing but right to execute an SQL query or to access another user object. Privilege can be given as
system privilege or user privilege.

GRANT user1 TO user2 WITH MANAGER OPTION;

24. What is VArray?

VArray is an oracle data type used to have columns containing multivalued attributes and it can hold bounded
array of values.

25. How do we get field details of a table?

Describe <Table_Name> is used to get the field details of a specified table.

26. What is the difference between rename and alias?

Rename is a permanent name given to a table or a column whereas Alias is a temporary name given to a table or
column. Rename is nothing but replacement of name and Alias is an alternate name of the table or column.

27. What is a View?

View is a logical table which is based on one or more tables or views. The tables upon which the view is based are
called Base Tables and it doesn’t contain data.

28. What is a cursor variable?

A cursor variable is associated with different statements which can hold different values at run time. A cursor
variable is a kind of reference type.

29. What are cursor attributes?

Each cursor in Oracle has set of attributes which enables an application program to test the state of the cursor.
The attributes can be used to check whether cursor is opened or closed, found or not found and also find row
count.

30. What are SET operators?

SET operators are used with two or more queries and those operators are Union, Union All, Intersect and Minus.
31. How can we delete duplicate rows in a table?

Duplicate rows in the table can be deleted by using ROWID.

32. What are the attributes of Cursor?

Attributes of Cursor are

 %FOUND

Returns NULL if cursor is open and fetch has not been executed
Returns TRUE if the fetch of cursor is executed successfully.
Returns False if no rows are returned.
 %NOT FOUND

Returns NULL if cursor is open and fetch has not been executed
Returns False if fetch has been executed
Returns True if no row was returned
 %ISOPEN

Returns true if the cursor is open


Returns false if the cursor is closed
 %ROWCOUNT

Returns the number of rows fetched. It has to be iterated through entire cursor to give exact real count.
33. Can we store pictures in the database and if so, how it can be done?

Yes, we can store pictures in the database by Long Raw Data type. This datatype is used to store binary data for
2 gigabytes of length. But the table can have only one Long Raw data type.

34. What is an integrity constraint?

An integrity constraint is a declaration defined a business rule for a table column. Integrity constraints are used to
ensure accuracy and consistency of data in a database. There are types – Domain Integrity, Referential Integrity
and Domain Integrity.

35. What is an ALERT?

An alert is a window which appears in the center of the screen overlaying a portion of the current display.

36. What is hash cluster?

Hash Cluster is a technique used to store the table for faster retrieval. Apply hash value on the table to retrieve
the rows from the table.
37. What are the various constraints used in Oracle?

Following are constraints used:

 NULL – It is to indicate that particular column can contain NULL values

 NOT NULL – It is to indicate that particular column cannot contain NULL values

 CHECK – Validate that values in the given column to meet the specific criteria

 DEFAULT – It is to indicate the value is assigned to default value

38. What is difference between SUBSTR and INSTR?

 SUBSTR returns specific portion of a string and INSTR provides character position in which a pattern is
found in a string.
 SUBSTR returns string whereas INSTR returns numeric.

39. What is the parameter mode that can be passed to a procedure?

IN, OUT and INOUT are the modes of parameters that can be passed to a procedure.

40. What are the different Oracle Database objects?

There are different data objects in Oracle –

 Tables – set of elements organized in vertical and horizontal

 Views – Virtual table derived from one or more tables

 Indexes – Performance tuning method for processing the records

 Synonyms – Alias name for tables

 Sequences – Multiple users generate unique numbers

 Tablespaces – Logical storage unit in Oracle

41. What are the differences between LOV and List Item?

LOV is property whereas list items are considered as single item. List of items is set to be a collection of list of
items. A list item can have only one column, LOV can have one or more columns.

42. What are privileges and Grants?

Privileges are the rights to execute SQL statements – means Right to connect and connect. Grants are given to
the object so that objects can be accessed accordingly. Grants can be provided by the owner or creator of an
object.
43. What is the difference between $ORACLE_BASE and $ORACLE_HOME?

Oracle base is the main or root directory of an oracle whereas ORACLE_HOME is located beneath base folder in
which all oracle products reside.

44. What is the fastest query method to fetch data from the table?

Row can be fetched from table by using ROWID. Using ROW ID is the fastest query method to fetch data from the
table.

45. What is the maximum number of triggers that can be applied to a single table?

12 is the maximum number of triggers that can be applied to a single table.

46. How to display row numbers with the records?

Select rownum, <fieldnames> from table;

This query will display row numbers and the field values from the given table.

47. How can we view last record added to a table?

Select * from (select * from employees order by rownum desc) where rownum<2;

48. What is the data type of DUAL table?

The DUAL table is a one-column table present in oracle database. The table has a single VARCHAR2 (1) column
called DUMMY which has a value of ‘X’.

49. What is difference between Cartesian Join and Cross Join?

There are no differences between the join. Cartesian and Cross joins are same.

Cross join gives cartesian product of two tables – Rows from first table is multiplied with another table which
is called cartesian product.

Cross join without where clause gives Cartesian product.

50. How to display employee records who gets more salary than the average salary in the department?

Select * from employee where salary>(select avg(salary) from dept, employee where dept.deptno =
employee.deptno;

http://techpreparation.com/computer-interview-questions/oracle-interview-questions-
answers35.htm#.VtaljRHlrIU

Oracle Interview Questions and Answers


http://www.orafaq.com/wiki/Interview_Questions

Interview Questions
http://www.javatpoint.com/oracle-interview-questions

http://stackoverflow.com/questions/14722883/what-is-the-maximum-number-of-columns-allowed-in-a-table

What is the maximum number of columns allowed in a table?

What is the maximum number of columns allowed in an Oracle table, in the following versions?

For versions 8i, 9i, 10g, and 11g, the limit is 1,000 columns per table.
Prior to that, Oracle 7 had a 254 column limit.
For Oracle 11g:
1000 Columns per table
32 columns per index
We said...
No, you may have upto 1,000 columns in a table these days.

If you have more than 255 - they will be stored in multiple row pieces (like a
chained row - the first 255 point to the next 255 point to the next 255 and so on)

http://stackoverflow.com/questions/2520871/what-is-the-limit-on-number-of-columns-in-oracle-10g-
and-derby-databases

What is the limit on number of columns in Oracle 10G and Derby Databases

2520939 Per table 1000 columns maximum


ed

Per index (or clustered index) 32 columns maximum

Per bitmapped index 30 columns maximum

What is the default port number for Oracle? 1520

http://www.red-database-security.com/whitepaper/oracle_default_ports.html

Service Port Product How to change

Oracle Net Listener / Enterprise Oracle Application Server / Edit listener.ora and
1521
Manager Repository port Oracle Database restart listener

http://thesprawl.org/research/oracle-default-ports/
Port# Name Description

1520- TNS TNS Listener (Transparent Network Substrate) serves as a main


1530 Listener communication point for Oracle. 1521 is the default port in this range.

How to increase the size of a table in oracle?

http://stackoverflow.com/questions/3452902/how-to-increase-the-size-of-a-table-in-oracle

3452902 i have a table "DEPT" , let me know how to increase the size of a table.

Are you talking about increasing the size of the TableSpace?

Here is the command for that

alter database datafile '<full_file_name>' resize <size>M;

ALTER DATABASE DATAFILE '/u01/oradata/userdata01.dbf' RESIZE 500M;

How to Test Oracle Connectivity?

Testing the Oracle Service Name

The TNSPING utility can be used to test an Oracle Service Name. To use it:
1.Open a Command Prompt (click Start, click Run, type cmd, and then click OK).
2. Type tnsping <service name> (for Oracle 7.3 or Oracle 8i and later) or tnsping80 <service
name> (for Oracle 8.0), and then press enter.

What is the sequence of steps in which the query gets executed? How is the query executed at the
back-end by the database engine?

http://searchoracle.techtarget.com/answer/SELECT-query-sequence-of-execution

select min(price)from items_ordered group by item having item='Tent'

How is the query executed at the back-end by the database engine?

FROM
WHERE
GROUP BY
HAVING
SELECT
ORDER BY

The first step is always the FROM clause. In your case, this is pretty straight-forward, because there's only
one table, and there aren't any complicated joins to worry about. In a query with joins, these are evaluated in
this first step. The joins are assembled to decide which rows to retrieve, with the ON clause conditions being
the criteria for deciding which rows to join from each table. The result of the FROM clause is an
intermediate result. You could think of this as a temporary table, consisting of combined rows which satisfy
all the join conditions. (In your case the temporary table isn't actually built, because the optimizer knows it
can just access your table directly without joining to any others.)

The next step is the WHERE clause. In your case, you don't have one, so the optimizer knows that it must
retrieve all the rows from the intermediate result. In a query with a WHERE clause, each row in the
intermediate result is evaluated according to the WHERE conditions, and either discarded or retained.

Next comes the GROUP BY. If there's a GROUP BY clause, the intermediate result is now partitioned into
groups, one group for every combination of values in the columns in the GROUP BY clause. In your case, all
the rows in each group have the same item. You can think of the partitioning as a sort, although a sort may not
actually be involved if the intermediate result is already in item sequence (which happens when the rows
retrieved by the FROM clause are accessed in item sequence via an index).

Now comes the HAVING clause. The HAVING clause operates once on each group, and all rows from
groups which do not satisfy the HAVING clause are eliminated. In your case, something very interesting
happens here. After having laboriously assembled (and possibly sorted) an entire intermediate result table, the
optimizer now throws away all rows in every group except the group where the item is 'Tent' (a word on this
later). In any case, after the HAVING clause has filtered the groups, a new intermediate result set is produced,
and in this new intermediate result, there is only one row per group. This single row per group is allowed to
have only the following types of columns:

 any of the columns in the GROUP BY clause

 aggregate functions operating on any other columns in the first intermediate result

Next comes the SELECT. From the rows of the new intermediate result produced by the GROUP BY and
HAVING clauses, the SELECT now assembles the columns it needs. In particular, none of the columns in the
original tables are available unless they are in the GROUP BY clause. In your case, you are selecting
min(price), which, since it is an aggregate function, is a valid column coming from the GROUP BY and
HAVING process.

Finally, the last step is the ORDER BY clause. In your case, there isn't one. In queries with both a GROUP
BY and ORDER BY clause, you can reference columns in the ORDER BY only if they are in the new
intermediate result produced by the grouping process, i.e. columns in the GROUP BY or aggregate functions
(or expressions based on these).

Remember the interesting result I mentioned earlier? What I'd like you to do is run through these steps again,
but this time, imagine that your HAVING condition (item='Tent') were written as a WHERE condition
instead, and see if that might make a difference to what happens as the query is executed.

http://www.bennadel.com/blog/70-sql-query-order-of-operations.htm

SQL Query Order of Operations


1. FROM clause
2. WHERE clause
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause

Logical Database Limits:

https://docs.oracle.com/cd/B28359_01/server.111/b28320/limits003.htm

Item Type of Limit Limit Value


Tables Maximum per clustered table 32 tables

Tables Maximum per database Unlimited

What is Parallel Sql?

Using parallel SQL with Oracle parallel hint to improve database performance

Enhance customers' Oracle database performance by using parallel SQL with an Oracle parallel hint,
enabling a SQL statement to be simultaneously processed by multiple threads or processes.
Parallel SQL enables a SQL statement to be processed by multiple threads or processes
simultaneously.

Today's widespread use of dual and quad core processors means that even the humblest of modern
computers running an Oracle database will contain more than one CPU. Although desktop and laptop
computers might have only a single disk device, database server systems typically have database files
spread— striped—across multiple, independent disk devices. Without parallel technology— when a
SQL statement is processed in serial—a session can make use of only one of these CPUs or disk
devices at a time. Consequently, serial execution of a SQL statement cannot make use of all the
processing power of the computer. Parallel execution enables a single session and SQL statement to
harness the power of multiple CPU and disk devices.

Parallel processing can improve the performance of suitable SQL statements to a degree that is often not
possible by any other method. Parallel processing is available in Oracle Enterprise Edition only.

SELECT *
FROM sh.customers
ORDER BY cust_first_name, cust_last_name, cust_year_of_birth

If executing without the parallel query option, a single process would be responsible for fetching all the
rows in the CUSTOMERS table. The same process would be responsible for sorting the rows to satisfy
the ORDER BY clause.

We can request that Oracle execute this statement in parallel by using the PARALLEL hint:

SELECT /*+ parallel(c,2) */ *


FROM sh.customers c
ORDER BY cust_first_name, cust_last_name, cust_year_of_birth

If parallel processing is available, the CUSTOMERS table will be scanned by two processes in parallel.
A further two processes will be employed to sort the resulting rows. A final process—the session that
issued the SQL in the first place—combines the rows and returns the result set. The process that requests
and coordinates the parallel processing stream is the Query coordinator.

Oracle supports parallel processing for a wide range of operations, including queries, DDL, and DML:

•Queries that involve table or index range scans


•Bulk insert, update, or delete operations
•Table and index creation
•The collection of object statistics using DBMS_STATS (see Chapter 7, "Optimizing the Optimizer")
•Backup and recovery operations using Recovery Manager (RMAN)

Parallel SQL
•Using parallel SQL to improve Oracle database performance
•Parallel processing: Using parallel SQL effectively
•Parallel execution: Determining SQL suitability, benefits
What is the Difference between Clustered and Non-Clustered Table?

https://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:4941517587762

You Asked
Is fetching row(s) using Primary key Index (in where clause) is better than Fetching row(s) using Unique
Index (in where clause)?
Is there any internal difference between those Unique Index and Primary Key Index?
and we said...
There is no such thing as a "primary key index".
A primary key is two things:
a. assures the values in a column(s) are unique
b. assures they are NOT NULL
A primary key under the covers will use either a UNIQUE or NON-UNIQUE index. If the
primary key is deferrable it'll use a non-unique index. If the column(s) are already
indexed with a non-unique index, the primary key constraint will rely on that index.
Otherwise a primary key will happen to create a unique index.

Hence, there is no real difference here. Under the covers there will be either a unique or non-unique
index.
By all means -- if something is a primary key CALL IT THAT. Don't use a unique index,
use the primary key constraint.

https://decipherinfosys.wordpress.com/2007/07/04/back-to-the-basics-difference-between-primary-key-and-
unique-index/

What is the Difference between Primary Key and Unique Index?

Both can be declared on one or more columns, both can be used to enforce foreign keys (if the unique
index is on not null column(s)), both can be declared as clustered/non clustered indexes (SQL Server
lingo), both can be used on computed columns as well (SQL Server).

The differences between the two are:

1. Column(s) that make the Primary Key of a table cannot be NULL since by definition; the Primary Key
cannot be NULL since it helps uniquely identify the record in the table. The column(s) that make up the
unique index can be nullable.
2. There can be only one Primary Key defined on the table where as you can have many unique indexes
defined on the table (if needed).
3. Also, in the case of SQL Server, if you go with the default options then a Primary Key is created as a
clustered index while the unique index (constraint) is created as a non-clustered index. This is just the
default behavior though and can be changed at creation time, if needed.

So, if the unique index is defined on not null column(s), then it is essentially the same as the Primary Key
and can be treated as an alternate key meaning it can also serve the purpose of identifying a record
uniquely in the table.

Can Oracle database handle very huge data volume?

 around 500gb - 700gb


Oracle can handle (theoretically) up to 8 exabyte data (8 millions terabytes), so 500-700 Gigabytes is not
so huge....

 . Re: Can Oracle database handle very huge data volume?

Roy,
Its actualy not "such a huge data".You have still not crossed 1TB.There are many shops who are running
databases or more than 10TBs even.There wont be any problem with the performance if the deployment
of both the db and the application is done optimally.As for the question that whether Oracle can stand or
not with this volume,surely it can.
Aman....

http://stackoverflow.com/questions/1487886/database-design-question-how-to-handle-a-huge-amount-of-
data-in-oracle

How to handle a huge amount of data in Oracle? (Database design question)

I have over 1.500.000 data entries and it's going to increase gradually over time. This huge amount
of data would come from 150 regions.

Now should I create 150 tables to manage this increasing huge data? Will this be efficient? I need
fast operation. ASP.NET and Oracle will be used.

5 Also, 1.5 million data entries is not that much. – Jack Marchetti Sep 28 '09 at 16:12

1487927 If all the data is the same, don't split it in to different tables. Take a look at Oracle's
table partitions. One-hundred fifty partitions (or more) split out by region (or
more) is probably more in line with what you're going to be looking for.

What is the difference between Bulk Collect & Cursor?


Cursor resides in our temp tablespace but as we bulk collect into some collection and this collection
resides in the computer memory (RAM). So while using cursor we should consider about our temp
tablespace and while using Bulk collect we should consider about server RAM.

Can we use commit or rollback command in the exception part of PL/SQL block?

Yes, we can use the TCL commands (commit/rollback) in the exception block of a stored procedure/function. The
code in this part of the program gets executed like those in the body without any restriction. You can include any
business functionality whenever a condition in main block (body of a proc/func) fails and requires a follow-thru
process to terminate the execution gracefully!

Yes we can use commit/rollback in exception part. Example:


DECALRE
…..
BEGIN
…….
EXCEPTION
WHEN NO_DATA_FOUND THEN

INSERT INTO err_log(


err_code, code_desc)
VALUES(‘1403’, ‘No data found’)

COMMIT;
RAISE;
END

Yes , we can use commit or rollback in exception part of PL SQL Block .


Below is an anonymous PL SQL block , try this :

Declare
myexception EXCEPTION;
Begin
RAISE myexception;
EXCEPTION
When myexception then
insert into table_name values (......);
COMMIT;

insert into table_name values (.......);


ROLLBACK;
END;

What are the conditions which decide whether to use a table or a view or a materialized view?
1. Security reasons we can use view.
2. If there is more transaction in a base table we better chose materialized view for performance.
3. Depend upon the situation where we need to refresh the data in specific time interval.

=====================

Table is the basic entity in any RDBMS, so for storing data you need table.

For view - if you have complex query from which you want to extract data again and again; moreover it is a
standard data which is required by many other users; also for REPORTS generation then create view . Avoid
inserting / updating / deleting through view unless it is essential. Keep view as read only (FOR SHOWING
REPORTS)

For materialized view - this view is mainly used in data warehousing. if you have two databases and you want a
view in both databases, remember in data warehousing we deal in GB or TB datasize. So create a summary table
in a database and make the replica (materialized view) in other database.

When to create materialized view-

[1] if data is in bulk and you need same data in more than one database then create summary table at one
database and replica in other databases.

[2] if you have summary columns in projection list of query.

Main advantages of materialized view over simple view are -

[1] It save data in database whether simple view's definition is saved in database

[2] Can create partition or index on materialize view to enhance the performance of view, but cannot on simple
view.

What is nologging?

http://www.dba-oracle.com/t_nologging_append.htm

The nologging option is a great way to speed-up inserts and index creation. It bypasses the writing of the
redo log, significantly improving performance. However, this approach is quite dangerous if you need to
roll-forward through this time period during a database recovery. In nologging mode you are running
without a safety net when you run nologging operations and you must:

 Backup before and after - You must take a backup, both before and after all nologging
operations
 Only nologging operations during the nologging window - Between the backups (the
nologging processing window), ONLY nologging operations should be run in the middle of this
"backup sandwich".

What is Cast Function?

http://www.techonthenet.com/oracle/functions/cast.php
In Oracle/PLSQL, the cast function converts one datatype to another. Syntax :

cast ( { expr | ( subquery ) | MULTISET ( subquery ) } AS type_name )

Note : The following casts are allowed:

TO FROM
char, number datetime raw rowid, nchar,
varchar2 / interval urowid nvarchar2
char, varchar2 X X X X X
number X X
datetime / interval X X
raw X X
rowid, urowid X X
nchar, nvarchar2 X X X X X

Applies To Oracle 11g, Oracle 10g, Oracle 9i

For Example : select cast('22-Aug-2003' AS varchar2(30)) from dual;

This would convert the date (ie: 22-Aug-2003) into a varchar2(30) value.

What is the Difference between PROCEDURE and FUNCTION?

We can't have any DDL DML and TCL command inside a function if that function is called from a
query.But if the function is not called from query then we can have all transactional statement(DDL
DML and TCL ) inside a function.

1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not
return a value or may return more than one value using the OUT parameter.

2. Function can be called from SQL statements where as procedure can not be called from the sql
statements

3. Functions are normally used for computations where as procedures are normally used for executing
business logic.

4. You can have DML (insert,update, delete) statements in a function. But, you cannot call such a
function in a SQL query.

5. A Function returns 1 value only. Procedure can return multiple values (max 1024).
6. Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that
uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during
creation but runtime throws error Function wont support deferred name resolution.

7. Stored procedure returns always integer value by default zero. where as function return type could be
scalar or table or table values

8. Stored procedure is precompiled execution plan where as functions are not.

9. A procedure may modify an object where a function can only return a value The RETURN statement
immediately completes the execution of a subprogram and returns control to the caller.

What is Normalization?

http://www.devshed.com/c/a/MySQL/An-Introduction-to-Database-Normalization/

Normalization is the process of efficiently organizing data in a database. There are two goals of the
normalization process:

Eliminating redundant data (for example, storing the same data in more than one table) and ensuring data
dependencies make sense (only storing related data in a table). Both of these are worthy goals as they
reduce the amount of space a database consumes and ensure that data is logically stored

This link is important: http://databases.about.com/od/specificproducts/a/normalization.htm

Re: Explain 1st, 2nd, 3rd normalization form of data base

Answer

 1st normal form: first identify the repeating group of fields n group them into separate table
 2nd normal form: it should be in 1st normal form and check all fields are dependent on primary
key
 3nd normal form: it should be in 2nd normal form and Remove columns that are not dependent
upon the primary key.

What is the result when size of char and varchar2 datatypes is same and different?

declare
A char(10):='Laxman';
B varchar2(10):='Laxman';
begin
if A=B then
dbms_output.put_line('char and varchar are equal');
else
dbms_output.put_line('char and varchar are NOT equal');
end if;
end;

===> char and varchar2 are NOT equal.

declare
A char(6):='Laxman';
B varchar2(6):='Laxman';
begin
if A=B then
dbms_output.put_line('char and varchar are equal');
else
dbms_output.put_line('char and varchar are NOT equal');
end if;
end;

==> char and varchar are equal.

Conclusion: When size of char and varchar2 datatypes is same then both the assigned values are equal.
When size of char and varchar2 are different then the assigned values are not equal.

Você também pode gostar