1. Introduction

The database’s SQL engine now supports a VALUES clause for many types of statements. This new clause allows for materializing rows of data on the fly by specifying them using the new syntax without relying on existing tables.

Oracle supports the VALUES clause for the SELECT, INSERT, and MERGE statements.

The introduction of the new VALUES clause allows developers to write less code for ad-hoc SQL commands, leading to better readability with less effort.

  1. INSERT and VALUES keyword

Before this feature we used to insert the data’s like below

 

Create table Emp

(

Empno number,

Ename varchar2(100)

);

 

Insert into emp values (1,’xxx’);

Insert into emp values (2,’yyy’);

Insert into emp values (3,’zzz’);

 

Commit;

 

In Oracle 23C, added this new feature to overcome from the multiple insert statement to the following statement.

 

Insert into emp values (1,’xxx’), (2,’yyy’), (3,’zzz’);

 

 

  1. SELECT and VALUES keyword

 

We can see how the same feature must be used for the select statement.

 

Select * from (values (1,’Ravi’), (2,’Arun’), (3,’Krish’)) as emp_tab (empno, ename);

 

  1. MERGE and VALUES keyword

In the same way will see how to write the queries with the merge statement.

MERGE INTO emp

USING (VALUES(1,’RAVI’),(2,’ARUN’),(3,’KRISH’)) as emp_tab(empno,ename)

On (emp.empno = emp_tab.empno)

When MATCHED then

Update set emp.ename = emp_tab.ename

When NOT MATCHED then

Insert (emp.empno , emp.ename)

Values ( emp_tab.empno,emp_tab.ename); 

 

  1. WITH and VALUES keyword

WITH T (id,ename) as

(

Values (1,’A’), (2,’B’)

)

Select * from T;

 

  1. CONCLUSION

The new VALUE constructor leverages a much simpler syntax, either for SELECT statements or for INSERT/CREATE as SELECT statements.

 

Recent Posts

Start typing and press Enter to search