Oracle Queries
Oracle Queries
You can execute many queries in oracle database such as insert, update, delete, alter table, drop,
create and select.
More Details...
Syntax
1. SELECT expressions
2. FROM tables
3. WHERE conditions;
Parameters
1) expressions: It specifies the columns or calculations that you want to retrieve.
2) tables:This parameter specifies the tables that you want to retrieve records from. There must be
at least one table within the FROM clause.
1. SELECT *
2. FROM customers;
output
output
Parameters:
1) table: The table to insert the records into.
The values to assign to the columns in the table. So column1 would be assigned the value of
expression1, column2 would be assigned the value of expression2, and so on.
4) source_table:
5) conditions:
Consider here the already created suppliers table. Add a new row where the value of supplier_id is
23 and supplier_name is Flipkart.
In this method, we insert values to the "suppliers" table from "customers" table. Both tables are
already created with their respective columns.
0.00 seconds
You can even check the number of rows that you want to insert by following statement:
1. SELECT count(*)
2. FROM customers
3. WHERE age > 20;
Output:
Count(*)
4
Syntax
1. INSERT ALL
2. INTO table_name (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
3. INTO table_name(column1, column2, column_n) VALUES (expr1, expr2, expr_n)
4. INTO table_name (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
5. SELECT * FROM dual;
Parameters
1) table_name: it specifies the table in which you want to insert your records.
2) column1, column2, column_n: this specifies the columns in the table to insert values.
3) expr1, expr2, expr_n: this specifies the values to assign to the columns in the table.
1. INSERT ALL
2. INTO suppliers (supplier_id, supplier_name) VALUES (20, 'Google')
3. INTO suppliers (supplier_id, supplier_name) VALUES (21, 'Microsoft')
4. INTO suppliers (supplier_id, supplier_name) VALUES (22, 'Apple')
5. SELECT * FROM dual;
Output
3 row(s) inserted.
0.02 seconds
In the following example, we are going to insert records into the both "suppliers" and "customers" tables.
1. INSERT ALL
2. INTO suppliers (supplier_id, supplier_name) VALUES (30, 'Google')
3. INTO suppliers (supplier_id, supplier_name) VALUES (31, 'Microsoft')
4. INTO customers (age, name, address) VALUES (29, 'Luca Warsi', 'New York')
5. SELECT * FROM dual;
Output
3 row(s) inserted.
0.03 seconds
Here, total 3 rows are inserted, 2 rows are inserted into the suppliers table and one row into the
customers table.
1. UPDATE table
2. SET column1 = expression1,
3. column2 = expression2,
4. ...
5. column_n = expression_n
6. WHERE conditions;
1. UPDATE table1
2. SET column1 = (SELECT expression1
3. FROM table2
4. WHERE conditions)
5. WHERE conditions;
Parameters:
1) column1, column2, ... column_n:
3) conditions:It specifies the conditions that must be fulfilled for execution of UPDATE stateme.
Oracle Update Example: (Update single column)
1. UPDATE suppliers
2. SET supplier_name = 'Kingfisher'
3. WHERE supplier_id = 2;
1. UPDATE suppliers
2. SET supplier_address = 'Agra',
3. supplier_name = 'Bata shoes'
4. WHERE supplier_id = 1;
Output:
1 row(s) updated.
0.06 seconds
Output:
2 row(s) updated.
0.02 seconds
Here, the customers table is updated by fetching the data from "suppliers" table.
Syntax
Parameters
1) table_name: It specifies the table which you want to delete.
2) conditions: It specifies the conditions that must met for the records to be deleted.
This statement will delete all records from the customer table where name is "Sohan".
This statement will delete all records from the customers table where the last_name is "Maurya"
and the customer_id is greater than 2.
Once a table is truncated, it can?t be rolled back. The TRUNCATE TABLE statement does not affect
any of the table?s indexes, triggers or dependencies.
Syntax
Output
Table truncated.
1.11 seconds
Now check the customers table, you will find that there is no data available in that table. It is
equally similar to DELETE TABLE statement in Oracle.