0% found this document useful (0 votes)
12 views14 pages

DDL and DML

The document details a SQL*Plus session where a user attempts to log in to an Oracle Database, unlocks user accounts, creates and manipulates tables, and performs various SQL operations including selecting, dropping, and purging tables. It shows the creation of a new table 'mobile', the backup of the 'emp' table, and the use of flashback to restore a dropped table. The session concludes with the dropping of the 'xyz' table and various queries to check the status of tables in the database.

Uploaded by

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

DDL and DML

The document details a SQL*Plus session where a user attempts to log in to an Oracle Database, unlocks user accounts, creates and manipulates tables, and performs various SQL operations including selecting, dropping, and purging tables. It shows the creation of a new table 'mobile', the backup of the 'emp' table, and the use of flashback to restore a dropped table. The session concludes with the dropping of the 'xyz' table and various queries to check the status of tables in the database.

Uploaded by

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

SQL*Plus: Release 11.2.0.1.

0 Production on Mon Jul 22 14:13:59 2024

Copyright (c) 1982, 2010, Oracle. All rights reserved.

Enter user-name: scott


Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied

Enter user-name: system


Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied

Enter user-name: sys as sysdba


Enter password:

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> alter user scott account unlock identified by Oracle1234;

User altered.

SQL> alter user hr account unlock identified by Oracle1234;

User altered.

SQL> connect
Enter user-name: scott
Enter password:
Connected.
SQL> set lines 200 pages 200;
SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
XYZ TABLE

6 rows selected.

SQL> create table mobile


2 (mid number(2) primary key,
3 brand varchar(15) not null unique,
4 cost number(6) not null);

Table created.

SQL> select * from emp;


EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10

14 rows selected.

SQL> create table empback


2 as
3 select * from emp;

Table created.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
EMPBACK TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

8 rows selected.

SQL> describe backup;


ERROR:
ORA-04043: object backup does not exist
SQL> describe empback;
Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ --------
----------------------------------------------------------------------------
EMPNO
NUMBER(4)
ENAME
VARCHAR2(10)
JOB
VARCHAR2(9)
MGR
NUMBER(4)
HIREDATE
DATE
SAL
NUMBER(7,2)
COMM
NUMBER(7,2)
DEPTNO
NUMBER(2)

SQL> select * from empback;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10

14 rows selected.

SQL> create table empbackk


2 as
3 select * from emp;

Table created.

SQL> select * from empbackk;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10

14 rows selected.

SQL> truncate table empbackk;

Table truncated.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
EMPBACK TABLE
EMPBACKK TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

9 rows selected.

SQL> describe empbackk;


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ --------
----------------------------------------------------------------------------
EMPNO
NUMBER(4)
ENAME
VARCHAR2(10)
JOB
VARCHAR2(9)
MGR
NUMBER(4)
HIREDATE
DATE
SAL
NUMBER(7,2)
COMM
NUMBER(7,2)
DEPTNO
NUMBER(2)

SQL> select * from empbackk;

no rows selected

SQL> select * from empback;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10

14 rows selected.

SQL> drop table empback;

Table dropped.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BIN$WPJaKFFfTa2zkBnYl2Q2Kw==$0 TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
EMPBACKK TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

9 rows selected.

SQL> drop table empbackk;

Table dropped.

SQL> purge table empbackk;

Table purged.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BIN$WPJaKFFfTa2zkBnYl2Q2Kw==$0 TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

8 rows selected.

SQL> select * from empback;


select * from empback
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> desc empback;


ERROR:
ORA-04043: object empback does not exist

SQL> show recyclebin;


ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
EMPBACK BIN$WPJaKFFfTa2zkBnYl2Q2Kw==$0 TABLE 2024-07-22:14:25:33
SQL> flashback table empback to before drop;

Flashback complete.

SQL> show recyclebin;


SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
EMPBACK TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

8 rows selected.

SQL> select * from empback;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10

14 rows selected.

SQL> drop table empback;

Table dropped.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BIN$duiXm/16Su658vlz/cPvSw==$0 TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

8 rows selected.

SQL> show recyclebin;


ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
EMPBACK BIN$duiXm/16Su658vlz/cPvSw==$0 TABLE 2024-07-22:14:34:48
SQL> purge table empback;

Table purged.

SQL> show recyclebin;


SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

7 rows selected.

SQL> desc xyz;


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ --------
----------------------------------------------------------------------------
SNAMES
NOT NULL NCHAR(1)

SQL> desc aa;


Name
Null? Type

-----------------------------------------------------------------------------------
------------------------------ --------
----------------------------------------------------------------------------
ABC
NUMBER(3)

SQL> set lines 100 pages 100;


SQL> desc aa;
Name Null? Type
----------------------------------------------------- --------
------------------------------------
ABC NUMBER(3)

SQL> desc xyz;


Name Null? Type
----------------------------------------------------- --------
------------------------------------
SNAMES NOT NULL NCHAR(1)

SQL> select * from xyz;

no rows selected

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
MOBILE TABLE
SALGRADE TABLE
XYZ TABLE

7 rows selected.

SQL> drop table xyz purge;

Table dropped.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
MOBILE TABLE
SALGRADE TABLE

6 rows selected.

SQL> show recyclebin;


SQL> purge table aa;
purge table aa
*
ERROR at line 1:
ORA-38307: object not in RECYCLE BIN

SQL> desc mobile;


Name Null? Type
----------------------------------------------------- --------
------------------------------------
MID NOT NULL NUMBER(2)
BRAND NOT NULL VARCHAR2(15)
COST NOT NULL NUMBER(6)

SQL> insert into mobile values('1','Mi','20000');

1 row created.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000

SQL> insert into mobile values('2','oppo','20300');

1 row created.

SQL> insert into mobile values('3','oneplus','20780');

1 row created.

SQL> insert into mobile values('4','samsung','30780');

1 row created.

SQL> insert into mobile values('5','vivo','39780');

1 row created.

SQL> insert into mobile values('6','apple','32780');

1 row created.

SQL> insert into mobile values('7','realme','33780');

1 row created.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000
2 oppo 20300
3 oneplus 20780
4 samsung 30780
5 vivo 39780
6 apple 32780
7 realme 33780

7 rows selected.

SQL> update mobile


2 set brand='galaxy'
3 where mid='4';

1 row updated.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000
2 oppo 20300
3 oneplus 20780
4 galaxy 30780
5 vivo 39780
6 apple 32780
7 realme 33780

7 rows selected.

SQL> update mobile set brand='iphone' where mid='6';

1 row updated.

SQL>
SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000
2 oppo 20300
3 oneplus 20780
4 galaxy 30780
5 vivo 39780
6 iphone 32780
7 realme 33780

7 rows selected.

SQL> update mobile set cost='50000' where mid='7';

1 row updated.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000
2 oppo 20300
3 oneplus 20780
4 galaxy 30780
5 vivo 39780
6 iphone 32780
7 realme 50000

7 rows selected.

SQL> update mobile set brand='twoplus',cost='60000' where mid='3';

1 row updated.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000
2 oppo 20300
3 twoplus 60000
4 galaxy 30780
5 vivo 39780
6 iphone 32780
7 realme 50000

7 rows selected.

SQL> update mobile set cost='100000' where mid in('6','7');

2 rows updated.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 20000
2 oppo 20300
3 twoplus 60000
4 galaxy 30780
5 vivo 39780
6 iphone 100000
7 realme 100000

7 rows selected.

SQL> update mobile set cost='100000' ;

7 rows updated.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 100000
2 oppo 100000
3 twoplus 100000
4 galaxy 100000
5 vivo 100000
6 iphone 100000
7 realme 100000
7 rows selected.

SQL> delete from mobile where mid='5';

1 row deleted.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 100000
2 oppo 100000
3 twoplus 100000
4 galaxy 100000
6 iphone 100000
7 realme 100000

6 rows selected.

SQL> delete from mobile where mid in('3','4');

2 rows deleted.

SQL> select * from mobile;

MID BRAND COST


---------- --------------- ----------
1 Mi 100000
2 oppo 100000
6 iphone 100000
7 realme 100000

SQL> delete from mobile;

4 rows deleted.

SQL> select * from mobile;

no rows selected

SQL> create table trains


2 (tno number(3) primary key,
3 tname varchar(15) not null);

Table created.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID


------------------------------ ------- ----------
AA TABLE
BONUS TABLE
DEPT TABLE
EMP TABLE
MOBILE TABLE
SALGRADE TABLE
TRAINS TABLE

7 rows selected.
SQL> select * from trains;

no rows selected

SQL> insert into trains values('1','chennaiexpress');

1 row created.

SQL> insert into trains values('2','goaexpress');

1 row created.

SQL> select * from trains;

TNO TNAME
---------- ---------------
1 chennaiexpress
2 goaexpress

SQL>

You might also like