Splitting string into multiple rows in Oracle

This may be an improved way (also with regexp and connect by): with temp as ( select 108 Name, ‘test’ Project, ‘Err1, Err2, Err3’ Error from dual union all select 109, ‘test2’, ‘Err1’ from dual ) select distinct t.name, t.project, trim(regexp_substr(t.error, ‘[^,]+’, 1, levels.column_value)) as error from temp t, table(cast(multiset(select level from dual connect by … Read more

Search All Fields In All Tables For A Specific Value (Oracle)

Quote: I’ve tried using this statement below to find an appropriate column based on what I think it should be named but it returned no results.* SELECT * from dba_objects WHERE object_name like ‘%DTN%’ A column isn’t an object. If you mean that you expect the column name to be like ‘%DTN%’, the query you … Read more

What is the Oracle equivalent of SQL Server’s IsNull() function?

coalesce is supported in both Oracle and SQL Server and serves essentially the same function as nvl and isnull. (There are some important differences, coalesce can take an arbitrary number of arguments, and returns the first non-null one. The return type for isnull matches the type of the first argument, that is not true for … Read more

Oracle PL/SQL – How to create a simple array variable?

You can use VARRAY for a fixed-size array: declare type array_t is varray(3) of varchar2(10); array array_t := array_t(‘Matt’, ‘Joanne’, ‘Robert’); begin for i in 1..array.count loop dbms_output.put_line(array(i)); end loop; end; Or TABLE for an unbounded array: … type array_t is table of varchar2(10); … The word “table” here has nothing to do with database … Read more

PL/SQL, how to escape single quote in a string?

You can use literal quoting: stmt := q'[insert into MY_TBL (Col) values(‘ER0002′)]’; Documentation for literals can be found here. Alternatively, you can use two quotes to denote a single quote: stmt := ‘insert into MY_TBL (Col) values(”ER0002”)’; The literal quoting mechanism with the Q syntax is more flexible and readable, IMO.

Number of rows affected by an UPDATE in PL/SQL

You use the sql%rowcount variable. You need to call it straight after the statement which you need to find the affected row count for. For example: set serveroutput ON; DECLARE i NUMBER; BEGIN UPDATE employees SET status=”fired” WHERE name LIKE ‘%Bloggs’; i := SQL%rowcount; –note that assignment has to precede COMMIT COMMIT; dbms_output.Put_line(i); END;