Selecting constants without referring to a table is perfectly legal in an SQL statement:
SELECT 1, 2, 3
The result set that the latter retu
Here is how I populate static data in Oracle 10+ using a neat XML trick.
create table prop
(ID NUMBER,
NAME varchar2(10),
VAL varchar2(10),
CREATED timestamp,
CONSTRAINT PK_PROP PRIMARY KEY(ID)
);
merge into Prop p
using (
select
extractValue(value(r), '/R/ID') ID,
extractValue(value(r), '/R/NAME') NAME,
extractValue(value(r), '/R/VAL') VAL
from
(select xmltype('
<ROWSET>
<R><ID>1</ID><NAME>key1</NAME><VAL>value1</VAL></R>
<R><ID>2</ID><NAME>key2</NAME><VAL>value2</VAL></R>
<R><ID>3</ID><NAME>key3</NAME><VAL>value3</VAL></R>
</ROWSET>
') xml from dual) input,
table(xmlsequence(input.xml.extract('/ROWSET/R'))) r
) p_new
on (p.ID = p_new.ID)
when not matched then
insert
(ID, NAME, VAL, CREATED)
values
( p_new.ID, p_new.NAME, p_new.VAL, SYSTIMESTAMP );
The merge only inserts the rows that are missing in the original table, which is convenient if you want to rerun your insert script.
SELECT *
FROM DUAL
CONNECT BY ROWNUM <= 9;
An option for DB2:
SELECT 101 AS C1, 102 AS C2 FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 201 AS C1, 202 AS C2 FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 301 AS C1, 302 AS C2 FROM SYSIBM.SYSDUMMY1
Oracle. Thanks to this post PL/SQL - Use "List" Variable in Where In Clause
I put together my example statement to easily manually input values (being reused in testing an application by testers):
WITH prods AS (
SELECT column_value AS prods_code
FROM TABLE(
sys.odcivarchar2list(
'prod1',
'prod2'
)
)
)
SELECT * FROM prods
select (level - 1) * row_dif + 1 as a, (level - 1) * row_dif + 2 as b, (level - 1) * row_dif + 3 as c
from dual
connect by level <= number_of_rows;
something like that
select (level - 1) * 3 + 1 as a, (level - 1) * 3 + 2 as b, (level - 1) * 3 + 3 as c
from dual
connect by level <= 3;
Try the connect by clause in oracle, something like this
select level,level+1,level+2 from dual connect by level <=3;
For more information on connect by clause follow this link : removed URL because oraclebin site is now malicious.