To extract the value of a tag from an XML-like string in PL/SQL

12 January 2025

To extract the value of a tag from the given XML-like string in PL/SQL, you can use the EXTRACTVALUE function or XMLTABLE for XML processing.

Example Using EXTRACTVALUE

DECLARE
    xml_data CLOB := '<Status>200</Status><Message>Success</Message>';
    l_message VARCHAR2(50);
BEGIN
    -- Extract the FunctionalReferenceID value
    l_message := EXTRACTVALUE(XMLTYPE('<root>' || xml_data || '</root>'), '/root/Message');
    
    -- Print the value
    DBMS_OUTPUT.PUT_LINE('FunctionalReferenceID: ' || l_message);
END;

Example Using XMLTABLE

DECLARE
    xml_data CLOB := '<Status>200</Status><Message>Success</Message>';
    l_message VARCHAR2(50);
BEGIN
    -- Use XMLTABLE to extract the Message
    SELECT value
    INTO l_message
    FROM XMLTABLE(
        '/root/Message'
        PASSING XMLTYPE('<root>' || xml_data || '</root>')
        COLUMNS value VARCHAR2(50) PATH '.'
    );

    -- Print the value
    DBMS_OUTPUT.PUT_LINE('Message: ' || l_message);
END;

EXTRACTVALUE, XMLTABLE

Phoenix

11 January 2025

After all the chaos,
I will be reborn from the ashes
and soar high to the moon,
like a phoenix from a fairy tale.

I hope you’ll watch me
rise, just like the old days.

The Night

27 December 2024

Sometimes, the night is a good time to hide yourself from the rest of the world. It gives a sense of relief, allowing you to be exactly as you want to be.

In the middle of the dark night you become your true self.

The promise

6 December 2024

I know that one day I will collapse,
And hopefully, you won’t witness it.
I will make sure that, until your last breath,
I’ll stay strong and keep us stronger.

That’s the promise I made—to hold you
Forever.

It's you

5 December 2024

You are the most precious gift
you could ever wish for.
You are the light that guides you
through the darkest nights.
You are the Santa
you’ve always dreamed of.
You are the Christmas
you’ve been waiting for.

Varchar datatype limits

30 November 2024

For NVARCHAR2 and VARCHAR2 maximum size is 4000 bytes, or 32767 bytes if the MAX_STRING_SIZE initialization parameter is set to EXTENDED. This is useful you have to allocate more data to a variable.

You can run the below command to view the parameter.

show parameter MAX_STRING_SIZE;
References

Oracle Doc, Max string size

Hope

28 November 2024

To my daughter,

In the midst of the war,
Amid the heart-aching pain,
Through the windy nights,
On my darkest days,
You are my hope.

Writing

20 November 2024

I want to write something every day. I don’t know what to write, but I love to write.

I don’t want to write for publishing; I want to write for the sake of writing.

I think I can write about myself, the thoughts in my head, or the things around me.

So, I am writing here to feel alive.

Light is coming

18 November 2024

To those who are in dark: Hold on, light is coming—and it’s within you.