A

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

SQL> set lines 150;

SQL> set pages 150;


SQL> select * from emp19;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


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

14 rows selected.

SQL> select * from dept19;

DEPTNO DNAME LOC

---------- -------------- -------------

10 ACCOUNTING NEW YORK

20 RESEARCH DALLAS

30 SALES CHICAGO

40 OPERATIONS BOSTON

50 IT CALIFORNIA

SQL> alter table emp19


2 drop column sno;
alter table emp19
*
ERROR at line 1:
ORA-12988: cannot drop column from table owned by SYS

SQL> update table emp19 set sno=1 where empno=7839;


update table emp19 set sno=1 where empno=7839
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> update emp19 set sno=1 where empno=7839;

1 row updated.

SQL> update emp19 set sno=2 where empno=7698;

1 row updated.

SQL> update emp19 set sno=3 where empno=7782;

1 row updated.

SQL> update emp19 set sno=4 where empno=7566;

1 row updated.

SQL> update emp19 set sno=5 where empno=7788;

1 row updated.

SQL> update emp19 set sno=6 where empno=7902;

1 row updated.

SQL> update emp19 set sno=7 where empno=7369;

1 row updated.

SQL> update emp19 set sno=8 where empno=7499;

1 row updated.

SQL> update emp19 set sno=9 where empno=7521;

1 row updated.

SQL> update emp19 set sno=10 where empno=7654;

1 row updated.

SQL> update emp19 set sno=11 where empno=7844;

1 row updated.

SQL> update emp19 set sno=12 where empno=7876;

1 row updated.
SQL> update emp19 set sno=13 where empno=7900;

1 row updated.

SQL> update emp19 set sno=14 where empno=7934;

1 row updated.

SQL> select * from emp19;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO SNO
---------- ---------- --------- ---------- --------- ---------- ----------
---------- ----------
7839 KING PRESIDENT 17-NOV-81 5000
10 1
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30 2
7782 CLARK MANAGER 7839 09-JUN-81 2450
10 3
7566 JONES MANAGER 7839 02-APR-81 3475
20 4
7788 SCOTT ANALYST 7566 19-APR-87 3500
20 5
7902 FORD ANALYST 7566 03-DEC-81 3500
20 6
7369 SMITH CLERK 7902 17-DEC-80 1300
20 7
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30 8
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30 9
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30 11
7876 ADAMS CLERK 7788 23-MAY-87 1600
20 12
7900 JAMES CLERK 7698 03-DEC-81 950
30 13
7934 MILLER CLERK 7782 23-JAN-82 1300
10 14

14 rows selected.

SQL> select * from emp19 group by sno having mod(sno,2)=1;


select * from emp19 group by sno having mod(sno,2)=1
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression

SQL> show errors;


No errors.
SQL> select * from emp19 where sno%2=0;
select * from emp19 where sno%2=0
*
ERROR at line 1:
ORA-00911: invalid character

SQL> select * from emp19 where sno % 2 = 0;


select * from emp19 where sno % 2 = 0
*
ERROR at line 1:
ORA-00911: invalid character

SQL> select * from emp19


2 group by sno having mod(sno,2)=1;
select * from emp19
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression

SQL> select * from emp19


2 where sno in(select sno from emp19 where sno%2 = 0);
where sno in(select sno from emp19 where sno%2 = 0)
*
ERROR at line 2:
ORA-00911: invalid character

SQL> show errors;


No errors.
SQL> select * from(select rownum, sno, ename from emp19)
2 where mod(rownum,2)=0;

no rows selected

SQL> select * from(select sno, ename from emp19)


2 where mod(sno,2)=0;

SNO ENAME

---------- ----------

2 BLAKE

4 JONES

6 FORD

8 ALLEN

10 MARTIN

12 ADAMS

14 MILLER

7 rows selected.

SQL> select * from emp19


2 where mod(sno,2)=0;
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO SNO
---------- ---------- --------- ---------- --------- ---------- ----------
---------- ----------
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30 2
7566 JONES MANAGER 7839 02-APR-81 3475
20 4
7902 FORD ANALYST 7566 03-DEC-81 3500
20 6
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30 8
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30 10
7876 ADAMS CLERK 7788 23-MAY-87 1600
20 12
7934 MILLER CLERK 7782 23-JAN-82 1300
10 14

7 rows selected.

SQL> set lines 150;


SQL> set pages 150;
SQL> select * from emp19
2 where mod(sno,2)=0;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO SNO
---------- ---------- --------- ---------- --------- ---------- ----------
---------- ----------
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30 2
7566 JONES MANAGER 7839 02-APR-81 3475
20 4
7902 FORD ANALYST 7566 03-DEC-81 3500
20 6
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30 8
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30 10
7876 ADAMS CLERK 7788 23-MAY-87 1600
20 12
7934 MILLER CLERK 7782 23-JAN-82 1300
10 14

7 rows selected.

SQL> select * from emp19


2 where mod(sno,2)=1;

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO SNO
---------- ---------- --------- ---------- --------- ---------- ----------
---------- ----------
7839 KING PRESIDENT 17-NOV-81 5000
10 1
7782 CLARK MANAGER 7839 09-JUN-81 2450
10 3
7788 SCOTT ANALYST 7566 19-APR-87 3500
20 5
7369 SMITH CLERK 7902 17-DEC-80 1300
20 7
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30 9
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30 11
7900 JAMES CLERK 7698 03-DEC-81 950
30 13

7 rows selected.

SQL> CREATE TABLE "AGENTS"


2 (
3 "AGENT_CODE" CHAR(6) NOT NULL PRIMARY KEY,
4 "AGENT_NAME" CHAR(40),
5 "WORKING_AREA" CHAR(35),
6 "COMMISSION" NUMBER(10,2),
7 "PHONE_NO" CHAR(15),
8 "COUNTRY" VARCHAR2(25)
9 );

Table created.

SQL> INSERT INTO AGENTS VALUES ('1', 'Ramasundar', 'Bangalore', '0.15', '077-
25814763', '');

1 row created.

SQL> INSERT INTO AGENTS VALUES ('2', 'Alex ', 'London', '0.13', '075-12458969',
'');

1 row created.

SQL> INSERT INTO AGENTS VALUES ('A008', 'Alford', 'New York', '0.12', '044-
25874365', '');

1 row created.

SQL> INSERT INTO AGENTS VALUES ('3', 'Ravi Kumar', 'Bangalore', '0.15', '077-
45625874', '');

1 row created.

SQL> INSERT INTO AGENTS VALUES ('4', 'Santakumar', 'Chennai', '0.14', '007-
22388644', '');

1 row created.

SQL> INSERT INTO AGENTS VALUES ('5', 'Lucida', 'San Jose', '0.12', '044-52981425',
'');

1 row created.

SQL> delete from agents where agent_code='A008';

1 row deleted.
SQL> select * from agents;

AGENT_ AGENT_NAME WORKING_AREA


COMMISSION PHONE_NO COUNTRY
------ ---------------------------------------- -----------------------------------
---------- --------------- -------------------------
1 Ramasundar Bangalore
.15 077-25814763
2 Alex London
.13 075-12458969
3 Ravi Kumar Bangalore
.15 077-45625874
4 Santakumar Chennai
.14 007-22388644
5 Lucida San Jose
.12 044-52981425

SQL> set lines 150;


SQL> set pages 150;
SQL> select * from agents;

AGENT_ AGENT_NAME WORKING_AREA


COMMISSION PHONE_NO COUNTRY
------ ---------------------------------------- -----------------------------------
---------- --------------- -------------------------
1 Ramasundar Bangalore
.15 077-25814763
2 Alex London
.13 075-12458969
3 Ravi Kumar Bangalore
.15 077-45625874
4 Santakumar Chennai
.14 007-22388644
5 Lucida San Jose
.12 044-52981425

SQL> delete from AGENTS


2 where mod(AGENT_CODE,2)=1;

3 rows deleted.

SQL> select * from agents;

AGENT_ AGENT_NAME WORKING_AREA


COMMISSION PHONE_NO COUNTRY
------ ---------------------------------------- -----------------------------------
---------- --------------- -------------------------
2 Alex London
.13 075-12458969
4 Santakumar Chennai
.14 007-22388644

SQL> spool off;

You might also like