Oracle Database

  Home  Oracle  Oracle Database


“Learn Oracle database programming with hundreds of Interview Questions and Answers and examples and get a better job as an Oracle DBA with this basic and advance Oracle Database Interview Questions and Answers guide”



430 Oracle Database Questions And Answers

301⟩ How To Export Data to a CSV File?

If you want to export data from a table to a file in CSV format, you can use the following steps:

► Right-click the table name, EMPLOYEES, in the object tree view.

► Select Export.

► Select CSV. The Export Data window shows up.

► Click Format tab.

► Select Format as: CSV.

► Enter File as: empMyTeam.csv.

► Click Columns tab.

► Check columns: FIRST_NAME, LAST_NAME, MANAGER_ID

► Click Where tab.

► Enter Where clause as: MANAGER_ID=100.

► Click Apply.

Your CSV file, empMyTeam.csv, is ready. Open it, you will see:

"FIRST_NAME","LAST_NAME","MANAGER_ID"

"Gerald","Cambrault","100"

"Lex","De Haan","100"

"Alberto","Errazuriz","100"

"Adam","Fripp","100"

"Michael","Hartstein","100"

"Payam","Kaufling","100"

"Neena","Kochhar","100"

...

CSV files can be open by Microsoft Excel.

 142 views

302⟩ What Is Oracle SQL Developer?

Oracle SQL Developer is a new, free graphical tool that enhances productivity and simplifies database development tasks. With SQL Developer, you can browse database objects, run SQL statements and SQL scripts, and edit and debug PL/SQL statements. You can also run any number of provided reports, as well as create and save your own.

Oracle SQL Developer is formerly called Project Raptor.

 130 views

304⟩ How To Download Oracle SQL Developer?

If you want to download a copy of Oracle SQL Developer, visit http://www.oracle.com/technology/software/products/sql/.

If you are using Windows systems, click the "Oracle SQL Developer for Windows" link. This allows you to download the Windows version in ZIP format with file name of sqldeveloper-v1.0.0.zip in 55,295,721 bytes.

 142 views

305⟩ How To Install Oracle SQL Developer?

Once you have sqldeveloper-v1.0.0.zip downloaded, extract the zip file into the root directory: .

When the extraction is done, the installation is completed. Your copy of Oracle SQL Developer is installed in directory: sqldeveloper, and ready to run.

 139 views

306⟩ What Is PL/SQL Language Case Sensitive?

PL/SQL language is not case sensitive:

► Reserved words are not case sensitive. For example: CASE and Case are identical.

► Variable names and other names are not case sensitive. For example: TOTAL_SALARY and total_salary are identical.

But values in string literals are case sensitive. For example: 'DBA' and 'dba' are different.

 138 views

307⟩ How To Place Comments in PL/SQL?

There are two ways to place comments into PL/SQL codes:

► SQL Statement Style: Starts you comment any where in the line but prefixed with '--'. The comment ends at the end of the line.

► C Language Style: Starts you comment any where in the line with '/*' and ends it with '*/' in the same line or some lines below.

Here is some example of PL/SQL comments:

BEGIN

-- This is a comment

/* To do:

Need to write some codes here

*/

END;

 127 views

308⟩ What Are the Types PL/SQL Code Blocks?

There are 3 types of PL/SQL code blocks:

► Anonymous Block - A block of codes with no name. It may contain a declaration part, an execution part, and exception handlers.

► Stored Program Unit - A block of codes with a name. It is similar to an anonymous block. But it can take parameters and return values.

► Trigger - A block of code that can be defined to fire based an specific event.

 142 views

309⟩ What Is an Anonymous Block?

An anonymous block is a PL/SQL code block with no name. It consists of three parts:

► Declaration Part - Defining local variables and local procedures. Declaration part is optional.

► Execution Part - Defining execution logic with executable statements. Execution part is required.

► Exception Part - Defining error handling logics. Exception part is optional.

Here how a complete anonymous block should look like:

DECLARE

-- Declaration statements

BEGIN

-- Executable statements

EXCEPTION

-- Error handling statements

END;

 120 views

310⟩ What Is a Named Program Unit?

A named program unit is a PL/SQL code block with an name. It consists of three parts:

► Declaration Part - Defining the program unit name, calling parameters, local variables and local procedures. Declaration part is required.

► Execution Part - Defining execution logic with executable statements. Execution part is required.

► Exception Part - Defining error handling logics. Exception part is optional.

There are two types of named program units:

► Procedure - Has no return values.

► Function - Has a return value.

 164 views

311⟩ What Is a Procedure?

A procedure is a named program unit. It consists of three parts:

► Declaration Part - Defining the procedure name, calling parameters, local variables and local procedures. Declaration part is required.

► Execution Part - Defining execution logic with executable statements. Execution part is required.

► Exception Part - Defining error handling logics. Exception part is optional.

Here how a complete procedure should look like:

PROCEDURE name (parameter_1, parameter_2) AS

-- Declaration statements

BEGIN

-- Executable statements

EXCEPTION

-- Error handling statements

END;

 125 views

312⟩ What Is a Function?

A function is a named program unit. It consists of three parts:

► Declaration Part - Defining the function name, calling parameters, return value type, local variables and local procedures. Declaration part is required.

► Execution Part - Defining execution logic with executable statements. Execution part is required.

► Exception Part - Defining error handling logics. Exception part is optional.

Here how a complete procedure should look like:

FUNCTION name (parameter_1, parameter_2) RETURN type AS

-- Declaration statements

BEGIN

-- Executable statements

RETURN value;

EXCEPTION

-- Error handling statements

END;

 126 views

313⟩ How To Declare a Local Variable?

A local variable can be defined in the declaration part with a declaration statement, which is a variable name followed a data type identifier. Below are some examples of declaration statements:

PROCEDURE proc_var_1 AS

domain VARCHAR2(80);

price REAL;

is_for_sale CHAR;

BEGIN

-- Executable statements

END;

 139 views

314⟩ How To Initialize Variables with Default Values?

There are two ways to assign default values to variables at the time of declaration:

► Using key word DEFAULT - Appending "DEFAULT value" to the end of declaration statements.

► Using assignment operator - Appending ":= value" to the end of declaration statements.

The script below show you some examples of declaration statements with default values:

PROCEDURE proc_var_1 AS

domain VARCHAR2(80) := 'rendc.org';

price REAL DEFAULT 999999.99;

is_for_sale CHAR := 'N';

BEGIN

-- Executable statements

END;

 149 views

315⟩ What Are the Arithmetic Operations?

There are 4 basic arithmetic operations on numeric values as shown in the following sample script:

PROCEDURE proc_arithmetic AS

addition NUMBER;

subtraction NUMBER;

multiplication NUMBER;

division NUMBER;

BEGIN

addition := 7 + 8;

subtraction := addition - 7;

multiplication := subtraction * 5;

division := multiplication / 8;

-- division should contain 5 now

END;

 139 views

316⟩ What Are the Numeric Comparison Operations?

PL/SQL supports 6 basic numeric comparison operations as shown in the following sample script:

PROCEDURE proc_comparison AS

res BOOLEAN;

BEGIN

res := 1 = 2;

res := 1 < 2;

res := 1 > 2;

res := 1 <= 2;

res := 1 >= 2;

res := 1 <> 2;

-- more statements

END;

 133 views

317⟩ How To Assign Values to Variables?

You can use assignment statements to assign values to variables. An assignment statement contains an assignment operator ":=", which takes the value specified on the right to the variable on left. The script below show you some examples of assignment statements:

PROCEDURE proc_var_2 AS

is_done BOOLEAN;

counter NUMBER := 0;

message VARCHAR2(80);

BEGIN

is_done := FASLE;

counter := counter + 1;

message := 'Hello world!';

END;

 132 views

318⟩ What Are the Logical Operations?

PL/SQL supports 3 logical operations as shown in the following sample script:

PROCEDURE proc_comparison AS

x BOOLEAN := TRUE;

y BOOLEAN := FALSE;

res BOOLEAN;

BEGIN

res = x AND y;

res = x OR y;

res = NOT x;

-- more statements

END;

 128 views

319⟩ How Many Categories of Data Types?

PL/SQL data types are grouped into 4 categories:

► Scalar Data Types: A scalar data type holds a single value.

► Composite Data Types: A composite data type has internal components, such as the elements of an array.

► LOB Data Types: A LOB data type holds a lob locator that specify the location of a large object.

► Reference Data Types: A reference data type holds a pointer that points to another data object.

 132 views

320⟩ How Many Scalar Data Types Are Supported in PL/SQL?

PL/SQL supports many scalar data types divided into 4 groups:

► Numeric Types: BINARY_DOUBLE, BINARY_FLOAT, BINARY_INTEGER, DEC, DECIMAL, DOUBLE PRECISION, FLOAT, INT, INTEGER, NATURAL, NATURALN, NUMBER, NUMERIC, PLS_INTEGER, POSITIVE, POSITIVEN, REAL, SIGNTYPE, SMALLINT.

► Character Types: CHAR, CHARACTER, LONG, LONG RAW, NCHAR, NVARCHAR2, RAW, ROWID, STRING, UROWID, VARCHAR, VARCHAR2.

► Boolean Types: BOOLEAN.

► Date Types: DATE, TIMESTAMP, TIMESTAMP WITH TIMEZONE, TIMESTAMP WITH LOCAL TIMEZONE, INTERVAL YEAR TO MONTH, INTERVAL DAY TO SECOND.

 144 views