PROGRAM : 1

Aim : To create a new user account
SQL> -- TO CREATE A NEW USER ACCOUNT SQL>CONNECT SCOTT/TIGER Connected. SQL> CREATE USER PUNEET IDENTIFIED BY RAJ; User created. SQL> GRANT CONNECT, RESOURCE TO PUNEET; Grant succeeded. SQL> CONNECT PUNEET/RAJ Connected. SQL>CONNECT SYSTEM/MANAGER Connected. SQL> ALTER USER PUNEET IDENTIFIED BY SANJAY; User altered. SQL> CONNECT PUNEET/SANJAY Connected.

1

PROGRAM : 2
AIM: TO CREATE, INSERT, DISPLAY, DELETE, UPDATE ,DROP A GIVEN TABLE
SQL> -- TO CREATE, INSERT, DISPLAY, DELETE, UPDATE ,DROP A GIVEN TABLE SQL> CONNECT MANVEE/MANU Connected. SQL> CREATE TABLE FRIENDS(SERIAL NUMBER(3),NAME VARCHAR2(20), AGE NUMBER(2), INCOME NUMBER(6)); Table created. SQL> DESC FRIENDS; Name Null? Type --------------------SERIAL NUMBER(3) NAME VARCHAR2(20) AGE NUMBER(2) INCOME NUMBER(6) SQL> INSERT INTO FRIENDS VALUES(1,'PUNEET',19,20000); 1 row created. SQL> INSERT INTO FRIENDS VALUES(2,'RICHA' ,20,12000); 1 row created. SQL> INSERT INTO FRIENDS VALUES(3,'GAURAV',21,17000); 1 row created. SQL> INSERT INTO FRIENDS VALUES(4,'ANKUSH',23,20000); 1 row created. SQL> INSERT INTO FRIENDS VALUES(5,'PRINCE',19,30000); 1 row created. SQL> SELECT * FROM FRIENDS; SERIAL NAMEAGE INCOME --------- --------------------

2

1 2 3 4 5

PUNEET RICHA GAURAV ANKUSH PRINCE

19 20 21 23 19

12000 12000 17000 20000 30000

SQL> INSERT INTO FRIENDS(SERIAL,AGE,INCOME)VALUES(6,23,23000); 1 row created. SQL> INSERT INTO FRIENDS(SERIAL,AGE,INCOME)VALUES(7,24,24000); 1 row created. SQL> INSERT INTO FRIENDS(SERIAL,AGE,INCOME)VALUES(8,25,25000); 1 row created. SQL> INSERT INTO FRIENDS(SERIAL,AGE,INCOME)VALUES(9,26,26000); 1 row created. SQL> INSERT INTO FRIENDS(SERIAL,AGE,INCOME)VALUES(10,27,27000); 1 row created. SQL> SELECT * FROM FRIENDS; SERIAL NAME AGE INCOME ------------- ------------ -------------- ---------------------1 PUNEET 19 20000 2 RICHA 20 12000 3 GAURAV 21 17000 4 ANKUSH 23 20000 5 PRINCE 19 30000 6 23 23000 7 24 24000 8 25 25000 9 26 26000 10 27 27000 10 rows selected. SQL> INSERT INTO FRIENDS VALUES(&SERIAL,'&NAME',&AGE,&INCOME); Enter value for serial: 11

3

Enter value for name: FRIENDS Enter value for age: 19 Enter value for INCOME: 19000 old 1: INSERT INTO FRIENDS VALUES(&SERIAL,'&NAME',&AGE,&INCOME) new 1: INSERT INTO FRIENDS VALUES(ll,'FRIENDS' ,19,19000) 1 row created. SQL>/ Enter value for serial: 12. Enter value for name: RICHA Enter value for age: 20 Enter value for INCOME: 20000 old 1: INSERT INTO FRIENDS VALUES(&SERIAL,'&NAME',&AGE,&INCOME) new 1: INSERT INTO FRIENDS V ALUES(12,'RICHA',20,2QOOO) 1 row created. SQL>/ Enter value for serial: 13 Enter value for name: GAURAV Enter value for age: 21 Enter value for INCOME: 21000 old 1: INSERT INTO FRIENDS VALUES(&SERIAL,'&NAME',&AGE,&INCOME) new 1: INSERT INTO FRIENDS VALUES(13,'GAURAV',21,21000) 1 row created. SQL>/ Enter value for serial: 14 Enter value for name: ANKUSH Enter value for age: 22 Enter value for INCOME: 22000 old 1: INSERT INTO FRIENDS VALUES(&SERIAL,'&NAME',&AGE,&INCOME) new 1: INSERT INTO FRIENDS VALUES(14,'ANKUSH',22,22000) 1 row created. SQL>/ Enter value for serial: 15 Enter value for name: PRINCE Enter value for age: 23 Enter value for INCOME: 23000 old 1: INSERT INTO FRIENDS VALUES(&SERIAL,'&NAME',&AGE,&INCOME) new 1: INSERT INTO FRIENDS VALUES(15,'PRINCE',23,23000)

4

1 row created. SQL> SELECT * FROM FRIENDS; SERIAL NAME AGE INCOME ----- ---------- ---------1 PUNEET 19 20000 2 RICHA 20 12000 3 GAURAV 21 17000 4 ANKUSH 23 20000 5 PRINCE 19 30000 6 23 23000 7 24 24000 8 25 25000 9 26 26000 10 27 27000 11 FRIENDS 19 19000 12 RICHA 20 20000 13 GAURAV 21 21000 14 ANKUSH 22 22000 15 PRINCE 23 23000 15 rows selected. SQL> UPDATE FRIENDS SET NAME='FRIENDS' WHERE SERIAL=6; 1 row updated. SQL> UPDATE FRIENDS SET NAME='ANKUSH' WHERE INCOME=24000; 1 rows updated. SQL> SELECT * FROM FRIENDS; SERIAL NAME AGE INCOME --------- -------------------- --------- --------1 PUNEET 19 20000 2 RICHA 20 12000 3 GAURAV 21 17000 4 ANKUSH 23 20000 5 PRINCE 19 30000 6 FRIENDS 23 23000 7 ANKUSH 24 24000 8 25 25000 9 26 26000 10 27 27000 11 FRIENDS 19 19000

5

12 13 14 15

RICHA GAURAV ANKUSH PRINCE

20 21 22 23

20000 21000 22000 23000

15 rows selected.

SQL> DELETE FROM FRIENDS; 15 rows deleted. SQL> SELECT * FROM FRIENDS; no rows selected SQL> DROP TABLE FRIENDS; Table dropped. SQL> SPOOL OFF

6

PROGRAM : 3
AIM: QUERYING RECORDS USING WHERE, ORDER BY ,GROUP BY CLAUSES AND MULTIPLE CONDITIONS
SQL> --QUERYING RECORDS USING WHERE, ORDER BY ,GROUP BY CLAUSES AND MULTIPLE CONDITIONS SQL> CONNECT MANISH/CHAWLA Connected. SQL> DESC SALES; Name Null? Type S_ORDER PROD_NO QTY_ORDERED VARCHAR2(10) VARCHAR2(1 0) NUMBER(3)

SQL> SELECT * FROM SALES; S_ORDER PROD_NO QTY_ORDERED -------- -------- -----------019001 POOO01 10 019001 P02543 6 019001 P09871 19 019002 P08765 13 018765 POOO01 3 018650 P09871 4 065433 POOO01 11 7 rows selected. SQL> SELECT * FROM SALES WHERE QTY ORDERED =10; S_ORDER PROD_NO QTY_ORDERED -------- -------- ---------019001 P00001 10 SQL> SELECT * FROM SALES WHERE PROD_NO='P00001'; S_ORDER PROD_NO QTY_ORDERED -------- -------- ---------019001 P00001 10 018765 POOOOl 3 065433 POOOOl 11 SQL> SELECT * FROM SALES WHERE PROD_NO='P00001' AND QTY_ORDERED=10;

7

S_ORDER PROD_NO QTY_ORDERED ------- ------- ---------019001 P00001 10 SQL> SELECT * FROM SALES WHERE PROD_NO='P00001' OR QTY_ORDERED=10; S_ORDER PROD_NO QTY_ORDERED - ----- ------- ---------019001 P00001 10 018765 P00001 3 065433 P00001 11 SQL> SELECT * FROM SALES ORDER BY PROD_NO; S_ORDER PROD_NO QTY_ORDERED ------- ------- ---------019001 POOO01 10 018765 POOO01 3 065433 POOO01 11 019001 P02543 6 019002 P08765 13 019001 P09871 19 018650 P09871 4 7 rows selected. SQL> SELECT * FROM SALES ORDER BY PROD_NO DESC; S_ORDER PROD_NO QTY_ORDERED ------- -------- ----------019001 018650 019002 019001 019001 018765 065433 P09871 P09871 P08765 P02543 POOO01 POOO01 POOO01 19 4 13 6 10 3 11

7 rows selected. SQL> SELECT PROD _ NO,SUM(QTY _ ORDERED) "TOTAL QTY _ORDERED" FROM SALES ROLL NO. 2206217 GROUP BY PROD_NO;

8

PROD_NO TOTALQTY_ORDERED

-------- -------------P00001 24 P02543 6 P08765 13 P09871 23 SQL> SELECT PROD_NO, SUM(QTY _ ORDERED) "TOTAL QTY _ORDERED" FROM SALES GROUP BY PROD_NO HA VINGPROD _ NO='POOOO l' ; P00001 24

9

PROGRAM : 4
AIM: TO CREATE TABLE WITH NOT NULL, PRIMARY, FOREIGN, UNIQUE AND CHECK CONSTRAINTS
SQL> --TO CREATE TABLE WITH NOT NULL, PRIMARY, FOREIGN, UNIQUE AND CHECK CONSTRAINTS SQL> CONNECT system/manager; Connected. SQL> CREATE TABLE STUD (NAME VARCHAR2(20), AGE NUMBER(2), ID NUMBER(6) PRIMARY KEY); Table created. SQL> DESC STUD Name Null? Type ------------ ----- ----NAME VARCHAR2(20) AGE NUMBER(2) ID NOT NULL NUMBER(6)

SQL> INSERT INTO STUD VALUES('&NAME',&AGE,&ID); Enter value for name: PUNEET Enter value for age: 19 Enter value for id: 1 old 1 : INSERT INTO STUD VALUES('&NAME';"&AGE,&ID) new 1: INSERT INTO STUD VALUES(' PUNEET ',19,1) 1 row created. SQL>/ Enter value for name: PUNEET Enter value for age: 21 Enter value for id: 1 old 1: INSERT INTO STUD VALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD VALUES('PUNEET ',21,1) INSERT INTO STUD VALUES(' PUNEET ',21,1) * ERROR at line 1: ORA-OOOO1: unique constraint (PUNEET.SYS_C00400) violated SQL> / Enter value for name: PUNEET Enter value for age: 20

10

Enter value for id: NULL old 1: INSERT INTO STUD VALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD VALUES(' PUNEET ',20,NULL) INSERT INTO STUD V ALUES(' PUNEET ',20,NULL) ERROR at line 1: ORA-01400: mandatory (NOT NULL) column is missing or NULL during insert SQL> CREATE TABLE STUD1(NAME VARCHAR2(20),ID NUMBER(6), AGE NUMBER(2),PRIMARY KEY(ID,NAME)); Table created. SQL> DESC STUDl; Name Null? Type ------- ------ -----NAME NOT NULL VARCHAR2(20) ID NOT NULL NUMBER(6) AGE NUMBER(2)

SQL> INSERT INTO STUDl VALUES('&NAME',&ID,&AGE); Enter value for name: MAN,ISH Enter value for id: 1 Enter value for age: 19 old 1: INSERT INTO STUDl VALUES('&NAME',&ID,&AGE) new 1: INSERT INTO STUDl VALUES(' GULSHAN ',1,19) 1 row created. SQL> / Enter value for name: RAHUL Enter value for id: 1 Enter value for age: 20 old 1: INSERT INTO STUDl VALUES('&NAME',&ID,&AGE) new 1: INSERT INTO STUDIV ALUES('RAHUL',1,20) 1 row created. SQL> / Enter value for name: RAHUL Enter value for id: 1 Enter value for age: 20 old 1: INSERT INTO STUDl VALUES('&NAME',&ID,&AGE) new 1: INSERT INTO STUDl VALUES('RAHUL',1,20)

11

INSERT INTO STUDl VALUES('RAHUL',1,20) * ERROR at line 1: ORA-OOOO1: unique constraint (PUNEET.SYS_C00401) violated SQL> CREATE TABLE STUD2(NAME V ARCHAR2(20),AGE NUMBER(2), ID NUMBER(2) UNIQUE); Table created. SQL>DESC STUD2; Name Null? Type ------ -----------NAME VARCHAR2(20) AGE NUMBER(2) ID NUMBER(2)

SQL> INSERT INTO STUD2 VALUES('&NAME',&AGE,&ID); Enter value for name: MANISH Enter value for age: 19 Enter value for id: 1 old 1: INSERT INTO STUD2 VALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD2 VALUES(' PUNEET ',19,1) 1 row created. SQL> / Enter value for name: PUNEET Enter value for age: 20 Enter value for id: 1 old 1: INSERT INTO STUD2 YALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD2 VALUES(' PUNEET ',20,1) INSERT INTO STUD2 V ALUES(' PUNEET ',20,1) * ERROR at line 1: ORA-00001: unique constraint (PUNEET.SYS_C00402) violated SQL> / Enter value for name: PUNEET Enter value for age: 21 Enter value for id: NULL old 1: INSERT INTO STUD2 VALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD2 VALUES(' PUNEET ',21,NULL)

12

1 row created. SQL> CREATE TABLE STUD3(NAME V ARCHAR2(20),ID NUMBER(6) NOT NULL, AGE NUMBER(2)); Table created. SQL> DESC STUD3; Name Null? Type ----- ----------NAME VARCHAR2(20) ID NOT NULL NUMBER(6) AGE NUMBER(2) SQL> INSERT INTO STUD3 V ALUES('&NAME',&ID,&AGE); Enter value for name: GULSHAN Enter value for id: NULL Enter value for age: 19 old 1: INSERT INTO STUD3 VALUES('&NAME',&ID,&AGE) new 1: INSERT INTO STUD3 VALUES(' PUNEET ',NULL, 19) INSERT INTO STUD3 VALUES(' PUNEET ',NULL,19) * ERROR at line 1: ORA-01400: mandatory (NOT NULL) column is missing or NULL during insert SQL> ALTER TABLE STUD3 ADD PRIMARY KEY(NAME); Table altered. SQL> CREATE TABLESTUD4(NAME VARCHAR2(20) REFERENCES STUD3, AGE NUMBER(2),ID NUMBER(6)); Table created. SQL> ALTER TABLE STUD3 DROP PRIMARY KEY; ALTER TABLE STUD3 DROP PRIMARY KEY * ERROR at line 1: ORA-02273: this unique/primary key is referenced by some foreign keys SQL> CREATE TABLE STUD5 (NAME V ARCHAR2(20),AGE NUMBER(2),ID NUMBER(6), FOREIGN KEY(NAME) REFERENCES STUD3);

13

Table created. SQL> ALTER TABLE STUD3 DROP PRIMARY KEY; ALTER TABLE STUD3 DROP. PRIMARY KEY * ERROR at line 1: ORA-02273: this unique/primary key is referenced by some foreign keys SQL> CREATE TABLE STUD6(NAME V ARCHAR2(20) CHECK(NAME LIKE 'C%'),AGE NUMBER(2),ID NUMBER(6»;

Table created. SQL> INSERT INTO STUD6 V ALUES('&NAME',&AGE,&ID); Enter value for name: PUNEET Enter value for age: 19 Enter value for id: 1 old 1: INSERT INTO STUD6 V ALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD6 VALUES(' PUNEET ',19,1) INSERT INTO STUD6 VALUES(' PUNEET ',19,1) * ERROR at line 1: ORA-02290: check constraint (PUNEET.SYS_C00407) violated

14

PROGRAM : 5
AIM: TO MODIFY THE STRUCTURE OF TABLE BY ADDIMODIFY COLUMN AND ADD/DROP PRIMARY, FOREIGN KEY
SQL> -- TO MODIFY THE STRUCTURE OF TABLE BY ADDIMODIFY COLUMN AND ADD/DROP PRIMARY, FOREIGN KEY SQL> CONNECT SYSTEM/MANAGER; Connected. SQL> CREATE TABLE GULSHAN2(NAME V ARCHAR2(20), AGE NUMBER(2)); Table created. SQL> DESC MANISH29; Name Null? Type ---------- ---------NAME VARCHAR2(20) AGE NUMBER(2) SQL> ALTER TABLE GULSHAN2 ADD (ROLL_NO VARCHAR2(6)); Table altered. SQL> DESC MANISH29; Name Null? Type -------- -------------NAME VARCHAR2(20) AGE NUMBER(2) ROLL NO VARCHAR2(6)

SQL> ALTER TABLE GULSHAN2 MODIFY(ROLL_NO NUMBER(6)); Table altered. SQL> DESC MANISH29; Name Nui1? Type --------- ------------NAME VARCHAR2(20) AGE NUMBER(2) ROLL NO NUMBE~J6)

15

SQL> CREATE TABLE GULSHAN2 (NAME VARCHAR2(20), ADDRESS VARCHAR2(20), ROLL_NO NUMBER(6)); Table created. SQL> DESC MANISH29A Name Null? Type ----- ----------NAME VARCHAR2(20) ADDRESS VARCHAR2(20) ROLL NO NUMBER(6)

SQL> ALTER TABLE Mft..-NISH29 ADD PRIMARY KEY(ROLL_NO); Table altered. SQL> DESC GULSHAN2; Name Null? Type ------------ --------------NAME VARCHAR2(20) AGE NUMBER(2) ROLL_NO NOT NULL NUMBER(6)

SQL> ALTER TABLE GULSHAN2 DROP PRIMARY KEY; Table altered. SQL> DESC GULSHAN2 Name Null? Type --------- -----------NAME VARCHAR2(20) AGE NUMBER(2) ROLL_NO NUMBER(6)

SQL> ALTER TABLE GULSHAN2 ADD PRIMARY KEY(ROLL_NO); Table altered. SQL> DESC GULSHAN2 Name Null? Type

16

------------ --------------NAME VARCHAR2(20) AGE NUMBER(2) ROLL_NO NOT NULL NUMBER(6) SQL> ALTER TABLE GULSHAN2 ADD CONSTRAINT ROLL_FKEY FOREIGN KEY(ROLL_NO) REFERENCES GULSHAN2; Table altered. SQL> ALTER TABLE GULSHAN2 DROP PRIMARY KEY; ALTER TABLE GULSHAN2 DROP PRIMARY KEY * ERROR at line 1: ORA-02273: this unique/primary key is referenced by some foreign keys SQL> ALTER TABLE GULSHAN2A DROP CONSTRAINT ROLL_FKEY; Table altered. SQL> ALTER TABLE GULSHAN2 DROP PRIMARY KEY; Table altered. SQL> DESC GULSHAN2; Name Null? Type ---------- ----------NAME VARCHAR2(20) AGE NUMBER(2) ROLL_NO NUMBER(6)

17

PROGRAM : 6
AIM: TO PERFORM RENAMING COLUMNS, RANGE SEARCHING, PATTERN MATCHING, USE OF DEFAULT AND LOGICAL OPERATORS ON A TABLE
SQL> -- TO PERFORM RENAMING COLUMNS, RANGE SEARCHING, PATTERN MATCHING, USE OF DEFAULT AND LOGICAL OPERATORS ON A TABLE SQL> CONNECT SYSTEM/MANAGER; Connected. SQL> DESC STUD; Name Null? Type NAME AGE ID VARCHAR2(20) NUMBER(2) NOT NULL NUMBER(6)

SQL> SELECT * FROM STUD; NAME AGE ID ---------- ------ ---MANISH 19 1 SQL> INSERT INTO STUD VALUES('&NAME',&AGE,&ID); Enter value for name: RAJ Enter value for age: 19 Enter value for id: 2 old 1: INSERT INTO STUD V LUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD VALUES ('RAJ', 19,2) 1 row created. SQL> / Enter value for name: GAURAV Enter value for age: 19 Enter value for id: 3 old 1: INSERT INTO STUD V ALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD VALUES('GAURAV',19,3) 1 row created. SQL>/

18

Enter value for name: RAHUL Enter value for age: 19 Enter value for id: 4 old 1: INSERT INTO STUD VALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD VALUES('RAHUL',19,4) 1 row created. SQL> / Enter value for name: RAGHAV Enter value for age: 20' Enter value for id: 5 old 1: INSERT INTO STUD VALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD V ALUES('RAGHAV',20,5) I row created. SQL>/ Enter value for name: VISHAL Enter value for age: 21 Enter value for id: 6 old 1: INSERT INTO STUD V ALUES('&NAME',&AGE,&ID) new 1: INSERT INTO STUD V ALUES('VISHAL',21 ,6) 1 row created. SQL> SELECT * FROM STUD; NAME AGE ID ------------- ------- ------MANISH 19 1 RAJ 19 2 GAURAV 19 3 RAHUL 19 4 RAGHAV 20 5 VISHAL 21 6

6 rows selected. SQL> SELECT AGE* 1 0 FROM STUD; AGE*lO ----190 190 190

19

190 200 210 6 rows selected. SQL> SELECT AGE* 1 0 "DEFINED AGE" FROM STUD 2' DEFINED AGE -------190 190 190 190 200 210 6 rows selected. SQL> SELECT * FROM STUD WHEREAGE=21 OR ID=l; NAME AGE ID --------- ------- ---MANISH 19 1 VISHAL 21 6

SQL> SELECT * FROM STUD WHERE AGE=20 AND ID=l; no rows selected SQL> SELECT * FROM STUD WHERE AGE=20 AND ID=5; NAME AGE ID ----- ------- --RAGHAV 20 5 SQL> SELECT * FROM STUD WHERE AGE NOT=21; SELECT * FROM STUD WHERE AGE NOT=21 * ERROR at line 1: ORA-00920: invalid relational operator

20

SQL> SELECT * FROM STUD WHERE NOT AGE=19; NAME AGE ID ------------ ------ -----RAGHAV 20 5 VISHAL 21 6

SQL> SELECT * FROM STUD WHERE ID BETWEEN 3 AND 6; NAME AGE ID --------- ------- ---GAURAV 19 3 RAHUL 19 4 RAGHAV 20 5 VISHAL 21 6

SQL> SELECT * FROM STUD WHERE ID NOT BETWEEN 3 AND 6; NAME AGE ID --------- -------- -----MANISH 19 1 RAJ 19 2

SQL> SELECT * FROM STUD WHERE NAME LIKE '_A%'; NAME AGE ID ------------ ----- -----MANISH 19 1 RAJ 19 2 GAURAV 19 3 RAHUL 19 4 RAGHAV 20 5

SQL> SELECT * FROM STUD WHERE NAME NOT LIKE'_A%'; NAME AGE ID ----------- ------- -----VISHAL 21 6

21

PROGRAM : 7
AIM: ILLUSTRATE THE USE OF ORACLE FUNCTIONS
SQL> -- ILLUSTRATE THE USE OF ORACLE FUNCTIONS SQL> CONNECT SYSTEM/MANAGER; Connected. SQL> DESC STUD; Name Null? Type ---------- --------- ----NAME VARCHAR2(20) AGE NUMBER(2) ID NOT NULL NUMBER(6)

SQL> SELECT * FROM STUD; NAME AGE ID ---------- ----- ----MANISH 19 1 RAJ 19 2 GAURAV 19 3 RAHUL 19 4 RAGHAV 20 5 VISHAL 21 6

6 rows selected. SQL> SELECT AVG(AGE) "AVERAGE AGE" FROM STUD; AVERAGE AGE ------------19.5 SQL> SELECT MIN(AGE) "MINIMUM AGE" FROM STUD; MINIMUM AGE 19

22

SQL> SELECT MAX(AGE) "MAXIMUM AGE" FROM STUD; MAXIMUM AGE ----------21 SQL> SELECT COUNT(*) "TOTAL ROWS" FROM STUD; TOTAL ROWS ---------6 SQL> SELECT COUNT(AGE) "TOTAL ROWS" FROM STUD; TOTAL ROWS --------6 SQL> SELECT SUM(AGE) FROM STUD; SUM (AGE) --------117 SQL> SELECT ABS(-21) FROM DUAL; ABS(-21) --------21 SQL> SELECT POWER(2,5) "RAISED" FROM DUAL; RAISED ---------32 SQL> SELECT ROUND(19.57663,3) FRQM DUAL; ROUND(19.57663,3) ------------19.577 SQL> SELECT SQRT(2) "SQUARE ROOT" FROM DUAL; SQUARE ROOT ---------1.4142136

23

SQL> SELECT LOWER(NAME) FROM STUD; LOWER(NAME) -------manish raj gaurav rahul raghav vishal 6 rows selected. SQL> SELECT UPPER(NAME) FROM STUD; UPPER(NAME) ----------MANISH RAJ GAURAV RAHUL RAGHAV VISHAL 6 rows selected.

SQL> SELECT INITCAP(NAME) FROM STUD; INITCAP(NAME) ------------Manish Raj Gaurav Rahul Raghav Vishal 6 rows selected. SQL> SELECT SUBSTR('GULSHAN',1,6) FROM DUAL; SUBSTR --------ANISH

24

SQL> SELECT LENGTH(NAME) FROM STUD WHERE ID=4; LENGTH (NAME) -----------SQL> SELECT LTRlM('GULSHAN','M') FROM DUAL; LTRlM -----ANISH SQL> SELECT RTRlM('GULSHAN','H).,FROM DUAL; RTRlM ----MANIS SQL> SELECT LPAD('GULSHAN',10,'$') FROM DUAL; LPAD('MANI ----------$$$$MANISH SQL> SELECT RPAD('GULSHAN',10,'$') FROM DUAL; RPAD('MANI ------------GULSHAN$$$$ SQL> SELECT TO_NUMBER('21') FROM DUAL; TO _ NUMBER('21') ----------21 SQL> SELECT TO_DATE('04-09-86','DD-MM-YY') FROM DUAL; TO_DATE(' --------04-SEP-86 SQL> SELECT TO _ CHAR(AGE) FROM STUD; TO _ CHAR(AGE) ------------19 19 19 19

25

20 21 6 rows selected.

PROGRAM : 8
AIM: ILLUSTRATE THE USE OF UNION ,INTERSECTION, AND MINUS CLAUSE
SQL> --ILLUSTRATE THE USE OF UNION ,INTERSECTION, AND MINUS CLAUSE SQL> CONNECT SYSTEM/MANAGER; Connected. SQL> SELECT * FROM STUD; NAME --------MANISH RAJ GAURAV RAHUL RAGHAV VISHAL AGE ID -------- ---19 1 19 2 19 3 19 4 20 5 21 6

6 rows selected. SQL> SELECT * FROM STUD2; NAME AGE ID ------- --------- ----GULSHAN 19 1 GULSHAN 21 SQL> SELECT * FROM STUD UNION SELECT * FROM STUD2; NAME AGE ID --------- ------ -----GAURAV 19 3 GULSHAN 19 1 GULSHAN 21 RAGHAV 20 5 RAHUL 19 4 RAJ 19 2 VISHAL 21 6

26

7 rows selected. SQL> SELECT * FROM STUD INTERSECT SELECT * FROM STUD2; NAME AGE ID ------ --------- ----MANISH 19 1 SQL> SELECT * FROM STUD MINUS SELECT * FROM STUD2; NAME AGE ID ------- -------- ----GAURAV 19 3 RAGHAV 20 5 RAHUL 19 4 RAJ 19 2 VISHAL 21 6

27

PROGRAM : 9
AIM: TO ILLUSTRATE THE USE OF GRANT AND REVOKE PERMISSION
SQL> -- TO ILLUSTRATE THE USE OF GRANT AND REVOKE PERMISSION SQL> CONNECT SYSTEM/MANAGER; Connected. SQL> SELECT * FROM TAB; TNAME TABTYFE CLUSTERlD -------- ---------------- -----STUD TABLE STUDl TABLE STUD2 TABLE STUD3 TABLE STUD4 TABLE STUDS TABLE STUD6 TABLE STUD7 TABLE STUD8 TABLE

9 rows selected. SQL> GRANT ALL ON STUDl TO SCOTT; Grant succeeded. SQL> CREATE USER ORANGE IDENTIFIED BY BLUES; User created. SQL> GRANT CONNECT, RESOURCE TO ORANGE; Grant succeeded. SQL> CONNECT SCOTT/TIGER; Connected. SQL> SELECT * FROM STUDl; NAME ID AGE ----------- ----- ----MANISH 1 19 RAHUL 1 20

28

SQL> CONNECT SYSTEM/MANAGER; Connected. SQL> REVOKE ALL ON STUD 1 FROM SCOTT; Revoke succeeded.

29

INTRODUCTION TO DATA: Data is defined as the representation of facts, concepts of instructions in a formal manner suitable for communication or processing by human's or by automatic means. Data refers to which is actually stored in database. Data are collection of unorganized facts but able to be organized in to useful information. Data can be of following different types: 1. INTEGRATED DATA: A collection of data is integrated if data is logically consistent i.e. the duplicate data items are agree with one another. A database can be considered as the unification of several distinct data files, with any redundancy among those files are eliminated. Data is said to be integrated data. 2. SHARED DATA: By shared we mean that individual pieces of data in the database can be shared among different users, in the sense that each of those users can have access to same piece of data, possibly for different purposes. Different users can effectively even access the same piece of data at the same time. INTRODUCTION TO DATABASE:A database can be defined as a collection of nonredundant data which can be shared by different application systems. A database implies separation of physical storage from use of the data by an application program to achieve program/data independence. Using a database system, the user or programmer or application specialist need not know the details of how the data are stored and such details are usually "transparent" to the user. ADVANTAGES OF DATABASE · Reduction in data redundancy · Maintenance of data integrity and quality · Avoidance of inconsistency · Reduced cost of software development · Security restrictions View of the Database .The database can present different views of itself to users, programmers and the database administrator. ·The internal data rep~esentation (internal view) is normally not seen by the user or application programmer.

30

.Theconceptual view or conceptual schema is the primary means by which the DBA builds and manages the database. The DBMS can present multiple views of the conceptual schema (external views) to programmers and users, depending on the application. INTRODUCTION TO DATABASE MANAGEMENT SYSTEM A database management system (DBMS) consists of collection of interrelated data and a set of programs to access that data. Th~ collection of data, usually referred to as the database contains information about one particular enterprise The primary goal of a DBMS is to provide an environment that is both convenient and efficient to use in retrieving and storing database information. DBMS COMPONENTS Data: -Data stored in a database include numerical data which may be integers (whole numbers only) or floating point numbers (decimal), and non-numerical data such as characters (alphabetic and numeric characters), date or logical (true or false). More advanced systems may include more complicated data entities such as pictures and images as data types. . Standard operations: Standard operations are provided by most DBMSs. These operations provide the user with basic capabilities for data manipulation. Examples of these standard operations are sorting, deleting and selecting records. Data definition language (DDL): DOL is the language used to describe the contents of the database. It is used to describe, for example, attribute names (field names), data types, location in the database, etc. Data manipulation and query language: Normally a query language is supported by a DBMS to form commands for input, edit, analysis, output, reformatting, etc. Some degree of standardization has been achieved with SQL (Structured Query Language). Programming tools: Besides commands and queries, the database should be accessible directly from application programs through function calls (subroutine calls) in conventional programming languages. File structures: Every DBMS has its own internal structures used to organize the data although some common data models are used by most DBMSs. ADVANTAGES OF DBMS: 1. Controlling redundancy: Each user group maintains its own files for handling its data processing applications. Much of data is stored twice: once in the files of each user group.

31

Additional user group may further duplicate some or all of data multiple times leads to several problems. Storage space is waisted when details stored repeated, and this problem may be serious for large databases. So DBMS helps in controlling redundancy. 2. Restricting unauthorized access: When multiple users share a database, it is likely that some users will not be authorized to access all information in the database. Eg:-financial database is often considered, and hence only authorized person can access data. In addition some users may be permitted only to retrieve data, whereas others are allowed both to retrieve and t? update. Typically, users or some users group are given account numbers protected by some passwords, which they can be used to access the database. A DBMS should provide a security and authorization subsystem. 3. Providing persistent storage for programs objects and data structures: Database can be used to provide persistent storagefor programs object and data structures. This is one of the main 'reasons for the emergence of the object oriented database systems.Programming language typically have complex data structure such as record types in Pascal or class definitions in C++. The values of program vafiables are discarded once a program terminates, unless the programmer explicitly stores them in permanents files, which often involves converting these complex structures into a format suitable for file storage. When the need arise to read this a data once more, the programmer must convert from the file format to the program variable structure. DBMS software automatically any necessary converSIOns. 4. Permitting Interfacing and actions using rules: Some database system provides capabilities for defining deduction rules for interferencing new information from the stored database facts. Such systems are called deductive database systems. 5. Providing multiple user interfaces: Because many types of users with varying levels of technical knowledge use a database, aDBMS should provide a variety of user interfaces. These includes query languages for casual users, programming language interfaces for application programmers, forms and commands code for parametric users, and menu driven interfaces are commonly known as graphical user interfaces. 6. Representing complex relationships among data: A database may include numerous varieties of data that are inter elated in many ways. A DBMS must have the capabilities to represents a variety of complex relationships among data as well as to retrieve and update rdated data easily and effectively.

7. Enforcing integrity constraints: Most database applications have certain integrity constraints that must hold for the data. A DBMS should provide capabilities for defining and enforcing these constraints.

32

The simplest type of integrity constraints involves specifying a data type for each data item. Some constraints can be specified to the DBMS and automatically enforced. Others constraints may have to be checked by update programs or at the time of data entry. 8. Providing' backup and recovery: A DBMS must provide facilities for recovering from hardware or software failures. The backup and recovery system of the DBMS is responsible for recovery. eg: - if the computer system fails in the middle of a complex update program, the recovery subsystem is responsible for making sure that the database is restored to the state it was in before the program started executing. INTRODUCTION TO DATABASE SYSTEM: A database system involves four major components: data, hardware, software, and users. DATA: Data is defined as the representation of facts, concepts of instructions in a formal manner suitable for communication or processing by human's or by automatic means. Data refers to which is actually stored in database. Data are collection of unorganized facts but able to be organized in to useful information. Data can be of following different types: 1. INTEGRATED DATA: A collection of data is integrated if data is logically consistent i.e. the duplicate data items are agree with one another. A database can be considered as the unification of several distinct data files, with any redundancy among those files are eliminated. Data is said to be integrated data. 2. SHARED DATA: By shared we mean that individual pieces of data in the database can be shared among different users, in the sense that each of those users can have access to same piece of data, possibly for different purposes. Different users can effectively even access the same piece of data at the same time. HARDWARE: The hardware components of the system consist of: 1. The secondary storage volunies most magnetic disks that are used to hold the stored data, together with the I/O devices (disc drives etc.) device controllers I/O channels. 2. The hardware processor and associated main memory that are used to support the execution of the database system software. SOFTWARE: Between the physical database itself i.e. the data as physically stored and the users of the system is a layer of software, known variously as the database manager or database server or most commonly, the database management system. All request for access to database are handled by the DBMS like for adding or removing files or tables, retrieving

33

data from· and updating data is such files or tables, these all facilities are provided by the DBMS. One general function provided by the DBMS is the shielding of the database users from hardware level details much as programming language system shield application programmers from hardware level details.

34

Sign up to vote on this title
UsefulNot useful