How to retrieve text stored in BLOB column in ORACLE 11g using SQL? - sql

I have compressed json text stored in BLOB column in Oracle 11g.
Is it possible to retrieve it using SQL only?
EDIT:
AFAIK the data was compressed on Linux OS using ZLIB and loaded using dbms_lob.loadfromfile

Oracle doesn't provide any built-in functions that would uncompress a ZLIB-compressed stream (though utl_compress uses very, very similar algorithms).
You would realistically need to load one of the various Java libraries that uncompresses a ZLIB-compressed stream into the database, write a bit of code to wrap that library, and then call that library from SQL. This wouldn't be a pure SQL implementation.
If you're really ambitious, it should be possible to implement the DEFLATE algorithm in pure SQL though that would likely be exceedingly painful SQL to write (or debug or maintain).

Related

Decompress gziped field with tsql prior 2016 features

How can you decompress an sql server field with nothing but tsql queries?
Assumptions:
The field was compressed using GZIP from an application.
The field is a varbinary(max).
MSSQL version is less than 2016, meaning you can't use decompress function.
I don't think this is possible, I tried searching on google and found nothing. I'd like to have confirmation on this.
I think your best bet is to look into a CLR solution. CLR functions are written in C# and then can be executed in a standard SQL call. There are loads of examples on the internet of CLR functions.
My answer assumes you have purely SQL Server and not a solution like SSIS or alike installed.
Here's a link for basic example. You'll load a library that handles gzips. Lots of solution directions here.
https://www.skylinetechnologies.com/Blog/Skyline-Blog/March-2013/CLR-Functions-in-SQL-Server-A-Tutorial

Equivalent of SQLXML Bulk Load in PostgreSQL

Is there an equivalent of Microsoft .Net's SQLXML Bulk Load (http://msdn.microsoft.com/en-us/library/ms171878.aspx) for Postgresql/PostGIS that I can run on linux? I have a huge and complicated XML file I'd like to import into PostGIS on a linux server without having to write a ton of code to shred the XML. I already have the XSD for it (this one: http://www.dft.gov.uk/transxchange/schema/schemas.htm) so I was hoping I could just specify the relations in the XSD (eg sql:key-fields="ProductID") and set it going.
If there isn't what's the next best thing to import it if I don't want to have to spend weeks writing code to convert XML into tables?
I am not aware of any utility, but I wonder if this is because, for the most of the open source weakly typed languages have good XML file parsers you could use to just pull it into a giant data structure and process it however you like.
So assuming you don't have files that are are huge, my recommendation would be something like Perl, DBI, and XML::Simple.

Which RDBMS has the richest super-set of ANSI-SQL?

Back in 1989, when I used to program with Oracle 5.2.3 on UNIX and VAX/VMS platforms, I considered SQLPLUS as having the richest super-set of built-in functions. ORACLEFORMS also had the ability to embed SQL statements within triggers. That was then, 21 years ago. At present, which other RDBMS' have come close, have the same, or more functionality than Oracle's SQLPLUS, DB2?.. SQL-Server?.. T-SQL?.. MySQL?.. etc?
It's hard to tell what is "richest". All systems have some proprietary things which the other systems don't support, including, but not limited to:
MODEL clause in Oracle
CROSS APPLY in SQL Server
DISTINCT ON in PostgreSQL
ON DUPLICATE KEY UPDATE in MySQL
DB2 has a complete Java virtual machine available for server side processing stored procedures, you don't get much more "complete" than that.
CouchDB uses JavaScript, can't get much more flexible and complete that that either.

SQL Images -> byte arrays

So I am importing some images stored in SQL image columns, and I need to change them to Byte arrays since I store my images as varbinary(max) and recreate them. I would LOVE it if there was a program to do this, or a really easy way since I don't have a ton of time.
Any ideas out there?
The image data type in Sql Server is a varbinary field that is being discontinued in future versions.
I would bet that a tool like bcp handles the "conversion" automatically. I use quotes because its a type conversion and not a format conversion.
Have you looked into writing a quick script in PowerShell? It has access to the full .NET framework, so should be somewhat simple if you're using those technologies.
Of course it's not simple if you have to learn PowerShell in order to write the script, but learning's always good :)

Querying XML like SQL?

Is there any framework for querying XML SQL Syntax, I seriously tire of iterating through node lists.
Or is this just wishful thinking (if not idiotic) and certainly not possible since XML isn't a relational database?
XQuery and XPath... XQuery is more what you are looking for if a SQL structure is desirable.
You could try LINQ to XML, but it's not language agnostic.
.Net Framework provides LINQ to do this or you can use the .Net System.Data namespace to load data from XML files.
You can even create queries that have joins among the tables, etc.
For example, System.Data.DataTable provides a ReadXml() method.
XQuery is a functional language that is closest to SQL. XPath is a notation for locating a node within the document that is used as part of XSLT and XQuery.
XML databases such as MarkLogic serve as XQuery engines for XML data, much as relational databases serve as SQL engines for relational data.
That depends on the problem you are solving. If XML file is pretty large, sometimes it's a necessity to use something like SAX parsers to traverse the file node by node, or you will get OutOfMemoryException or will run out even of virtual memory on your computer.
But, if the expected size of XML file is relatively small, you can simply use something like Linq, also see my answer - here I tried to explain, how to make traversing through nodes much easier with constructions like yield return.
SQL Server 2005 supports XML DML on it's native xml data type.
XQuery is certainly the way forward. This is what is used by XML databases like eXist and MarkLogic.
In the Java world there are several solutions for running XQuery on flat files, most notably Saxon
For .NET, there is not so much available. Microsoft did have an XQuery library, although this was pulled from .NET 2 and has never resurfaced. XQSharp is a native .NET alternative, although currently only a command line version has been released.