1

As a bloody newbie when it comes to complex sql commands, I want to execute two XPath database queries where the second command uses the result of the first one:

declare
version VARCHAR2(256);
document VARCHAR2(256);
begin

select ID_VERSION into version from VERSIONTABLE where extract(VERSION_XML, '//p:contract[@id="contract-001"]', 'xmlns:p="http://www.foo.com/v1"').getClobVal() IS NOT NULL;
select ID_DOCUMENT into document from DOCUMENTTABLE where extract(DOCUMENT_XML, '//p:content[@ref='$version']', 'xmlns:p="http://www.foo.com/v1"').getClobVal() IS NOT NULL;

end;
/

The first command will always return exactly one ID_VERSION. As a result, I want to print document.

The question: how do I properly include version in the second command? Executing above commands, it outputs following error at the code position of '$version':

PLS-00181: unsupported preprocessor directive '$VERSION' [SQL State=65000, DB Errorcode=6550] 

Thank you!

1 Answer 1

1

The string concatenation operator in PL/SQL is || - so you'd want to do something like:

select ID_DOCUMENT
  into document
  from DOCUMENTTABLE
  where extract(DOCUMENT_XML,
                '//p:content[@ref=' || version || ']', 
                'xmlns:p="http://www.foo.com/v1"').getClobVal() IS NOT NULL;

Share and enjoy.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. It worked partly: the former error is gone of course, but for some reason it doesn't find any data: if I try version := 'version-123; select ID_DOCUMENT into document from DOCUMENTTABLE where extract(DOCUMENT_XML, '//p:content[@ref=' || version || ']', 'xmlns:p="http://www.foo.com/v1"').getClobVal() IS NOT NULL; the error is ORA-01403: no data found. However, there is data if I insert the string directly. Do you know the reason? Thanks in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.