Thursday, August 18, 2016

PLSQL - Key Points

PLSQL -Key Points

Make code maintenance easier by:
       Documenting code with comments
       Developing a case convention for the code
       Developing naming conventions for identifiers and other objects
       Enhancing readability by indenting
All SQL functions are available in plsql
decode and group functions are not available in plsql.
When you are working with nulls, you can avoid some common mistakes by keeping in mind the following rules:
          Comparisons involving nulls always yield NULL.
          Applying the logical operator NOT to a null yields NULL.
          In conditional control statements, if the condition yields NULL, its associated sequence of statements is not executed.
sequences can be directly used in plsql in 11g :    
DECLARE
l_employee_id  NUMBER(10);
BEGIN
l_employee_id :=sequence.nextval;

END;

PLSQL Comments


PLSQL  Comments

Use  -- for single line comments
Use /* */ for multiple line comments

Eg: Comments before a piece of code- to narrate what the code is about
 --cursor to get all the records in a particular department
   CURSOR  cur_employees IS SELECT  employee_id, first_name, salary from employees where department_id=10;

Eg: Comments to show the version of a PLSQL program unit, generally it is a good practice to maintain the history of modifications.
/*
Created by
Created Date
Description


modified by
modified date
description
search tag

modified   by
modified date
description
search tag


*/

Wednesday, August 17, 2016

PLSQL- Variables


PLSQL Variables

Variables store data temporarily in memory area.
These can be used throughout the program and can be modified in executable section.
Local Variables are initialized when the program begins and destroyed when the program end.
Global Variables are initialized at the beginning  of session, persistent across session and destroyed at end of session.
Variables are declared in the declaration section.
Can assign a default value while declaration of Variable.
Variable's type can be of tables column type.
Can be passed as parameters to other PLSQL programs
Use naming conventions for naming variables.
Never use column names as variable names. Difficult to read the program.
Use assignment operator := to assign values
Use DEFAULT keyword to assign default value.
If variable is not initialized ,its values will be null.
Can have NOT NULL as a constraint.


Types of Variables :

Scalar :  Holds a single value, all SQL Variables are scalar variables.
Reference: %TYPE- refers to a  tables column
Composite :Holds multiple values of same type. These are records and collections
Bind Variables: These are created outside the plsql block. Holds values ever after block executed.

               

An example of declaration of variables from oracle documentation

DECLARE
   wages          NUMBER;
   hours_worked   NUMBER := 40;
   hourly_salary  NUMBER := 22.50;
   bonus          NUMBER := 150;
   country        VARCHAR2(128);
   counter        NUMBER := 0;
   done           BOOLEAN;
   valid_id       BOOLEAN;
   emp_rec1       employees%ROWTYPE;
   emp_rec2       employees%ROWTYPE;
   TYPE commissions IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
   comm_tab       commissions;
BEGIN
   wages := (hours_worked * hourly_salary) + bonus;
   country := 'France';
   country := UPPER('Canada');
   done := (counter > 100);
   valid_id := TRUE;
   emp_rec1.first_name := 'Antonio';
   emp_rec1.last_name := 'Ortiz';
   emp_rec1 := emp_rec2;
   comm_tab(5) := 20000 * 0.15;
END;
/


PLSQL - Blocks


PLSQL Block Structure

DECLARE
--declarations (variables, constants, user defined types, cursors)
BEGIN
--processing /execution (SQL Statements, PLSQL statements)
EXCEPTION
--alternative actions to be performed when exceptions occurs in processing
END;

DECLARE, EXCEPTION are optional sections.
BEGIN.. END are mandatory sections.

Types of Blocks

Anonymous block.- Block without name
Procedure -Named PLSQL object /subprogram
Function- Named PLSQL object/subprogram

Typically use a procedure to perform an action and a function to compute and return a value.

Subprograms are stored in database and can be executed many times. Anonymous block is a onetime execution program and doesn't store in database.

PLSQL - Introduction


PLSQL Introduction

PLSLQL is a procedural extension to SQL (Structured Query Language).
A language to access/process data in Oracle Database
Like any other programming language,  PLSQL provides procedural constructs such as variables, constants, data types, procedural constructs, OOPS concepts, collections, error handling.
It has a block like structure, which makes code maintenance easier.
It has PLSQL compiler for compilations of programs.
It has reusable programs which can be compiled once executed many times.
It has PLSQL engine where PLSQL statements are executed.

It logically combines SQL statements into one unit, which improves performance when multiple SQL statements are execute as  a single unit.

RBS - SQL and PLSQL Interview Questions




First Round:
What is index? How it helps in improving performance?
Types of Index?
What is materialized view?
What is the concept of SQL Loader?
Difference between procedure and function?
Whether procedure returns values? How?
What are packages? Advantage of creating a package?
What is sequence? Parameters passed in the sequence?
Can we use %ISOPEN attribute of implicit cursor? Explain attributes of cursor?
How to handle the large transnational data?
What are Triggers? Explain a situation where you have used DML Trigger?
In a Partitioned table if a value greater than the defined range is inserted than whether value is inserted or not?
What is the process in which change is implemented in Production environment?

Second Round:
Explain how the change is implemented in production?
Explain SQL loader in detail, what files are involved?
What is Difference between SQL loader and external table?
Have you fixed any code issue in production environment?

Friday, August 12, 2016

E - PLSQL Interview Questions

E 3rd round.


Tell me about ur self.
What do u mean by quality of work.
Eveyone will do quality of work. What is special in it.
What you are saying is not quality of work. what exactly is quality of work.
What are your current roles and responsibilities.
Do u work in team.
How will your team cordinate with each other.
To whom u will report.
Does any one report to you.
If you are stuck with something at work, how will u resolve it.
suppose i hired you, and i have given a task.There is no documentation, no body explians about the existing system. How will u understand the existing sytem and complete your task.
You will be working alone in bangalore office. Your work will be assigned by US guys. Will be be able to work alone.
Have you ever worked with US teams.
About your previous compnay. 
previous company salary.
Why do u want to change.(Reason i have given work life balance).
Do u have any questions.
Hr will get back you.

Featured Post

Will the data from Oracle Database be lost after formatting the system in which it is installed?

So Someone asked me a question,  Will the data from Oracle Database be lost after formatting the system in which it is installed? Since the ...

Popular Posts