Oracle Equivalent to MySQL INSERT IGNORE?

If you’re on 11g you can use the hint IGNORE_ROW_ON_DUPKEY_INDEX: SQL> create table my_table(a number, constraint my_table_pk primary key (a)); Table created. SQL> insert /*+ ignore_row_on_dupkey_index(my_table, my_table_pk) */ 2 into my_table 3 select 1 from dual 4 union all 5 select 1 from dual; 1 row created.

“Safe” TO_NUMBER()

From Oracle Database 12c Release 2 you could use TO_NUMBER with DEFAULT … ON CONVERSION ERROR: SELECT TO_NUMBER(‘*’ DEFAULT 0 ON CONVERSION ERROR) AS “Value” FROM DUAL; Or CAST: SELECT CAST(‘*’ AS NUMBER DEFAULT 0 ON CONVERSION ERROR) AS “Value” FROM DUAL; db<>fiddle demo

TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

You need to add the SID entry for XE in order to register the instance with the listener. After installation of Oracle XE, everything looks good, but when you issue C:\>sqlplus / as sysdba SQL>shutdown immediate SQL>startup TNS-12505: TNS:listener does not currently know of SID given in connect descriptor the instance will not register with … Read more

How do I calculate tables size in Oracle

You might be interested in this query. It tells you how much space is allocated for each table taking into account the indexes and any LOBs on the table. Often you are interested to know “How much spaces the the Purchase Order table take, including any indexes” rather than just the table itself. You can … Read more

How to best split csv strings in oracle 9i

Joyce, Here are three examples: 1) Using dbms_utility.comma_to_table. This is not a general purpose routine, because the elements should be valid identifiers. With some dirty tricks we can make it work more universal: SQL> declare 2 cn_non_occuring_prefix constant varchar2(4) := ‘zzzz’; 3 mystring varchar2(2000):=’a:sd:dfg:31456:dasd: :sdfsdf’; — just an example 4 l_tablen binary_integer; 5 l_tab dbms_utility.uncl_array; … Read more

Oracle PL/SQL – Raise User-Defined Exception With Custom SQLERRM

Yes. You just have to use the RAISE_APPLICATION_ERROR function. If you also want to name your exception, you’ll need to use the EXCEPTION_INIT pragma in order to associate the error number to the named exception. Something like SQL> ed Wrote file afiedt.buf 1 declare 2 ex_custom EXCEPTION; 3 PRAGMA EXCEPTION_INIT( ex_custom, -20001 ); 4 begin … Read more

PL/SQL – Use “List” Variable in Where In Clause

Create the SQL type like this: CREATE TYPE MyListOfValuesType AS TABLE OF VARCHAR2(4000); And then use it in a SQL statement DECLARE MyListOfValues MyListOfValuesType; BEGIN MyListOfValues := MyListOfValuesType(‘MyValue1’, ‘MyValue2’); FOR rec IN ( SELECT * FROM DatabaseTable WHERE DatabaseTable.Field in ( SELECT * FROM TABLE(MyListOfValues) ) ) LOOP … END LOOP; END; Up until Oracle … Read more