Apr 18, 2010

Using LIST, n, APPEND commands in SQL * plus - Oracle

In earlier post http://angeldeeps.blogspot.com/2010/04/sql-plus-oracle-editing-commands.html I discussed about list of editing commands used in SQL * plus - Oracle.

Here, I am going to discuss few of the commands from that list.

//Here I have created a table called emp having empno and empname fields.

SQL> create table emp (empno number, empname varchar(20));


Table created.

//Inserting few records into emp table
SQL> insert into emp values(1,'Deepika');


1 row created.


SQL> insert into emp values(2, 'Aarti');


1 row created.


SQL> insert into emp values(3, 'Rupal');


1 row created.


SQL> insert into emp values(4, 'Ratna');


1 row created.


SQL> insert into emp values(5, 'Sonal');


1 row created.


//List command will show your last command executed
SQL> list
  1* insert into emp values(5, 'Sonal')


//Retrieving values to view

SQL> select * from emp;


     EMPNO EMPNAME
---------- --------------------
         1 Deepika
         2 Aarti
         3 Rupal
         4 Ratna
         5 Sonal

//Retrieving particular field records
SQL> select empno
  2  , empname from emp;


     EMPNO EMPNAME
---------- --------------------
         1 Deepika
         2 Aarti
         3 Rupal
         4 Ratna
         5 Sonal

//n - here n is 1 means it will show me statement at that line no
SQL> 1
  1* select empno

//Added jobcode field to emp table

SQL> alter table emp add (jobcode varchar(10));


Table altered.


SQL> select * from emp;


     EMPNO EMPNAME              JOBCODE
---------- -------------------- ----------
         1 Deepika
         2 Aarti
         3 Rupal
         4 Ratna
         5 Sonal

//Updating jobocde 
SQL> update emp set jobcode = 'A001' where empno =1;


1 row updated.


SQL> update emp set jobcode = 'B001' where empno = 2;


1 row updated.


SQL> update emp set jobcode = 'C001' where empno = 3;


1 row updated.


SQL> update emp set jobcode = 'D001' where empno = 4;


1 row updated.


SQL> update emp set jobcode = 'E001' where empno = 5;


1 row updated.

//retrieving particular field records

SQL> select empname
  2  from emp;


EMPNAME
--------------------
Deepika
Aarti
Rupal
Ratna
Sonal

// A - it will append jobcode to my last statement executed
SQL> A, jobcode;
  2* from emp, jobcode


//L will show last statement 
SQL> L
  1  select empname
  2* from emp, jobcode



SQL> select * from emp;


     EMPNO EMPNAME              JOBCODE
---------- -------------------- ----------
         1 Deepika              A001
         2 Aarti                B001
         3 Rupal                C001
         4 Ratna                D001
         5 Sonal                E001


SQL> L
  1* select * from emp


//C - will change. Here I am changing my last statement's emp table with dept table. So my query will now be select * from dept;
SQL> c/emp/dept
  1* select * from dept


SQL> L
  1* select * from dept

No comments:

Post a Comment