Oracle Questions

Q:

How can we read and write operating system files from PL/SQL program?

Answer

The UTL_FILE database package can be used to read and write operating system files. You need to have read /write access rights in that directory before the package can be used.


Example to write file:


Fhandler is a variable of type UTL_FILE.FILE_TYPE


UTL_FILE.PUTF(fHandler, 'Im writing to a file\n');


 


Example to read file:


UTL_FILE.GET_LINE(fHandler, buf);

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

0 1564
Q:

Explain Not Null constraint.

Answer

Oracle NOT NULL is used on a column to ensure that the value for that column can never be NULL.
Example:
Below, the constraint is that the id should never be NULL. If it is, oracle throws an error.
create table employee ( id number NOT NULL, Name varchar(200) );

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

0 1564
Q:

What are Cursors? Explain Types of cursors in PL/SQL

Answer

Cursors help you manipulate the information retrieved by select statements. This can be done by assigning a name to the cursor.


Example:


CURSOR emp_cur 


IS 


SELECT emp_number from employee_tbl where employee_name = name_in;


Types of Cursors:


Implicit cursors- These cursors are not declared by the programmer. They are issued when the SQL statement is executed. The open, close and fetching is done by itself.


Example:


UPDATE employee SET salary = salary * 2.1;


Here, an implicit cursor is issued to identify the set of rows in the table which would be affected by the update.


 


Explicit cursors- These cursors are defined by programmer. They are used in queries that return multiple rows.


Example:


CURSOR emp_cur 


IS 


SELECT emp_number from employee_tbl where employee_name = name_in;

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

1 1556
Q:

What is a PL/SQL Record data type?

Answer

A record data type represents a data type for that row in a database table. It lets u define your own records and not your own fields.

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

0 1552
Q:

What are the basic SQL*Plus commands?

Answer

1) START- Used to run a SQL script.
2) ACCEPT- Accepts input from user.
3) GET- Gets the sql file from user to place in buffer.
4) LIST- Displays the last command executed.
5) RUN- Used to list and run the command in buffer
6) SHOW- Shows the environment settings. Example: SHOW PAGESIZE

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

0 1518
Q:

How to Add a new column to an existing table?

Answer

New column can be added using the ALTER TABLE command as shown below:
Example:
ALTER TABLE employee ADD DateOfBirth date

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

0 1463