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

Saturday, 20 June 2015

How to create a view on a table that does not exist?

we can create a view on a table that really doesn't exist yet we can do this by putting
a word (Force) in create view command-

SYNTAX

CREATE FORCE VIEW
        <VIEW_NAME>
                AS
         <SELECT STATEMENT>;      -- ASSUMING THE TABLE DOES NOT EXIST


e.g.

CREATE FORCE VIEW DEPARTMENT_FORCE_VW AS
SELECT * FROM DEPARTMENT;


Here view gets created but its status is invalid, it becomes valid when we create table DEPARTMENT
(table on which view is defined).

How to create view in oracle

SYNTAX

CREATE OR REPLACE VIEW VIEW_NAME AS
  SELECT COLUMNS
  FROM TABLES
  WHERE CONDITION;

e.g.

CREATE OR REPLACE VIEW EMPLOYEE_VW AS
  SELECT EMPLOYEE_NAME,DEPARTMENT,SALARY
  FROM EMPLOYEE
  WHERE EMPLOYEE_NAME LIKE = '%WAN%';


See also

How to create a view on a table that does not exist?





Add multiple column in existing oracle table


SYNTAX

ALTER TABLE TABLE_NAME
  ADD (COLUMN_1 DATA_TYPE,
       COLUMN_2 DATA_TYPE,
       ...
       COLUMN_N DATA_TYPE);

e.g.

ALTER TABLE EMPLOYEE_DETAIL
  ADD (EMPLOYEE_FIRST_NAME VARCHAR2(100),
       EMPLOYEE_LAST_NAME VARCHAR2(100));

Add column in table in Oracle

To add a column to an existing table in Oracle, you can use the ALTER TABLE statement. Here's the syntax:


ALTER TABLE table_name
ADD (column_name data_type [constraint]);


Here's a breakdown of the syntax elements:

- ALTER TABLE: This clause indicates that you're modifying the structure of an existing table.
- table_name: This is the name of the table to which you want to add the column.
- ADD: This keyword specifies that you're adding a new column to the table.
- (column_name data_type [constraint]): Within parentheses, you specify the details of the new column. column_name is the name of the new column, data_type is the data type of the column, and [constraint] is an optional constraint that you can apply to the column (e.g., NOT NULL, DEFAULT, etc.).

Here's an example of adding a column named email of type VARCHAR2(100) to an existing table named employees:


ALTER TABLE employees
ADD (email VARCHAR2(100));


After executing this statement, the email column will be added to the employees table.

If you want to add a constraint to the new column, such as NOT NULL, you can include it in the ADD clause:


ALTER TABLE employees
ADD (email VARCHAR2(100) NOT NULL);


This statement adds the email column with a NOT NULL constraint, ensuring that every row in the table must have a value for the email column.

Wednesday, 3 June 2015

Power Function in MySql

Below is the Power Function. Power Function always must have 2 parameters.

SELECT POWER(3,2);

Result:-   9

You can also use POW instate of POWER.

In simple words, above function will work like:-  3*2






Also read:- Power Function SQL

Power Function in SQL Server

Below is the example of Power Function. Power Function always must have 2 parameters.

SELECT POWER(2,3);

Result:-  8

In simple words, Above function would work like 2*2*2.

Power Function in Oracle

Below is the Power function in oracle. Power function always must have 2 parameters.

SELECT POWER(2,3) FROM DUAL;

Result:-   8

Above function is like 2*2*2.
Please provide your feedback in the comments section above. Please don't forget to follow.