Best way to do multi-row insert in Oracle?

In Oracle, to insert multiple rows into table t with columns col1, col2 and col3 you can use the following syntax: INSERT ALL INTO t (col1, col2, col3) VALUES (‘val1_1’, ‘val1_2’, ‘val1_3’) INTO t (col1, col2, col3) VALUES (‘val2_1’, ‘val2_2’, ‘val2_3’) INTO t (col1, col2, col3) VALUES (‘val3_1’, ‘val3_2’, ‘val3_3’) . . . SELECT 1 … Read more

Not equal != operator on NULL

<> is Standard SQL-92; != is its equivalent. Both evaluate for values, which NULL is not — NULL is a placeholder to say there is the absence of a value. Which is why you can only use IS NULL/IS NOT NULL as predicates for such situations. This behavior is not specific to SQL Server. All … Read more

Select n random rows from SQL Server table

select top 10 percent * from [yourtable] order by newid() In response to the “pure trash” comment concerning large tables: you could do it like this to improve performance. select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) The cost of this will be the key scan … Read more

SET NOCOUNT ON usage

Ok now I’ve done my research, here is the deal: In TDS protocol, SET NOCOUNT ON only saves 9-bytes per query while the text “SET NOCOUNT ON” itself is a whopping 14 bytes. I used to think that 123 row(s) affected was returned from server in plain text in a separate network packet but that’s … Read more

Update statement with inner join on Oracle

That syntax isn’t valid in Oracle. You can do this: UPDATE table1 SET table1.value = (SELECT table2.CODE FROM table2 WHERE table1.value = table2.DESC) WHERE table1.UPDATETYPE=’blah’ AND EXISTS (SELECT table2.CODE FROM table2 WHERE table1.value = table2.DESC); Or you might be able to do this: UPDATE (SELECT table1.value as OLD, table2.CODE as NEW FROM table1 INNER JOIN … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)