Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday, 6 August 2014

Fetching Data from Oracle

Fetching data from a table:-
To understand this we will create EMPLOYEE table and will try to retrieve some data from employee table.
CREATE TABLE EMPLOYEE (EMPNO NUMBER, EMPNAME VARCHAR2 (10), SALARY NUMBER);

INSERT INTO EMPLOYEE VALUES (1,’CHANCHAL’, 5000);
INSERT INTO EMPLOYEE VALUES (2, JACK’, 6000);
INSERT INTO EMPLOYEE VALUES (3,’JOHN’, 7000);
INSERT INTO EMPLOYEE VALUES (4,’MIKE’, 8000);
INSERT INTO EMPLOYEE VALUES (5,’SCOTT’, 9000);

Above we have inserted some values in EMPLOYEE table. Now suppose I want to retrieve all the records from EMPLOYEE table then we will fire query like:-
SELECT * FROM EMPLOYEE;



If I want  to fetch only the rows which are having salary more than 7000 then I can retrieve it by specifying where condition:-
If I want to retrieve row only for 1 EMPNO then I will use = sign.

tly2 C e w p�N �W ll not be saved in your table.







What is modifying a table?
 Modify can be used to modify data type of the existing tables columns. Suppose if you are required to modify DEPT_NO column to VARCHAR2 data type of EMPLOYEE table.
Remember while modifying data type of the column; you need to make sure that the column is empty in case you are trying to switch from number to char or varchar2. In case you have to increase the length of the varchar2 data type then you can do it easily but you can’t modify data type from bigger length to smaller length. See the example above. I have created table called
DEPARTMENT which is having DEPT_NO and DEPT_TYPE columns. Initially I have given DEPT_NO column number data type. After creating table I have modified that to varchar2 data type having length 10 and inserted some values into the DEPARTMENT table. After that I have changed the length of the DEPT_NO column to varchar2 with length 15 and inserted 15 length values. Now I want to again modify the DEPT_NO column and make the length 14. I tried to perform that but it does not allow me to decrease the length of the column data type while there is a value already present which is having  more than the length I want to modify.
In short you cannot directly switch to another data type without empting column first and you cannot modify less length of data type while there is a value having more length than you want to modify.
ng" | � t e x�Y ��W v:shape>


Type username (schema name), password and host string:-
Click OK.
Oracle sql developer:-
Install oracle sql developer or click on sql developer.exe file, it will show you initialization process:-
Click on
Once you click on  you will land onto the below screen. Type the name of the connection as you want, type the username, password, and then click on save password checkbox, type host name or ip_address of the machine, specify the port number and database SID or Service name, after putting all the information click on test  or you can directly click on connect button:-

Once you click on save button, the connection will be saved in the connection tab so you can use it again and again. You can see below the name CONNECTION_TO_SCOTT is present in the connection tab.


If you want to add more connection then just click on  and put all the required information. After you saved it, it will be listed in connection tab.


No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.