Accessing JSON inside CLOB column - sql

I'm trying to access the columns stored inside this CLOB of JSON. However, because it is not version 12C of Oracle I cannot use dot notation to reference the column names like "table.column"
I am really struggling. I have tried to use dbms_lob.substr to extract it but i just end up getting the full CLOB.
My screenshot attached is displayed when running the following :
SELECT
*
FROM TRANSFORM_OB_BB_SIT_OWNER.BUCKETS
WHERE bucket_name ='LatestApplicationVersions'
However, I want to be able to access 'PersonalCountryOfNationality' where it is = 'United Kingdom' enter image description here

If you want to work with JSON with a version older than 12c, I recommend using the PLJSON package, here is a link:
https://github.com/pljson/pljson/tree/develop
You can find exemples here:
https://github.com/pljson/pljson/tree/develop/examples

Related

Replacing text inside blob

I got quite large xml saved in BLOB and I need to edit value its value.
I'm trying following
UPDATE MY_TABLE
SET MY_BLOB=REPLACE(CONVERT(MY_BLOB USING UTF8), 'oldValue', 'newValue')
WHERE MY_ID = 'someID'
Still, I keep getting SQL Error: ORA-00907: missing right parenthesis
but srsly, where do I miss something?
CONVERT needs a least two input parameters and is not for BLOB
Documentation
Here is useful information about update a text in BLOB column.
You can consider converting blob to clob and then calling replace function on it. Some useful info: http://fazlansabar.blogspot.com/2012/03/replace-function-for-blob-fields-in.html

Encrypting the output using select statement on oracle database

Updated question:
I am working with scenario where the source oracle schema do not have a field say "Date of Birth" saved in encrypted format but when using select statement I want output to be in encrypted format. I do not know the version of the oracle to find the appropriate function in the documentations.
I have worked with MySQL and I am familiar with "password()" function.  I am looking for similar function for Oracle in SQL not PL/SQL as I cannot use that in the application I am using it should be one line query to fetch the results. I tried using DBMS_CRYPTO as per the documentation https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_crypto.htm#i1004271 but I am getting error fetching data on my application could be possible that DB version may not be supporting DBMS_CRYPTO.
Any other suggestion on which function can be used to display non-encrypted field in encrypted format when using select on Oracle(thin) query?

Oracle 12C : querying based on json keys having '.' in them

I am exploring oracle 12c for storing json data in a json aware clob column named METADATA. My existing data in that column looks something like this:
{
"com.xyz.abc.key": {
"key_a": "value_a",
"key_b": ["value_b_1", "value_b_2", "value_c_2"]
}
}
The problem is that if I were to construct a query using JSON_VALUE
JSON_VALUE(METADATA ,'$.com.xyz.abc.key.key_a')
then I rightly get null as result as oracle will interpret a different json path. I tried escaping characters but that also doesn't work.
I went through oracle's whitepaper on this topic but it doesn't cover this case.
I need help in correctly constructing my SQL/JSON query in this case.
Edit
Solution : '$."com.xyz.abc.key".key_a' is the correct way for doing this.

ORA-00911: invalid character - Using XMLType

I have been working with Oracle XML DB of version 11gR2. I have created a XML table with column as XMLType(Binary XMLType).
Question 1:
When I insert a XML document, all the single quotes in the attributes list gets converted to double quotes automatically. How can I get rid of this? Because I have to reprocess the entire XML document when I have to fetch it.
Question 2:
When I tried to retrieve I have used function getclobval(). This is working well with SQLPLUS and SQL Developer. However when I run this query through OCI, I am getting the error "ORA-00911: invalid character"
Can anyone help me on the above two questions?
Q1:
Have a look on Oracle support at bug 9871299: LOSS OF UNESCAPING WITH XMLTABLE
This bug was introduced in 11.2.0.1.

How to fire a select query for this certain tag <m:Number> in XMLTYPE

I am using a XMLTYPE column in my table.
My schema is developed on this link on sqlfiddle
http://sqlfiddle.com/#!4/90306/1
I am able to fetch the value of building using the query there.
But my actual XML is
http://sqlfiddle.com/#!4/226cf
<m:Building>FBI</m:Building>
having a tag like <m:Building> .
But when i am trying to get the value of building here in second schema,i am getting error.
How i can achieve this ?
Thanks in advance.
You'll need to provide the XML Namespace to the extract function, for example:
SELECT
w.col1.extract
('/House/Building/text()', 'xmlns="rn://dt.com/batch/2010/08/13"').getStringVal()
"Building"
FROM tab1 w;