Program-1 1. Login To Oracle by User Name Given by You

You might also like

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

Program-1

1. Login to oracle by user name given by you

2. See list of tables

3. View today’s date


4. See list of all Eviormental variables

5. Perform some mathematical operation by using dual


6. Create table student with following column

7. Display Structure of table

8. See records of table

9. Insert the following Data


10. See all records of table

11. Describe structure of table and commit data


12. Add new column email, type varchar2(15)

13. See records & structure of table

14. Set Email of all records to btech@gmail.com


15. See all records of table

16. Rollback the Email data & see all records


17. Set the email of ‘Amit ’ to abc@xyz

18. See records of table


19. Add 5 more records and complete the table

20. See all records


21. Commit & clear screen

22. Set line size 20


23. Set line size 200 &see all records

24. Set pagesize 7


25. Set page size 500
26. Set heading off

27. Set heading on & display all records


28. Make Duplicate copy of table student

29. Truncate student table

30. Drop student tabe


31. See all tables
32. Show user

33. Disconnect

PROGRAM – 2
Create a new table “Employee”
Insert the following data into the table using any method:
EmpCode Name Salary 101 Amit 30000 201 Kapil 22000 301 Rohit 45000 401 Amit
27000 401 Amit 27000.

Try to Add the following new record EmpCode


Name Salary 901 Bhattacharya 33000
Increase the size of name column to 25.
. See the structure of table again

Now again try to add the above record again.


See the records of the table
Reduce the size of name column to 5. (Note the output even if it is an error)
Commit the data and see all records.
a) Select name from employee;
b) Select name, name, name, name from employee;
c) Select name, empcode from employee;
d) Select name, empcode from employee order by salary;
e) Select name, Salary, salary + 500 , salary-50000 from employee;
f) Select sum(salary) from employee;
g) Select min(salary) from employee;
h) Select max(salary) from employee;
. Display name, actual salary, 50 % increased salary of all employees.

Make a copy of employee table as “NewEmp” table with all records.


See the records of “NewEmp” table.

See the records of “NewEmp” table.


Make a copy of employee table as “Emp2” table with no (Zero) records.

See the records of all 3 table (Employee, NewEmp and Emp2)


See the structure of all 3 table (Employee, NewEmp and Emp2).

Create a new table “MyTable” from employee table with only Name and Salary
columns.
Drop the columns “name” and “empcode” from NewEmp table. 30. See the records of
NewEmp Table.

Truncate the “Mytable” table. (do not use delete command)


See the records of “MyTable” table
Rollback
Again See the records of “MyTable” table. (What is your observation?)

Drop the “MyTable” table


See the records of “MyTable” table
Rollback
Again See the records of “MyTable” table. (What is your observation?)

PROGRAM-3
Write queries for the following outputs.

1. Show all records

2. Show record of all students living in Delhi


3.Show record of all student whose name starts with “A”.

4.Show record of all student whose second alphabet of name is “a”.

5.Show record of all student whose name ends with “it”.


6.Show records of all students having age greater than 25 & living in Dehradun.

7.Show the list of all cities (names of cities should not be repeated)
8.Show the names students alphabetically in ascending order.

9.Display name in lowercase, cities in uppercase.


10.Display those records which do not have pin code

=>Insert the following data further into the same table.

Roll No Name City Pincode Age


12 Gaurav Rampur 312125
Manish 314136
14 Aviral 319143 29
15 Gwaliar 313149 25

11.A. Assign Roll No. “13” to Manish.


11.B. Assign the name “Abhijeet” to Roll No. 15
11.C. Increase all age by 3 years.
11.D. Set the age of all students living in Meerut to “25”.
12. Add a new column named “Balance”, type number to the Students table.
13. Set the balance of all students to Rs. 20,000/-. See All records. Commit.
14. Increase the balance by Rs. 500/- for all Bombay & Delhi students. See All records.
Commit.

15.Show the total balance amount of all students.

16.Show the maximum balance


17.Create a new table “student2” as a copy of Students with all rows from Students table
PROGRAM-4
<1>

SQL> select upper('gehu') from dual;

<2>

SQL> select lower('GEHU') from dual;


<3>
SQL> select initcap(‘hello world') from dual;

<4>
SQL> select ltrim(' hai') from dual;
<5>
SQL> select rtrim('hai ') from dual;

<6>
SQL> select rtrim(' hai ') from dual;

<7>
SQL> select concat('GEHU',' university') from dual;

<8>
SQL> select length('GEHU’) from dual;

<9>
SQL> select replace('GEHU university', 'GEHU','GEU') from dual;

<10>
SQL> select substr('UNIVERSITY', 4,6) from dual;

<11>
SQL> select rpad('GEHU',10,'*')from dual;

<12>
SQL> select lpad('GEHU',10,'*') from dual;

<13>
SQL> select Instr('COCOON',’O’) from dual;

<14>
SQL> select replace('Dany','y','ie') from dual;

<15>
SQL> select translate('cold','ld','ol') from dual;

<16>
SQL> select sysdate from dual;

<17>
SQL> select round(sysdate)from dual;

<18>
SQL> select add_months(sysdate,3)from dual;

<19>
SQL> select last_day(sysdate)from dual;

<20>
SQL> select sysdate+20 from dual;

<21>
SQL> select next_day(sysdate,'tuesday')from dual;

NUMERIC FUNCTIONS:
<1>
SQL> select round(15.6789)from dual;

<2>
SQL> select ceil(23.20)from dual;

<3>
SQL> select floor(34.56)from dual;

<4>
SQL> select trunc(15.56743)from dual;

<5>
SQL> select sign(-345)from dual;
<6>
SQL> select abs(-70)from dual;

MATH FUNCTIONS:
<1>
SQL> select abs(45) from dual;

<2>
SQL> select power(10,12) from dual;
<3>
SQL> select mod(11,5) from dual;

<4>
SQL> select exp(10) from dual;

<5>
SQL> select sqrt(225) from dual;
PROGRAM – 5
Constraints-1

1. WAQ (write a query) to create an “Account” table with following constraints:


All constraints to be given ONLY at column level
AccountNo Number Primary Key
CustName Varchar2 Not Null
AccountType Varchar2 Default Value ‘Saving’
Balance Number >1000
PassportNo Varchar2 Unique

2. See and note the structure of above created table using “describe”. (Note structure
carefully)
and write answers for the following questions:
a. Which constraints are displayed in the structure?
b. Can you tell from the structure which column is Unique?
c. Can you tell from the structure which column is Primary and Which Not
Null?
d. Can you tell from the structure which column has check constrain?.
3. See the contents of “User_Constraints” table and note the constraint number and type
of constraints for your above table. (You can attach printout of this table)

4. Insert the following data in the above table (In case of Error , Correct the data yourself)

117501 Puneet Saving 1100 B9895


117502 Saving 2100 A9895
117507 Rohit Current 500 C9898
117507 Rohit Current 5000 C9898
117504 Kumar Saving 1100 C9898
117508 Shweta Saving 7100 A6789
117503 Deepak Current 12000

Write Each Query without using substitution and note the output of each.

Commit The Data


5. WAQ (write a query) to create an “Account2” table with following constraints:

AccountNo Number Primary Key


CustName Varchar2 Not Null
AccountType Varchar2 Default Value ‘Current’
Balance Number >5000
PassportNo Varchar2 Unique

6. See and note the structure of above created table using “describe”. (Note structure
carefully)

7. WAQ (write a query) to create an “Account3” table with following constraints:

AccountNo Number Primary Key (at Row/Table Level)


CustName Varchar2 Not Null (Only at Table / Row Level)

(if an error comes, first note the error and then correct the query)
8. See the contents of “User_Constraints” table and note the constraint number and type
of constraints for your above tables.

9. Drop the NOT NULL Constraint from Account3 Table.

10. WAQ (write a query) to create an “Account4” table with following constraints:

AccountNo Number Primary Key (Constraint Name : PKey)


CustName Varchar2 Not Null (Constraint Name :NNull )
AccountType Varchar2 Default Value ‘Current’
Balance Number >5000 (Constraint Name :ChkBal)
PassportNo Varchar2 Unique (Constraint Name : UU)

11. See the contents of “User_Constraints” table and note the constraint number and
type
of constraints for your above table.

12. Drop the Primary Key & Unique Constraint from Account4 Table.

13. WAQ (write a query) to create an “Account5” table without any constraints:

AccountNo Number (No constraint)


CustName Varchar2 (No constraint)
Balance Number (No constraint)
14. Insert the following data in the above table:

8111 Puneet 1000


8111 Mudit 2000
8114 Kumar 3000
8115 Shweta 500
8115 Deepak 6000
15. See the structure of Account5 table

16. Add the primary key constraint for AccountNo in Account5 Table
(If an error comes, note the error and write the reason)

17. In case of error in above ques, rectify the above table contents and repeat above
Question
(Write all the steps and queries)
18. See the contents of “User_Constraints” table and search the name of Account5 table
in it.

19. Add UNIQUE constraint in Account5 Table for CustName field.

20. Add Check constraint in Account5 Table for Balance field. ( Amount> 1500)

21. In case of error in above ques, rectify the above table contents and repeat above
Question
(Write all the steps and queries)

22. See the contents of “User_Constraints” table and search the name of Account5 table
in it.
(Note the constraint number for account5 table)

You might also like