0% found this document useful (0 votes)
30 views

SQL and PLSQL Q&A - 1.3

%type is used to declare a variable that has the same data type as a column in a table or variable. %rowtype is used to declare a variable that has the same structure as a row in a table.

Uploaded by

Sumithra Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

SQL and PLSQL Q&A - 1.3

%type is used to declare a variable that has the same data type as a column in a table or variable. %rowtype is used to declare a variable that has the same structure as a row in a table.

Uploaded by

Sumithra Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

SQL Q/A

Self introductions
• I am Peddappa basically i am from anantapur (Andhrapradesh)
• Totally i have 2 years 4 months experience as a PLSQL developer
• Previously i worked with Nextgen healthcare there i worked on clinical trails related
project
• IQVIA end clients do clinical trails on human beings at different different locations
• We do work on data imports & exports on the same data as per the client requirement
• we need to export the clinical trails result status .
• If they are testing one drug on 1000 members out of 1000 members how many
members feeling better or if they get any Adverse events like cold,fever,headache we
need to export this type of data.
• By using UTL file packages we do import & export the data., for each and every task
they do create jira ticket.
• So we need to work as per the requirement, as a database developer I written
procedures, Functions, packages and SQL statements , views, etc.
Self introduction
• I am Anitha basically i am from anantapur (Andhrapradesh)
• Totally i have 3 years 2months experience as a PLSQL developer.
• I worked with Alti source in Bangalore.
• There I worked on real estate related project.
• We worked as a offshore team for Tango
• It is proving end to end services to their end clients on lease and rent payments.
• Based on client requirement we need to export and import the data from .txt or .csv files.
• IF we take example as a KFC, subway stores they may have 30000 + stores all over the
world., to pay rent and lease they can use tango product.
• Like that Tango has 150 + clients.

• As a DB developer i written procedures ,functions, packages based on client requirements.


And also created indexes and views.
• By using UTL file packages I did import and export jobs.
Difference b/w DELETE and TRUNCATE

DELETE TRUNCATE
1. Delete is a DML command. 1. Truncate is a DDL
2. We can delete all rows as command.
well as specific rows. 2. Truncate will delete all
3. Rollback will work after rows in a single run. Can’t
Delete. delete specific rows.
4. It is slower than Truncate. 3. Rollback won’t work after
Truncate.
4. It’s faster than Delete.
Difference B/W char and varchar2
Char Varchar2
• It is used to store character • It is used to store character
string of fixed length. string of variable length.
• It has a max size of 2000 • It has a max size of 4000
bytes. bytes.
• It is static data type • It is a dynamic data type.
• It can lead to memory • It manages memory
wastage. efficiently.
Difference B/W date and Timestamp

Date TimeStamp
• It will returns date and time • It will returns date and time
along with microseconds.
Difference B/W substr and instr
Substr Instr
• It will return the set of • It will return the position
characters from a given number of a given
string. character.
• Ex:select • Ex:select
substr('welcome',1,3) from instr('welcome','e',1,1) from
dual; dual;
Cursor
cursor is a buffer area used to process multiple records in PLSQL
block

1. Implicit cursor 2. Explicit cursor


• Implicit cursors are • Explicit cursors are
automatically created by programmer-defined cursors
Oracle whenever an SQL for gaining more control over
statement is executed, when the context area. An explicit
there is no explicit cursor for cursor should be defined in
the statement. the declaration section of
• Whenever a DML statement the PL/SQL Block. It is
(INSERT, UPDATE and DELETE) created on a SELECT
is issued, an implicit cursor is Statement which returns
associated with this more than one row.
statement
Triggers
• Triggers are used to maintain data quality and to maintain audit
log. It is a named PLSQL program.
• Oracle Database automatically executes a trigger when a
specified event takes place, which may be in the form of a
system event or a DML statement being issued against the table
• There are 5 types of triggers.
• 1) DML triggers
• 2) DDL triggers
• 3) System triggers
• 4) Instead of triggers
• 5) Compound triggers
Constraints
• Constraints are used to maintain data quality. There
are 7 types of constraints.
• 1) Primary key
• 2) Not null
• 3) Unique
• 4) Check
• 5) Default
• 6) Compound primary key
• 7) Foreign key
Difference b/w view and materialized view

VIEW Materialized View


1. It is just a named query. It 1. Stores data physically and get
doesn’t store anything. updated periodically. While
Actual data comes from querying MV, it gives data
the table . from MV only.
2. Online data from 2. Offline data from underlying
base tables.
underlying base tables.
3. MV’s can be set to refresh
3. No need to refresh.
manually, on set schedule or
based on the database
detecting a change in data
from source tables.
Difference B/W procedure and function

Procedure Function
1. It may or may not return a 1. Always it will return a
value. value.
2. In procedures we can 2. We can’t perform DML
perform DML’s statements in Functions.
3. We can execute by using 3 3. We can execute by using 4
execution methods. execution methods.
4. We can’t call procedures in 4. We can call functions in
select statement. select statement
5. Exec procedure_name;
Difference B/W union and union all
Union Unionall
• It will sort the result. • It won’t sort the result.
• It won't displays duplicate • It displays duplicate values.
values.

• Valume reduce chey laptop


di
How to delete duplicate records
• We can delete duplicate records by using rowid.
• In a select statement we can use Distinct.
• Delete from emp e1 where rowid > (select
min(rowid) from emp e2 where e2.emp_id =
e1.emp_id);
• TO DISPLAY DUPLICATE RECORDS.
• Select emp_id,count(*) from emp group by
emp_id having count(*) > 1;
Difference B/W Rank and Dense_rank

Rank Dense rank


• Rank function is an analytic • Dense rank computes the
function that calculates the rank of a row in an ordered
rank of a value in a set of group of rows and returns
values. the rank as a number.
• Rank may not be • Here the ranks are
consecutive number. consecutive number.
• Rank function will skip the • Dense Rank function won’t
numbers when there are skip the numbers even
duplicate ranks when there are duplicate
ranks
Difference B/W right outer join and left outer
join
Right outer join Left outer join
• It will display matched and • It will display matched and
unmatched values from unmatched values from left
right side table and side table and matched
matched values from left values from right side table.
side table.
Why do we use Joins & types of joins
• We use joins to join number of tables based on
same columns. There are 7 types of joins.
• 1)equi join
• 2)non equi join
• 3)cross join
• 4) full outer join
• 5)Right outer join
• 6)left outer join
• 7)self join.
Indexes
• Indexes are used to improve the performance
of a query.
• There are 5 types :
1. B-tree index
2. Bitmap index
3. Function based index
4. Complex index
5. Unique index
To display top 5 emp’s ranks based on salary

• SELECT * FROM
(SELECT employee_id , first_name , salary ,
RANK() OVER (ORDER BY salary DESC ) AS rnk
FROM kia_emp1)
WHERE rnk <= 5;
Difference b/w %type and %rowtype

%type %rowtype
• It is used to refer data type • It is used to refer data type
of a column in a table of a row in a table

You might also like