Sorry to sound negative, absolutely not the point here ... most of the answer are to avoid using LONG as data type in your table structure of most of the obvious reasons, stated by the technical ingenuous'. (NOTE: Honestly, I do not understand all the technicalities, but I did understand it is quite to consume it SQL operations.)
Coming back to, why I needed it or most of us requesting for the answer - (two fold, is my opinion)
- When the data structure is designed by (gently put- else dictated) and is built-into package you are dealing with, ideally then you left with no choice of changing the DS, but to come to need of quering it.
- (Plus) a bonus 'need' typically by the technicians cut their hands-off of privilege of writing or running PLSQL blocks. Also, let me confess, you might still not be so sure to get access to run this (as this would mean needing to use an 11g built-in function), given some of insecurities of clientele / the systems you are working with.
Now, I know there could be advocates suggesting, to approach people front on accessing privileges of accommodating the task, the proper way. Pardon my excusing of the path, only to alternatively identify a solution to help.
So, with no further ado
Here it is -
- Now point one premium piece of the puzzle, and I admit this happen to be fairly quickly.
SELECT
DBMS_XMLGEN.getxml (
'SELECT t.' || :LONG_COLUMN || ' LONG_COL
FROM ' || :TABLE_NAME || ' t
WHERE ' || :SEARCH_COLUMN || ' =
' || :SEARCH_CRITERIA
)
xml_text
FROM DUAL
- Covering second base, I had tough luck for a long time, specially when the data contains some of the special characters of XML - like & (ampersand), > (greater than), < (less than) and ' (apostrophe or single quote)
- So, if you know, or running this temporarily you may avoid the next crude way of dealing with this, that is, the way to work with XML special characters.
Remove the wrapped XML tags to get the clean content. (as far as I am concerned, this was the solution, complete for my end of the problem)
SELECT
REPLACE (
REPLACE (
xml_text,
SUBSTR (xml_text,1,
INSTR (xml_text, '<LONG_COL>') + LENGTH ('<LONG_COL>') - 1),
''),
SUBSTR (xml_text, INSTR (xml_text, '</LONG_COL>'),
LENGTH (xml_text) ),
'')
FROM (SELECT DBMS_XMLGEN.getxml (
'SELECT t.' || :LONG_COLUMN || ' LONG_COL
FROM ' || :TABLE_NAME || ' t
WHERE ' || :SEARCH_COLUMN || ' = '
|| :SEARCH_CRITERIA)
xml_text
FROM DUAL)