Attributes-I'd, Name, Duration, Fees
Attributes-I'd, Name, Duration, Fees
Que:= Display the course where the fees is less then 50000.
Syntax:=[SELECT * FROM table_name WHERE condition;]
Code:= select *from course where fees<50000;
Output:=
Que:= Display the course where the fees is more then 50000.
Syntax:=[ SELECT * FROM table_name WHERE condition;]
Code:= select *from course where fees>50000;
Output:
Que:= Display the course where the fees is equal then 50000.
Syntax:=[ SELECT * FROM table_name WHERE condition;]
Code:= select *from course where fees=50000;
Output:=
Que:= Display the courses which start with H and end with g.
Syntax:=[SELECT * FROM table_name WHERE col_name LIKE ‘start_word%last_word’;]
Code:= select * from course where name like 'H%g';
Output:=
B-Restricting and sorting data:-
Que:= Display the course name in assending order.
Syntax:=[SELECT * FROM table_name ORDER BY col_name;]
Code:= select * from course order by name;
Output:=
Output:=
Que:= Find the length of the course_name from the given table.
Syntax:=[SELECT col_name,LENGTH(col_name) FROM tab_name;]
Code:= select name,length(name)from course;
Output:=
Que:= Return a portion of the string from a given start point to end point.
Syntax:=[SELECT col_name,SUBSTR(col_name,stratindex,length) FROM tab_name;]
Code:= select name,substr(name,3,2)from course;
Output:=
Que:=Right join.
Syntax:=[SELECT col_name1,col_name2,..col_nameN FROM tab_name RIGHT JOIN ON
tab_name1.reference_colname= tab_name2.primary_colname;]
Code:= select id,name,c_name,duration From student right join course On
student.course_id=course.c_id;
Output:=
Que:= Full Join.
Syntax:=[SELECT col_name1,col_name2,..col_nameN FROM tab_name FULL JOIN ON
tab_name1.reference_colname= tab_name2.primary_colname;]
Code:= select id,name,c_name,duration From student Full join course On
student.course_id=course.c_id;
Output:=
Que:=count()
Syntax:=[SELECT COUNT(col_name) FROM tab_name WHERE COL_NAME LIKE ‘word%’;]
Code:= select count(c_name) from course where c_name like 'B%';
Output:=
Que:= Sum()
Syntax:=[SELECT SUM(col_name) FROM tab_name;]
Code:= select sum(fee) from course;
Output:=
Que:=min()
Syntax:=[SELECT * FROM tab_name WHERE col_name=(SELECT MIN(col_name) FROM tab_name);]
Code:= select * from course where fee=(Select min(fee) from course);
Output:=
Que:max()
Syntax:=[SELECT * FROM tab_name WHERE col_name=(SELECT MAX(col_name) FROM tab_name);]
Code:= select * from course where fee=(Select max(fee) from course);
Output:=
Que:=avg()
Syntax:=[SELECT AVG(col_name) FROM tab_name;]
Code:=select avg(fee) from course;
Output:=
Que-Create a table “course” and insert a data of different 10 courses. Attributes-I'd , Name ,
Duration, Fees.
Syntax:=[INSERT INTO tab_name VALUES(val1,val2,val3);]
Code:=
B- Using DELETE statement:-
Que:For deleting a single row from the table.
Syntax:=[DELETE tab_name WHERE condition;] Code:= delete cours Where c_id=10;
Output:=
Que:= For deleting the entire data of table as well as it’s structure.
Syntax:=DROP TABLE tab_name;
Code:=DROP TABLE cours;
Output:=
Que:=Creating new table having specific fields but all the records from existing table.
Syntax:=[CREATE TABLE new_tab AS SELECT col_name1,col_name2 FROM tab_name;]
Code:=create table new_course1 as select c_id,c_name from course;
Output:
Que:=Creating new table having specific records but all fields from existing table.
Syntax:=[CREATE TABLE new_tab AS SELECT * FROM tab_name WHERE condition;]
Code:=create table new_course3 as select * from course where fee<80000;
Output:=
Que:=Creating new table having no records but all the fields from the existing table.
Syntax:=[CRAETE TABLE new_tab AS SELECT * FROM tab_name WHERE false_condition;]
Code:= create table new_course3 as select * from course where 1=2;
Output:=
B-Including Constraints:-
Que:=Not Null constraints.
Syntax:=[CREATE TABLE tab_name(col_name datatype) NOT NULL;]
Code:=create table coursedetils(c_id number(3) NOTT NULL);
Output:=
Que:=Unique constraints.
Syntax:=[CREATE TABLE tab_name(col_name datatype) UNIQUE;]
Code:=create table coursedetails(c_name varchar2(15) UNIQUE);
Output:=
Que:=Primary Key constraints.
Syntax:=[CREATE TABLE tab_name(col_name datatype) PRIMARY KEY;]
Code:= create table coursedetails(c_id number(3) PRIMARY KEY);
Output:=
Que:=Check constraints.
Syntax:=[CREATE TABLE tab_name(col_name datatype) CHECK(condition);]
Code:= create table coursedetails(fee number(15) CHECK(fee>=40000);
Output:=
Que:=Intersect operator.
Syntax:=[select col_name from tab_name intersect select col_name2 from tab_name2;]
Code:= select c_name from coursedetails intersect select name from student;
Output:=
Que:=Minus operator.
Syntax:=[SELECT col_name FROM tab_name MINUS SELECT col_name2 FROM tab_name2;]
Code:= select c_name from coursedetails minus select name from student;
Output:=
Output:
Output:=
Que:=Using If statement.
Syntax:=[ IF condition THEN statements;
END IF;]
Code:=
Output:=
Output:=
Output:=
Output:=
Que:=Using For loop.
Syntax:= FOR counter IN ini_value ..final_value LOOP
sequence_of_statements;
END LOOP;
Code:=
Output:=
Output:=
B-Writing Explicit Cursors
Que:=Using explicit cursor.
Syntax:=
Creating cursor:= CURSOR cursor_name IS select_statement;
Opening the Cursor:=OPEN cursor_name;
Fetching the cursor:= FETCH cursor_name INTO col_name1,col_name2,col_name3;
Closing the cursor:=Close cursor_name;
Code:=
Output:=
Que:=Using loops in cursor.
Code:=
Output:=
C-Handelling Exception
Syntax:=
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
WHEN exception1 THEN exception1-handling-statements
WHEN exception2 THEN exception2-handling-statements
WHEN exception3 THEN exception3-handling-statements
WHEN others THEN
exception3-handling-statements
END;
Code:=
Output:=
Pract-9 Procedure and Function.
A-Creating Procedure.
Que:=Create a procedure to find the minimum of two value.
Syntax:= CREATE OR REPLACE PROCEDURE procedure_name [(parameter_name[IN|OUT|IN
OUT] type [])] IS / AS
BEGIN
< procedure_body >
END procedure_name;
Code:=
Output:=
B-Creating Function:
Que:=Create a function totalcourse which counts the number of total courses of the
coursedetails table.
Syntax:= CREATE OR REPLACE FUNCTION function_name [parameter_name[IN|OUT|IN
OUT] type [, ...]] RETURN return_datatype IS / AS
BEGIN
<function_body >
END [function_name];
Code:=
Output:=
C-Managing Subprograms
Output:=
D-Creating Packages:-
Que:=Create a package.
Code:=
1-Creating package:
Syntax:=
CREATE OR REPLACE PACKAGE package_name IS
sub_program and public element declaration
..
END package_name;
Code:=
Output:=