Showing posts with label Oracle Interview Questions. Show all posts
Showing posts with label Oracle Interview Questions. Show all posts

How to find text in oracle stored procedure

USE : user_source table
select  * from user_source where type = 'PROCEDURE' and lower(text) like lower('%text%');

Oracle DECODE function

Oracle DECODE function


Oracle decode function allow to transform data values at retrieval time.

Syntax :

DECODE(expr, search, result
             [, search, result ]...
       [, default ]
      )

 Example :

 We have a column named Floor, with values of GF, FF, SF and TF. When we run SQL queries, we want to transform these values into Ground Floor, First Floor, Second Floor and Third Floor.


select
decode (
floor,
‘GF’,’Ground Floor’,
‘FF’,’First Floor’,
‘SF’,’Second Floor’,
‘TF’,’Third Floor’,
‘NOT KNOWN’
)
from
apartment;

What are few Oracle DDL statements or commands ?

Below are few  DDL commands to create, alter, drop, and rename tables.


CREATE TABLE


  • Create a table.
  • Create a table based on another table by using a subquery.


ALTER TABLE


  • Modify table structures.
  • Change column widths, change column data types, and add columns.


DROP TABLE




  • Remove rows and a table structure.
  • Once executed, this statement cannot be rolled back.


RENAME




  • Rename a table, view, sequence, or synonym.

TRUNCATE


  • Remove all rows from a table and release the storage space used by the table.
COMMENT


  •  Add a comment to a table or a column.
  • Query the data dictionary to view the comment.

Oracle 9i Tutorial : What is syntax of DELETE Statement Syntax


You can remove existing rows by using the DELETE statement.


Delete Statement Syntax below :

  DELETE [FROM]    table

  [WHERE    condition];


Oracle 9i Tutorial : UPDATE Statement Syntax

UPDATE Statement Syntax



Update Statement is used to modify existing rows in table.

Below is Update State Syntax :

UPDATE  table
SET  column = value [, column = value, ...]
[WHERE   condition];

In the syntax:
  table  is the name of the table
  column  is the name of the column in the table to populate
  value  is the corresponding value or subquery for the column
  condition  identifies the rows to be updated and is composed of column names   expressions, constants, subqueries, and comparison operators

Updating Rows in a Table

•Specific row or rows are modified if you specify the WHERE clause.
   •All rows in the table are modified if you omit the WHERE clause.
 

Updating Rows Based on Another Table

You can use subqueries in UPDATE statements to update rows in a table. The example on the slide updates the COPY_EMP table based on the values from the EMPLOYEES table. It changes the department number of all employees with employee 200’s job ID to employee 100’s current department number.

Oracle 9i Tutorial : INSERT Statement Syntax

INSERT Statement Syntax


INSERT statement is used to add new rows to table.


Syntax of INSERT statement below :


INSERT Statement Syntax








Only one row can be inserted at a time with this syntax.

INSERT statement can also be used for copying rows from another table.

Syntax below :

INSERT INTO table1 ( column11 , column12 , ..... )
SELECT column21 , column22 , .......
FROM
table2

 Example below :

Oracle 9i Tutorial : Data Manipulation Language

      Data Manipulation Language ( DML )


A DML statement is executed when you:

–Add new rows to a table

–Modify existing rows in a table

–Remove existing rows from a table

Transaction

A transaction consists of a collection of DML statements that form a logical unit of work.

Oracle 9i Tutorial : Adding Comments to Table

Adding a Comment to a Table

You can add a comment of up to 2,000 bytes about a column, table, view, or snapshot by using the COMMENT statement. The comment is stored in the data dictionary and can be viewed in one of the following data dictionary views in the COMMENTS column:
ALL_COL_COMMENTS
USER_COL_COMMENTS
ALL_TAB_COMMENTS
USER_TAB_COMMENTS
Syntax
    COMMENT ON TABLE table | COLUMN table.column
      IS 'text';
In the syntax:
  table  is the name of the table
 
column  is the name of the column in a table
 
text  is the text of the comment
You can drop a comment from the database by setting it to empty string (''):
    COMMENT ON TABLE  employees IS ' ';

Oracle 9i Tutorial : Drop,Rename and Truncate table

DROP TABLE

  Remove rows and a table structure.
  Once executed, this statement cannot be rolled   back.
  -DROP TABLE EMPLOYEE

RENAME

  Rename a table, view, sequence, or synonym.
  -RENAME EMPLOYEE TO EMPL;

TRUNCATE

  Remove all rows from a table and release the   storage space used by the table.
  The DELETE statement removes only rows.
  -TRUNCATE TABLE EMPLOYEE;

Oracle 9i Tutorial : ALTER TABLE Statement

 ALTER TABLE Statement

         After you create a table, you may need to change the table structure because: you omitted column, your column definition needs to be changed, or you need to remove columns. You can do this by using the ALTER TABLE statement.

Use the ALTER TABLE statement to:
•Add a new column
–Alter table employee add(manager number(4));
•Modify an existing column
–Alter table employee modify(empname varchar2(10));
•Define a default value for the new column
–Alter table employee modify(hiredate date default sysdate);
•Drop a column
                     - Alter table employee drop column manager;

Oracle 9i Tutorial : Creating a Table by Using a Subquery Syntax

Creating a Table  by Using a Subquery Syntax


•Create a table and insert rows by combining the CREATE TABLE statement and the AS subquery option.
•Match the number of specified columns to the number of subquery columns.
Define columns with column names and default values.


Creating a Table from Rows in Another Table
A second method for creating a table is to apply the AS subquery clause, which both creates the table and inserts rows returned from the subquery.
In the syntax:
  table  is the name of the table
  column  is the name of the column, default value, and integrity constraint
  subquery  is the SELECT statement that defines the set of rows to be inserted into   the new table
Guidelines
The table is created with the specified column names, and the rows retrieved by the SELECT statement are inserted into the table.
The column definition can contain only the column name and default value.
If column specifications are given, the number of columns must equal the number of columns in the subquery SELECT list.
If no column specifications are given, the column names of the table are the same as the column names in the subquery.
The integrity rules are not passed onto the new table, only the column data type definitions.
Example :

Oracle 9i Tutorial : Table and Data Dictionary

User Tables:

–Are a collection of tables created and maintained by the user
–Contain user information

Data Dictionary:

–Is a collection of tables created and maintained by the Oracle Server
Contain database information

 Tables in the Oracle Database

User tables are tables created by the user, such as EMPLOYEES. There is another collection of tables and views in the Oracle database known as the data dictionary. This collection is created and maintained by the Oracle server and contains information about the database.
All data dictionary tables are owned by the SYS user. The base tables are rarely accessed by the user because the information in them is not easy to understand. Therefore, users typically access data dictionary views because the information is presented in a format that is easier to understand. Information stored in the data dictionary includes names of the Oracle server users, privileges granted to users, database object names, table constraints, and auditing information.
There are four categories of data dictionary views; each category has a distinct prefix that reflects its intended use.

Table and Data Dictionary

Oracle 9i Tutorial : CREATE TABLE Syntax

Oracle 9i Tutorial : CREATE TABLE Syntax


•You must have:
–CREATE TABLE privilege
–A storage area
•You specify:
–Table name
–Column name, column data type, and column size
CREATE TABLE Statement
Create tables to store data by executing the SQL CREATE TABLE statement. This statement is one of the data definition language (DDL) statements, that are covered in subsequent lessons. DDL statements are a subset of SQL statements used to create, modify, or remove Oracle9i database structures. These statements have an immediate effect on the database, and they also record information in the data dictionary.
To create a table, a user must have the CREATE TABLE privilege and a storage area in which to create objects. The database administrator uses data control language (DCL) statements, which are covered in a later lesson, to grant privileges to users.
In the syntax:
  schema  is the same as the owner’s name
  table  is the name of the table
  DEFAULT expr  specifies a default value if a value is omitted in the INSERT   statement
  column  is the name of the column
  datatype  is the column’s data type and length

Oracle 9i Tutorial : Naming Rule

Naming Rules :

Table names and column names:
  1. Must begin with a letter
  2. Must be 1–30 characters long
  3. Must contain only A–Z, a–z, 0–9, _, $, and #
  4. Must not duplicate the name of another object owned by the same user
  5. Must not be an Oracle server reserved word

 Naming Guidelines

Use descriptive names for tables and other database objects.
Note: Names are case insensitive. For example, EMPLOYEES is treated as the same name as eMPloyees or eMpLOYEES.
For more information, see Oracle9i SQL Reference,“Object Names and Qualifiers.”

Labels

.NET Framework Interview Questions (7) .NET Interview Questions (10) .NET Remoting Interview Questions (1) ADO.NET and BLOB Error (1) ADO.NET Interview Questions (4) Agile Articles (9) AJAX Articles (5) AJAX Interview Questions (11) Algorithms (2) Analytics Articles (2) Analytics Interview Questions (3) Android FAQs - Part 1 (2) Articles (13) ASP.NET Articles (24) ASP.NET Error and Resolution (4) ASP.NET Interview Questions (23) ASP.NET Tutorial (8) AWS Interview Questions (16) Business Analyst Interview Questions (1) Cloud Computing Interview Questions (16) CSharp Articles (17) CSharp Interview Questions (32) CSharp Tutorial (17) Data Analysis (2) Data Structure (1) Design Pattern Articles (5) DevOps Tutorial (1) Digital Marketing Interview Questions (1) Download Templates (1) Error Resolution (6) Excel Articles (9) Excel Macros (1) Excel Tips and Tricks (10) HTML5 Interview Questions (3) HTML5 Tutorial (3) Interview Preparation (2) Interview Questions (24) Introduction to Business Analytics (10) Introduction to Python (7) Introduction to R Programming (23) JAVA Articles (6) Java Tutorial (5) LINQ Articles (4) LINQ Interview Questions (2) LINQ Tutorial (3) Microservices Interview Questions (1) MVCInterviewQuestions (2) OOPs Interview Questions (4) Oracle 9i Tutorial (14) Oracle Articles (2) Oracle Interview Questions (15) Outlook Error (1) PHP Interview Questions (3) PHP Tutorial (3) Product Management (12) Product Management Interview Questions (14) Product Owner Interview Questions (2) Program Management (5) Project Management (13) Project Management Articles (34) Project Management Interview Questions (25) Quiz (1) RallyDev Help (1) Scrum Master Interview Questions (11) Selenium Tutorial (1) Sharepoint Articles (1) SQL Interview Questions (23) SQL Server Articles (20) SSIS Interview Questions (6) SSRS Interview Questions (1) Technical Program Management (12) Technical Program Management - Interview Questions (24) TechnicalProgramManagement (5) Threading Interview Questions (2) Tutorial (8) UML Articles (3) UML Interview Questions (2) Unix (3) UNIX Tutorial (3) WCF Articles (20) WCF Interview Questions (9) WCF Quiz (2) WCF Tutorial (16) Web Service Articles (5) Web Service Interview Questions (3) Window Azure (1) XML Articles (6) XML Interview Questions (3) XML Tutorial (3)