Practical-1: AIM: To Understand Basic Queries and Functions in SQL

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

110110116018

PRACTICAL-1
AIM: To understand basic queries and functions in SQL.
1.Create:
Synatx:
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
Example:

2.Insert
Syntax :INSERT INTO table_name
VALUES (value1,value2,value3,...);
Example:

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

3. Update :
Syntax:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

4. Distinct :
Syntax :
Select Distinct column_name from table_name;
Example :

5. Where :
Syntax:

SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
Example:

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

6. OrderBy :
Syntax :

SELECT column_name, aggregate_function(column_name)


FROM table_name
WHERE column_name operator value
GROUP BY column_name;
Example :

7. MAX() :
Syntax: SELECT MAX(column_name) FROM table_name;
Example :

8. MIN() :
Syntax: SELECT MIN(column_name) FROM table_name;
Example :

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

9. AVG()
Syntax : SELECT AVG(column_name) FROM table_name
Example :

10. SUM() :
Syntax : SELECT SUM(column_name) FROM table_name;
Example :

11. GroupBy :
Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
Example :

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

12. Drop :
Syntax : Drop Table table_name;
Example :

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

PRACTICAL-2
AIM : Revision of joins.

Left Join:
The LEFT JOIN keyword returns all rows from the left table (table1), with the
matching rows in the right table (table2). The result is NULL in the right side when
there is no match.
Syntax:
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

Example:

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

Right Join:
The RIGHT JOIN keyword returns all rows from the right table (table2), with the
matching rows in the left table (table1). The result is NULL in the left side when there
is no match.
Syntax:
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;

Example:

Inner Join:
The INNER JOIN keyword selects all rows from both tables as long as there is a
match between the columns in both tables.
Syntax:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
Example:

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

Full Join:
The FULL OUTER JOIN keyword returns all rows from the left table (table1) and
from the right table (table2).The FULL OUTER JOIN keyword combines the result of
both LEFT and RIGHT joins.
Syntax:
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
Example:

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

PRACTICAL-3

Aim : Implementing simple PL/SQL block.

PL/SQL permits the creation of structured logical blocks of code that


describes processes which have to be applied to data. A single PL/SQL code
consists of a set of SQL statements, clubbed together and passed to the Oracle
entity. The structure of PL/SQL can be divided into sections namely :

1) The Declare section,

2) The Master and End section that also contains an Exception section (optionally).

The Declare Section: Code blocks starts with a declaration section in which memory
variables and other Oracle objects can be declared an initialized.

The Begin Section: It consists of a set of SQL and PL/SQL statements which
describe processes that have to be applied to table data. Data manipulation,
retrieval, looping and branching constructs can be applied in this section.

The Exception section: This section deals with handling of errors that arise during
execution of the data manipulation statements, which make up the PL/SQL code
block.

The End Section: This marks the end of a PL/SQL code block.

DISTIBUTED DATABASE APPLICATION


& SYSTEM

110110116018

1) Create a PL/SQL block to retrieve information about a student whose roll-no is


entered by User.

PRACTICAL -4

DISTIBUTED DATABASE APPLICATION


& SYSTEM

10

110110116018

Aim: Write a PL/SQL code block that will accept anaccount number
from the user, check if theusersbalance is less than the minimum
balance, onlythen deduct Rs. 100/- from the balance. Theprocess is
fired on the ACCT_MSTR table.
Create atable ACC_MASTER
create table ACC_MASTER_46
(
acc_no number(5),
open_date date,
branch varchar(15),
amount number(10,2),
acc_type varchar(15)
);
Insert Data into table
insert into ACC_MASTER_46 values(00001,'06/Aug/2014','anand',5000,'saving');
insert into ACC_MASTER_46 values(00002,'15/Jul/2014','vadodara',1500,'current');
insert into ACC_MASTER_46 values(00003,'08/Apr/2014','valsad',5520,'saving');
insert into ACC_MASTER_46 values(00004,'07/Jan/2014','surat',5020,'saving');
insert into ACC_MASTER_46 values(00005,'23/Feb/2014','bardoli',5010,'saving');
insert into ACC_MASTER_46 values(00006,'20/Mar/2014','bharuch',5030,'loan');

Query
DECLARE
DISTIBUTED DATABASE APPLICATION
& SYSTEM

11

110110116018

accno number(5);
accnew number(5);
amtnew number(10,2);
BEGIN
accno:=&accno;
select acc_no,amount into accnew,amtnew from ACC_MASTER_46 where acc_no=
accno;
IF amtnew<2500
THEN
amtnew:=amtnew-100;
update ACC_MASTER_46 set amount =amtnew where acc_no=accno;
END IF;
END;

DISTIBUTED DATABASE APPLICATION


& SYSTEM

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy