PREREQUISITE
prerequisite : You should read our lesson
DBA and SQL basics before complete this lesson
Object of lesson 1 - DBA in 25 days
Objective : Objective of this series “Lets learn SQL statement SELECT” is to learn basics of SQL statement “SELECT”.As we learnt that SELECT is the only keyword in SQL to retrieve data from Oracle Database.Lets see more details about SELECT with examples.
Suppose you have a database named “timewasteblogCOM” loaded with user details like user id, user_ name, email,phone number,join_date,donation in table “USERS”.
Now you want to see list of all records loaded into the table “USERS” table.
1.You should have access to database “timewasteblogCOM”.
2.Start SQLPLUS or Isqlplus and connect to database.
3.Next need to execute SQL statment which retrive desired data.
4.Now we already learnt SELECT is keyword we need to use to retrieve data.
First Part of SQL statement : SELECT
5. What to retrieve ? all of user names. * means all
Next SQL statement part *
6. Now we need to tell in which table data loaded . So in our case table name will be “USERS”
Next SQL statement part USERS
So Here is the complete SQL statment : SELECT * from USERS
Bingo ! your first SQL statement completed. 
Now lets see more details of SELECT
Basic SELECT statment syntax
SELECT *| { [DISTINCT] column |expression [alias] ,…..} FROM table;
| SELECT
*
DISTINCT
Column|expression
aliases |
Selects one or more columns
Selects ALL columns
Suppresses duplicates
Selects named column or expression
Gives different names to selected columns |
One more example:
1.Suppose you want to select 2 columns named as user_names,email from our database “timewasteblogCOM” .SQL statement will look like as below.
SELECT user_name,email FROM USERS;
Note: Every SQL statement should end with ‘;’
Lets learn about Arithmetic Operators usage
Arithmetic Operation in SQL statement:* / + -
Suppose if I want to know how it looks if each user donation doubles [Interesting ! isn't], then SQL quesry will look like below.
SELECT user_name,donation, donation*2 FROM USERS
Above SQL statment will show records related to user_name, donation along with it shows new column with heading “donation*2″ with digits which are equal to donation multiply by 2.
New column “donations*2″ is virtual one, its not real. Just display purpose only.
Now lets discuss about Operator Precedence.SQL Multiplication and division takes priority than addition and subtraction.You can force priority by using Parentheses.
Example: Conider Mr.John given $10 donation then following SQL query will show “2*donation+100″ column with value $22.
SELECT user_name,donation, 2*donation+100 FROM USER
If we enforce Arithmetic Precedence with Parentheses result will be $220 ( I like it )
SELECT user_name,donation, 2* (donation+100)
NULL value special value
NULL value
A record in a table is unavailable,unassigned,unknown, or inapplicable then that is called NULL value. ZERO is NOT equal to NULL value.Just blank space also not NULL value.In Arithmetic operation with NULL value results NULL only.
Meaningful Custom Column Name
Column Alias
In above example we saw user_name column showing user name. Now I want to show more meaningful name like NAME in query result you can use Alias feature.By default SQlPLUS uses name of the selected column as column name in query result. Some times those columns names are not descriptive.So using Alias feature you can show meaningful column names instead of original column names.
SELECT user_name AS Name from USERS;
Above SQL query result shows list of user names under column “Name” instead of original column name “User_Name”.
If Alias contains spaces or special characters oris case sensitive you need to put Alias in double quotations.
DISTINCT - duplicate eliminator
DISTINCT
SQL keyword DISTINCT helps to eliminates duplicate enties in SQL query result.
SELECT DISTINCT last_name from USERS
Above query results rows which are duplicate free of user last_names.
Next we going to see some LAB simulations related to current lesson.
Please leave your comments/questions here. Response guaranteed
.
Other Posts related to current topic
- Passed OCA PAPER -1 Oracle 9i sql 1Z0-007
- How to apply for OCA exam 1Z0-007
- 01. Lets learn SQL statement SELECT 1Z0-007 (This post)
- Oracle DBA and SQL basics video tutorials - 00
- SQL vs SQLPLUS - Learn SQL online
- Project OCA DBA DAY-1 schedule details.FREE OCA tutorial
- Let's start PROJECT OCA
- Oracle OCA DBA certification details and guidance
- How to convert as oracle DBA from system administrator
- How Oracle Works in single shot
- Best books to learn Oracle DBA
- Got the software now time to gather Oracle 10g books
- Oracle 10g Express vs Standard vs Enterprise
- Become a Oracle DBA within 25 days

This
work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License