IT Tutorial

SQL SELECT Statement and DESC Command in Oracle SQL | Oracle SQL Tutorials -2

Hi,

I will explain SQL SELECT Statement in Oracle SQL in this post of Oracle SQL Tutorial series.

Read the previous post of this tutorial series before this.

 

Introduction to Oracle SQL | Oracle SQL Tutorials -1

 

 

The SQL SELECT Statement

Most popular of SQL Command is the Select statement and The SELECT statement is used to query data from a database.

 

SELECT Syntax

If you use the * from, then you can query all the columns from related table.

 

SELECT * FROM table_name;


SQL> select * from hr.departments;  

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
           10 Administration                        200        1700
           20 Marketing                             201        1800
           30 Purchasing                            114        1700
           40 Human Resources                       203        2400
           50 Shipping                              121        1500
           60 IT                                    103        1400
           70 Public Relations                      204        2700
           80 Sales                                 145        2500
           90 Executive                             100        1700
          100 Finance                               108        1700
          110 Accounting                            205        1700

 

 

 

If you run the DESC TABLE, you can display the table description of table as follows.

 

You can display all columns of any table using the DESC command as follows.

DESC TABLE_NAME;

 

SQL> desc hr.departments
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 DEPARTMENT_ID                             NOT NULL NUMBER(4)
 DEPARTMENT_NAME                           NOT NULL VARCHAR2(30)
 MANAGER_ID                                         NUMBER(6)
 LOCATION_ID                                        NUMBER(4)

SQL>

 

If you want to display only specific columns, you can query the table as follows.

SELECT column1, column2,column3,column4 ...
FROM table_name;



SQL> SELECT DEPARTMENT_ID, DEPARTMENT_NAME FROM HR.DEPARTMENTS;

DEPARTMENT_ID DEPARTMENT_NAME
------------- ------------------------------
           10 Administration
           20 Marketing
           30 Purchasing
           40 Human Resources
           50 Shipping
           60 IT
           70 Public Relations
           80 Sales
           90 Executive
          100 Finance
          110 Accounting

 

You can query all column of table as follows.

 

SQL> SELECT DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID FROM HR.DEPARTMENTS;

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
           10 Administration                        200        1700
           20 Marketing                             201        1800
           30 Purchasing                            114        1700
           40 Human Resources                       203        2400
           50 Shipping                              121        1500
           60 IT                                    103        1400
           70 Public Relations                      204        2700
           80 Sales                                 145        2500
           90 Executive                             100        1700
          100 Finance                               108        1700
          110 Accounting                            205        1700

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 1,365 views last month,  2 views today

Exit mobile version