Posts

Showing posts from April, 2015

Managing overflows in LISTAGG

Image
This is an interesting problem that has come up a few times in discussions (and I think it has been mentioned on the SQL forums as well).  When using LISTAGG  on very large data sets you can sometimes create a list that is too long and consequently get an ORA-01489: result of string concatenation is too long   error . Obviously, it is possible to determine in advance if the error is going to occur using some bespoke PL/SQL code and then take appropriate action within your application to manage the rows that contain stings that exceed the VARCHAR2 limit. Many customers have implemented workarounds to overcome the  ORA-01489  error, however, this has mostly involved the use of complex code which has impacted performance. Wouldn’t it be great if there was a simple yet elegant way to resolve this issue? Actually there is and we can use a few of the most recent analytical SQL functions. If you are using Database 12c you can make use of the  MATCH_RECOGNIZE  function to effecti