Transform data from rows to columns. I've got two ID rows, and one text VARCHAR2 type row. But one of the ID rows not always the same. Sometime missing the data.
I tried with PIVOT and GROUP BY until now this gave me only errors.
SELECT prj_id, udn_id, txt_value
FROM TBL
GROUP BY tbl.prj_id;
I would like transform this:
(The empty line is only for the better visibility)
PRJ_ID UDN_ID TXT_ VALUE
8344 82 13/10/2009
8344 64 E S
8344 178 End
8364 82 12/10/2009
8364 64 A M
8364 89 M
8364 178 Internal
8335 82 05/10/2009
8335 64 E S
8335 89 N
8335 178 End
8377 82 13/10/2009
8377 64 Z D
8377 89 N;M
8377 178 Internal
to this:
82 64 89 178
8344 13/10/2009 E S N/A End
8364 12/10/2009 A M M Internal
8335 05/10/2009 E S N End
8377 13/10/2009 Z D N;M Internal
Any idea how can solve this with SQL?
The oldfashioned way (prior to PIVOT) was to aggregate value using DECODE (or CASE, for better readability). Here's an example (lines 16 onwards are what you're looking for):
SQL> with tbl (prj_id, udn_id, txt_value) as
2 (select 8344, 82, '13/10/2009' from dual union all
3 select 8344, 64, 'E S' from dual union all
4 select 8344, 178, 'End' from dual union all
5 --
6 select 8364, 82, '12/10/2009' from dual union all
7 select 8364, 64, 'A M' from dual union all
8 select 8364, 89, 'M' from dual union all
9 select 8364, 178, 'Internal' from dual union all
10 --
11 select 8335, 82, '05/10/2009' from dual union all
12 select 8335, 64, 'E S' from dual union all
13 select 8335, 89, 'N' from dual union all
14 select 8335, 178, 'End' from dual
15 )
16 select prj_id,
17 max(case when udn_id = 82 then txt_value end) "82",
18 max(case when udn_id = 64 then txt_Value end) "64",
19 max(case when udn_id = 89 then txt_value end) "89",
20 max(case when udn_id = 178 then txt_Value end) "178"
21 from tbl
22 group by prj_id;
PRJ_ID 82 64 89 178
---------- ---------- ---------- ---------- ----------
8335 05/10/2009 E S N End
8344 13/10/2009 E S End
8364 12/10/2009 A M M Internal
SQL>
This is achievable using the PIVOT in oracle.
Please use below and let me know in case of any queries.
select * from (
with all_data as(
select '8344' prj_id, 82 id, '40099' txt_val from dual union all
select '8344' prj_id, 64 id, 'E S' txt_val from dual union all
select '8344' prj_id, 178 id, 'End' txt_val from dual union all
select '8364' prj_id, 82 id, '40098' txt_val from dual union all
select '8364' prj_id, 64 id, 'A M' txt_val from dual union all
select '8364' prj_id, 89 id, 'M' txt_val from dual union all
select '8364' prj_id, 178 id, 'Internal' txt_val from dual union all
select '8335' prj_id, 82 id, '40091' txt_val from dual union all
select '8335' prj_id, 64 id, 'E S' txt_val from dual union all
select '8335' prj_id, 89 id, 'N' txt_val from dual union all
select '8335' prj_id, 178 id, 'End' txt_val from dual union all
select '8377' prj_id, 82 id, '40099' txt_val from dual union all
select '8377' prj_id, 64 id, 'Z D' txt_val from dual union all
select '8377' prj_id, 89 id, 'N;M' txt_val from dual union all
select '8377' prj_id, 178 id, 'Internal' txt_val from dual)
select prj_id,id,txt_val from all_data)
pivot
(max(txt_val)
for id in (82 as "82_val", 64 as "64_val", 89 as "89_val", 178 as "178_val"))
order by 1
;
I am new to Oracle syntaxes. So, I have written in SQL server syntax. Hope this helps you:
CREATE TABLE Project(PRJ_ID int, UDN_ID INT, TXT_VALUE varchar(100));
INSERT INTO Project VALUES (8344,82,'E S'),(8344,69,'A M'),(8364,82,'End'),(8364,59,'Internal');
DECLARE #columns NVARCHAR(MAX), #columns1 NVARCHAR(MAX), #sql NVARCHAR(MAX);
--selecting distinct values and concatenating to get a result like [82],[69],[82]...
SELECT #columns1 = STUFF((
SELECT DISTINCT ',' + '['+ CAST(UDN_ID AS VARCHAR) + ']' FROM Project
FOR XML PATH('')
), 1, 1, '')
FROM Project;
--using that dynamic column string in the pivot query string
SET #sql = 'SELECT PRJ_ID,' + #columns1 + ' FROM
(
SELECT * FROM Project
) AS src
PIVOT
(
MAX(TXT_VALUE) FOR src.UDN_ID IN ('+ #columns1
+ ')
) AS p;';
--executing the pivot query
EXEC sp_executesql #sql;
Related
I am trying to find out all the tables where table names consist of numbers less than a fixed number 16284961 at the end preceded by an underscore for example LOG_16282961.
Sample User_segments table:
Segment_name Bytes
---------------------------------------
LOG_16282961 34
BAL1_16282961 78
BIN$xIDte/qXAFbgU4IeBEeQpw==$0 12
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
BIN$xIDte/qWAFbgU4IeBEeQpw==$0 19
EXCH_16283961 90
C$_0LOG_16283961 45
LOG_16284961 21
BAL1_16284961 81
BIN$w1RLAvSeAWjgU4IeBEe2Mw==$0 33
EXCH_16284961 67
C$_0LOG_16284961 39
.......................................
.......................................
Expected Output:
Segment_name Bytes
----------------------
LOG_16282961 34
BAL1_16282961 78
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
EXCH_16283961 90
C$_0LOG_16283961 45
.......................
.......................
Query:
SELECT segment_name, bytes/1024/1024 AS "SIZE in MB" FROM user_segments WHERE segment_type='TABLE' AND to_number(regexp_substr(segment_name, '[0-9]+')) < 16284961;
Using above query, although I am getting my result but additionally it also includes following tables which are not required in my output:
BIN$xIDte/qXAFbgU4IeBEeQpw==$0 12
BIN$xIDte/qWAFbgU4IeBEeQpw==$0 19
BIN$w1RLAvSeAWjgU4IeBEe2Mw==$0 33
Can you please help fix my query to get the desired output? Thanks.
Here's one way - using regexp_substr to isolate one or more consecutive digits at the end of the input string, only if immediately preceded by underscore. (If the string does not have that structure, regexp_substr returns null and the filter condition becomes null < [something], which is never true.)
Create mock-up table for testing:
create table test_data (segment_name, bytes) as
select 'LOG_16282961' , 34 from dual union all
select 'BAL1_16282961' , 78 from dual union all
select 'BIN$xIDte/qXAFbgU4IeBEeQpw==$0', 12 from dual union all
select 'EXCH_16282961' , 28 from dual union all
select 'C$_0LOG_16282961' , 17 from dual union all
select 'LOG_16283961' , 89 from dual union all
select 'BAL1_16283961' , 10 from dual union all
select 'BIN$xIDte/qWAFbgU4IeBEeQpw==$0', 19 from dual union all
select 'EXCH_16283961' , 90 from dual union all
select 'C$_0LOG_16283961' , 45 from dual union all
select 'LOG_16284961' , 21 from dual union all
select 'BAL1_16284961' , 81 from dual union all
select 'BIN$w1RLAvSeAWjgU4IeBEe2Mw==$0', 33 from dual union all
select 'EXCH_16284961' , 67 from dual union all
select 'C$_0LOG_16284961' , 39 from dual
;
Query and output:
select *
from test_data
where to_number(regexp_substr(segment_name, '_(\d+)$', 1, 1, null, 1))
< 16284961
;
SEGMENT_NAME BYTES
------------------------------ ----------
LOG_16282961 34
BAL1_16282961 78
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
EXCH_16283961 90
C$_0LOG_16283961 45
If query you wrote works, just omit tables you don't want. Those you mentioned have been dropped and are now in recycle bin. So, either purge recyclebin before running the query, or use additional condition, e.g.
SELECT segment_name, bytes / 1024 / 1024 AS "SIZE in MB"
FROM user_segments
WHERE segment_type = 'TABLE'
AND substr(segment_name, 1, 4) <> 'BIN$' --> this
AND TO_NUMBER (REGEXP_SUBSTR (segment_name, '[0-9]+')) < 16284961;
Because of the limitations we have in Amazon Redhshift SQL (which is based on PostgreSQL 8.0.2). I am forced to execute the following query for some other complex query purposes:
create temporary table NS AS (
select 1 as n union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 12 union all
select 13 union all
select 14 union all
select 15 union all
select 16 union all
select 17 union all
select 18 union all
select 19 union all
select 20 union all
select 21 union all
select 22 union all
select 23 union all
select 24 union all
select 25 union all
select 26 union all
select 27 union all
select 28 union all
select 29 union all
select 30 union all
select 31 union all
select 32 union all
select 33 union all
select 34 union all
select 35 union all
select 36 union all
select 37 union all
select 38 union all
select 39 union all
select 40 union all
select 41 union all
select 42 union all
select 43 union all
select 44 union all
select 45 union all
select 46 union all
select 47 union all
select 48 union all
select 49 union all
select 50 union all
select 51 union all
select 52 union all
select 53 union all
select 54 union all
select 55 union all
select 56 union all
select 57 union all
select 58 union all
select 59 union all
select 60 union all
select 61 union all
select 62 union all
select 63 union all
select 64 union all
select 65 union all
select 66 union all
select 67 union all
select 68 union all
select 69 union all
select 70 union all
select 71 union all
select 72 union all
select 73 union all
select 74 union all
select 75 union all
select 76 union all
select 77 union all
select 78 union all
select 79 union all
select 80 union all
select 81 union all
select 82 union all
select 83 union all
select 84 union all
select 85 union all
select 86 union all
select 87 union all
select 88 union all
select 89 union all
select 90 union all
select 91 union all
select 92 union all
select 93 union all
select 94 union all
select 95 union all
select 96 union all
select 97 union all
select 98 union all
select 99 union all
select 100 union all
select 101 union all
select 102 union all
select 103 union all
select 104 union all
select 105 union all
select 106 union all
select 107 union all
select 108 union all
select 109 union all
select 110 union all
select 111 union all
select 112 union all
select 113 union all
select 114 union all
select 115 union all
select 116 union all
select 117 union all
select 118 union all
select 119 union all
select 120 union all
select 121 union all
select 122 union all
select 123 union all
select 124 union all
select 125 union all
select 126 union all
select 127 union all
select 128 union all
select 129 union all
select 130 union all
select 131 union all
select 132 union all
select 133 union all
select 134 union all
select 135 union all
select 136 union all
select 137 union all
select 138 union all
select 139 union all
select 140 union all
select 141 union all
select 142 union all
select 143 union all
select 144 union all
select 145 union all
select 146 union all
select 147 union all
select 148 union all
select 149 union all
select 150 union all
select 151 union all
select 152 union all
select 153 union all
select 154 union all
select 155 union all
select 156 union all
select 157 union all
select 158 union all
select 159 union all
select 160 union all
select 161 union all
select 162 union all
select 163 union all
select 164 union all
select 165 union all
select 166 union all
select 167 union all
select 168 union all
select 169 union all
select 170 union all
select 171 union all
select 172 union all
select 173 union all
select 174 union all
select 175 union all
select 176 union all
select 177 union all
select 178 union all
select 179 union all
select 180 union all
select 181 union all
select 182 union all
select 183 union all
select 184 union all
select 185 union all
select 186 union all
select 187 union all
select 188 union all
select 189 union all
select 190 union all
select 191 union all
select 192 union all
select 193 union all
select 194 union all
select 195 union all
select 196 union all
select 197 union all
select 198 union all
select 199 union all
select 200
);
But this executed only once, later it even failed to even execute without throwing any error in all three mediums I'm trying. i.e. SQL Workbech, Amazon Hubble and Amazon ETL Manager. So, this simple query executing only sporadically with most of the time not executing. Can you please let me know if there is a limitaiton in the number of select statements that we can union? If yes, why it is even not throwing an error?
Thanks.
How about this way using generate_series() without using 200 unions?
CREATE TEMP TABLE NS AS SELECT * FROM generate_series(1, 200)
I have a table below:
RuleID | Code | Value
654 Branch 54
654 MessageType MT103
654 Currency USD
654 SourceSys xyz
<!--Comment-Another set of RuleID data-->
656 Branch 54
656 MessageType MT102
656 Currency INR
--------So ON -------------
<!--Comment-Another set of RuleID data-->
658 Branch 54
658 MessageType MT103
658 Currency INR
Every RuleID will max have 5 to 6 code and thier value.It may have 1 also 2 also. Here for example I have given 2 set values.one for Rule id 654 and other 656.
Now Need a query where I can get all RuleID where Branch = 54 and MessageType=MT102
I tried below:- (But this will obviuos not work)
select RuleID
from MyTable
where (CODE='Branch' and Value='54')
and (CODE='MessageType' and Value='MT102')
Read the Union also but that also will not work here.
Think join should do here, but not getting result.
Expected Result: I want to Query all RuleID where Branch is 54 and MessageType is MT103. So Expected Result is Ruleid-654,658
Use OR.
SELECT RuleID
FROM MyTable
WHERE (CODE = 'Branch' AND Value = '54')
OR (CODE = 'MessageType' AND Value = 'MT102')
Something like this, perhaps?
SQL> WITH test (ruleid, code, VALUE)
2 AS (SELECT 654, 'Branch', '54' FROM DUAL
3 UNION
4 SELECT 654, 'MessageType', 'MT103' FROM DUAL
5 UNION
6 SELECT 654, 'Currency', 'USD' FROM DUAL
7 UNION
8 SELECT 654, 'SourceSys', 'xyz' FROM DUAL
9 UNION
10 --
11 SELECT 656, 'Branch', '54' FROM DUAL
12 UNION
13 SELECT 656, 'MessageType', 'MT102' FROM DUAL
14 UNION
15 SELECT 656, 'Currency', 'INR' FROM DUAL)
16 SELECT ruleid
17 FROM test
18 WHERE ( ( code = 'Branch'
19 AND VALUE = '54')
20 OR ( code = 'MessageType'
21 AND VALUE = 'MT102'))
22 GROUP BY ruleid
23 HAVING COUNT (*) = 2;
RULEID
----------
656
SQL>
You can use intersection
WITH MyTable as
(
SELECT 654 RuleId, 'Branch' code, '54' value FROM DUAL
UNION
SELECT 654, 'MessageType', 'MT103' FROM DUAL
UNION
SELECT 654, 'Currency', 'USD' FROM DUAL
UNION
SELECT 654, 'SourceSys', 'xyz' FROM DUAL
UNION
SELECT 656, 'Branch', '54' FROM DUAL
UNION
SELECT 656, 'MessageType', 'MT102' FROM DUAL
UNION
SELECT 656, 'Currency', 'INR' FROM DUAL
)
select RuleID
from MyTable
where CODE='Branch'
and Value='54'
intersect
select RuleID
from MyTable
where CODE='MessageType'
and Value='MT102'
Here is a minimal working example of what I'm trying to do and what I'm getting:
I have a query as follows:
/*
with tran_party as -- ALL DUMMY DATA ARE IN THESE CTE FOR YOUR REFERENCE
(select 1 tran_party_id, 11 transaction_id, 101 team_id_redirect
from dual
union all
select 2, 11, 101 from dual
union all
select 3, 11, 102 from dual
union all
select 4, 12, 103 from dual
union all
select 5, 12, 103 from dual
union all
select 6, 12, 104 from dual
union all
select 7, 13, 104 from dual
union all
select 8, 13, 105 from dual),
tran as
(select 11 transaction_id, 1001 account_id, 1034.93 amount from dual
union all
select 12, 1001, 2321.89 from dual
union all
select 13, 1002, 3201.47 from dual),
account as
(select 1001 account_id, 111 team_id from dual
union all
select 1002, 112 from dual),
team as
(select 101 team_id, 'UUU' as team_code from dual
union all
select 102, 'VV' from dual
union all
select 103, 'WWW' from dual
union all
select 104, 'XXXXX' from dual
union all
select 105, 'Z' from dual)
-- */
-- The Actual Query
select a.account_id,
t.transaction_id,
(select listagg (tm_redir.team_code, ', ')
within group (order by tm_redir.team_code)
from tran_party tp_redir
inner join team tm_redir
on tp_redir.team_id_redirect = tm_redir.team_id
inner join tran t_redir
on tp_redir.transaction_id = t_redir.transaction_id
where t_redir.account_id = a.account_id
and t_redir.transaction_id != t.transaction_id)
as teams_redirected
from tran t inner join account a on t.account_id = a.account_id;
NOTE: tran_party.team_id_redirect is a foreign key that references team.team_id.
Current output:
ACCOUNT_ID TRANSACTION_ID TEAMS_REDIRECTED
---------- -------------- ----------------
1001 11 WWW, WWW, XXXXX
1001 12 UUU, UUU, VV
1002 13
Expected output:
I want the repeated items in TEAMS_REDIRECTED column to be selected only once, like this:
ACCOUNT_ID TRANSACTION_ID TEAMS_REDIRECTED
---------- -------------- ----------------
1001 11 WWW, XXXXX
1001 12 UUU, VV
1002 13
What I tried:
Instead of selecting from tran_party directly, I wrote an inline view that selects distinct values from tran_party like this:
select a.account_id,
t.transaction_id,
(select listagg (tm_redir.team_code, ', ')
within group (order by tm_redir.team_code)
from (select distinct transaction_id, team_id_redirect -- Note this inline view
from tran_party) tp_redir
inner join team tm_redir
on tp_redir.team_id_redirect = tm_redir.team_id
inner join tran t_redir
on tp_redir.transaction_id = t_redir.transaction_id
where t_redir.account_id = a.account_id
and t_redir.transaction_id != t.transaction_id)
as teams_redirected
from tran t inner join account a on t.account_id = a.account_id;
While this does give me the expected output, when I use this solution in my actual code, it takes about 13 seconds to retrieve just one row. Thus I cannot use what I already tried.
Any help will be appreciated.
The following method gets rid of the in-line view to fetch duplicates, it uses REGEXP_REPLACE and RTRIM on the LISTAGG function to get the distinct result set in the aggregated list. Thus, it won't do more than one scan.
Adding this piece to your code,
RTRIM(REGEXP_REPLACE(listagg (tm_redir.team_code, ',')
WITHIN GROUP (ORDER BY tm_redir.team_code),
'([^,]+)(,\1)+', '\1'),
',')
Modified query-
SQL> with tran_party as -- ALL DUMMY DATA ARE IN THESE CTE FOR YOUR REFERENCE
2 (select 1 tran_party_id, 11 transaction_id, 101 team_id_redirect
3 from dual
4 union all
5 select 2, 11, 101 from dual
6 union all
7 select 3, 11, 102 from dual
8 union all
9 select 4, 12, 103 from dual
10 union all
11 select 5, 12, 103 from dual
12 union all
13 select 6, 12, 104 from dual
14 union all
15 select 7, 13, 104 from dual
16 union all
17 select 8, 13, 105 from dual),
18 tran as
19 (select 11 transaction_id, 1001 account_id, 1034.93 amount from dual
20 union all
21 select 12, 1001, 2321.89 from dual
22 union all
23 select 13, 1002, 3201.47 from dual),
24 account as
25 (select 1001 account_id, 111 team_id from dual
26 union all
27 select 1002, 112 from dual),
28 team as
29 (select 101 team_id, 'UUU' as team_code from dual
30 union all
31 select 102, 'VV' from dual
32 union all
33 select 103, 'WWW' from dual
34 union all
35 select 104, 'XXXXX' from dual
36 union all
37 select 105, 'Z' from dual)
38 -- The Actual Query
39 select a.account_id,
40 t.transaction_id,
41 (SELECT RTRIM(
42 REGEXP_REPLACE(listagg (tm_redir.team_code, ',')
43 WITHIN GROUP (ORDER BY tm_redir.team_code),
44 '([^,]+)(,\1)+', '\1'),
45 ',')
46 from tran_party tp_redir
47 inner join team tm_redir
48 on tp_redir.team_id_redirect = tm_redir.team_id
49 inner join tran t_redir
50 on tp_redir.transaction_id = t_redir.transaction_id
51 where t_redir.account_id = a.account_id
52 and t_redir.transaction_id != t.transaction_id)
53 AS teams_redirected
54 from tran t inner join account a on t.account_id = a.account_id
55 /
ACCOUNT_ID TRANSACTION_ID TEAMS_REDIRECTED
---------- -------------- --------------------
1001 11 WWW,XXXXX
1001 12 UUU,VV
1002 13
SQL>
In my C++ program I tried something like this:
INSERT INTO TEMP_TABELA (OSE_ID) values (7,12,16,17,19,21,24,26,30,33,35,38,42,46,53,58,59,72,73,74,77,78,82,86,87,88,89,91,92,93,100,101,102,104,106,109,113,115,127,133,139,140,142,143,144,148,149,150,151,153,155,160,164,166,167,170,172,178,188,189,191,192,198,199,200,201,202,203,205,207,208,219,220,223,225,231,233,236,240,241,242,244,245,253);
But all I got was:
Description: There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
Source: Microsoft OLE DB Provider for SQL Server
The same sentence must work also on Oracle, because my program works for both.
Can anyone help me?
Oracle's and SQL Server's bulk insertion syntax is different from one another, so the safest means is to use individual INSERT statements:
INSERT INTO TEMP_TABELA (OSE_ID) values (7);
INSERT INTO TEMP_TABELA (OSE_ID) values (12);
INSERT INTO TEMP_TABELA (OSE_ID) values (16);
INSERT INTO TEMP_TABELA (OSE_ID) values (17);
...
INSERT INTO TEMP_TABELA (OSE_ID) values (253);
This works in Oracle, it split's on the string (assuming 10g+)
CREATE TABLE TESTX(NUM NUMBER);
INSERT INTO TESTX(NUM)
select regexp_substr (x, '[^,]+', 1, level) as token
from (SELECT '7,12,16,17,19,21,24,26,30,33,35,38,42,46,53,58,59,72,73,74,77,78,82,86,87,88,89,91,92,93,100,101,102,104,106,109,113,115,127,133,139,140,142,143,144,148,149,150,151,153,155,160,164,166,167,170,172,178,188,189,191,192,198,199,200,201,202,203,205,207,208,219,220,223,225,231,233,236,240,241,242,244,245,253' X FROM DUAL) t
connect by regexp_instr (x, '[^,]+', 1, level) > 0
84 rows inserted
Do this for Oracle:
INSERT INTO TEMP_TABELA (OSE_ID)
select 7 from dual union all
select 12 from dual union all
select 16 from dual union all
select 17 from dual union all
select 19 from dual union all
select 21 from dual union all
select 24 from dual union all
select 26 from dual union all
select 30 from dual union all
select 33 from dual union all
select 35 from dual union all
select 38 from dual union all
select 42 from dual union all
select 46 from dual union all
select 53 from dual union all
select 58 from dual union all
select 59 from dual union all
select 72 from dual union all
select 73 from dual union all
select 74 from dual union all
select 77 from dual union all
select 78 from dual union all
select 82 from dual union all
select 86 from dual union all
select 87 from dual union all
select 88 from dual union all
select 89 from dual union all
select 91 from dual union all
select 92 from dual union all
select 93 from dual union all
select 100 from dual union all
select 101 from dual union all
select 102 from dual union all
select 104 from dual union all
select 106 from dual union all
select 109 from dual union all
select 113 from dual union all
select 115 from dual union all
select 127 from dual union all
select 133 from dual union all
select 139 from dual union all
select 140 from dual union all
select 142 from dual union all
select 143 from dual union all
select 144 from dual union all
select 148 from dual union all
select 149 from dual union all
select 150 from dual union all
select 151 from dual union all
select 153 from dual union all
select 155 from dual union all
select 160 from dual union all
select 164 from dual union all
select 166 from dual union all
select 167 from dual union all
select 170 from dual union all
select 172 from dual union all
select 178 from dual union all
select 188 from dual union all
select 189 from dual union all
select 191 from dual union all
select 192 from dual union all
select 198 from dual union all
select 199 from dual union all
select 200 from dual union all
select 201 from dual union all
select 202 from dual union all
select 203 from dual union all
select 205 from dual union all
select 207 from dual union all
select 208 from dual union all
select 219 from dual union all
select 220 from dual union all
select 223 from dual union all
select 225 from dual union all
select 231 from dual union all
select 233 from dual union all
select 236 from dual union all
select 240 from dual union all
select 241 from dual union all
select 242 from dual union all
select 244 from dual union all
select 245 from dual union all
select 253 from dual
And this for SQL Server:
INSERT INTO TEMP_TABELA (OSE_ID)
select 7 union all
select 12 union all
select 16 union all
select 17 union all
select 19 union all
select 21 union all
select 24 union all
select 26 union all
select 30 union all
select 33 union all
select 35 union all
select 38 union all
select 42 union all
select 46 union all
select 53 union all
select 58 union all
select 59 union all
select 72 union all
select 73 union all
select 74 union all
select 77 union all
select 78 union all
select 82 union all
select 86 union all
select 87 union all
select 88 union all
select 89 union all
select 91 union all
select 92 union all
select 93 union all
select 100 union all
select 101 union all
select 102 union all
select 104 union all
select 106 union all
select 109 union all
select 113 union all
select 115 union all
select 127 union all
select 133 union all
select 139 union all
select 140 union all
select 142 union all
select 143 union all
select 144 union all
select 148 union all
select 149 union all
select 150 union all
select 151 union all
select 153 union all
select 155 union all
select 160 union all
select 164 union all
select 166 union all
select 167 union all
select 170 union all
select 172 union all
select 178 union all
select 188 union all
select 189 union all
select 191 union all
select 192 union all
select 198 union all
select 199 union all
select 200 union all
select 201 union all
select 202 union all
select 203 union all
select 205 union all
select 207 union all
select 208 union all
select 219 union all
select 220 union all
select 223 union all
select 225 union all
select 231 union all
select 233 union all
select 236 union all
select 240 union all
select 241 union all
select 242 union all
select 244 union all
select 245 union all
select 253
The parentheses in your statement in the example indicate to SQL Server that you want all that to be on one row. You need to enclose each row in parentheses and separate those by commas, i.e:
INSERT INTO TEMP_TABELA (OSE_ID)
values (7),
(12),
(16),
(17),
(19),
(21),
(24),...
I'm not sure if this will work in Oracle or not, but if not you may need to create a condition in your calling application to determine which DB it's working with and modify the query appropriately.
Similar to #OMGPonies can also do something like:
INSERT INTO TEMP_TABLEA(OSE_ID)
SELECT 7 union all
SELECT 12 ...
Not sure which is faster or even if you care about speed given the number of items you're inserting.
Not tested on oracle but I'm about 90% sure it will work.