Use SQL Query to convert a base64 string back into an image - sql

I'm trying to write a SQL statement that will convert an image in a base64 string format back to an image and save to the file system.

As per the comments above, I can't accomplish what I want using pure SQL. Will call C# code from SQL instead.

Related

Oracle convert blob to string

I would like to convert a blob of an oracle db to an readable string.
I have tried some functions, but none of them worked for me.
In the end I tried to convert the string via sql statement like:
SELECT CONVERT(CAST(blob as BINARY) USING utf8) as blob FROM tablewithblob
Can anyone tell me, what I am doing wrong? The error of the sqldeveloper is "missing right paranthesis. Thanks in advance!
The CONVERT(value USING charset) function is a mysql function, not Oracle
https://www.w3schools.com/sql/func_mysql_convert.asp
Take a look at this instead
https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions027.htm
But it looks like DBMS_LOB is a better way to do what you're doing in Oracle. Go check out How do I get textual contents from BLOB in Oracle SQL

Convert DB2 EBCDIC column to Ascii in a SQL Statement

I know I can do the conversion very easily using C# or any other number of programming languages, however, I want to know if I can do the conversion of a column that has EBCDIC encoded text so that the result of the query is in a readable string such as ascii encoded.
Ultimately, I will import the data into SQL Server and I know SSIS can do it, but before I do that, I want to exhaust any paths that are not SQL language.
For example a little know combination of built in functions available in DB2 SQL or SQL-Server 2008
Here is an example of data
Data as stored in DB2: 0xC6C3C3C1E3C5D9D7C9D3D360F8F840
Text: FCCATERPILL-88
The C# conversion is so easy so I included it here:
System.Text.Encoding ei = Encoding.GetEncoding(37);
textBox1.Text = ei.GetString(allBytes.ToArray())
I'm not an AS400 admin so I'm not sure what to do with what is being suggested in the comments.

Convert VarBinary RTF blob to text in MS SQL

I am using SQL server - 2008.
Column Datatype - VarBinary
RTF File is compressed and saved to this varbinary column.
Now how to access and view data in RTF file using SQL ?
it's returns this: 㠰た㠴弰巎楛㵤㠵㜸ㄲ㠴. etc.
Sample Tried Code here:
http://rextester.com/YOFHK34016
any solution to this.
in 2008 Decompress and compress function not work.
how i can get RTF file as it is to text.
That's works for me:
select convert(varchar(max),convert(varbinary(max),bv.value)) from blobValue bv
Instead using nvarchar try to use varchar.
But I shuld say that this will return rtf formated text, something like:
"{\rtf1\ansi\ansicpg1251\deff0\deflang1049{\fonttbl{\f0\fnil MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}"
To get actual text from it you can use .Net dll to convert it.
You can add .net dll to your database and than call it's functions from Sql script. More detailed about it: Call dll function from sql stored procedure using the current connection
It worked for me, thanks a bunch.
I used:
SELECT convert(nvarchar(max),convert(varbinary(max),[FORMULATEXT]))

How to read BLOB from oracle db?

I'm trying to read BLOB data in the form of string from oracle db using sql developer.
This is the query that I'm using :
select utl_raw.cast_to_varchar2(dbms_lob.substr(BLOB_COL,2000)) from BLOB_TABLE where BLOB_ID= 997600;
But the output what I get is machine readable format and not text.
Any suggestions on how to change this query?
Run the query, just query the BLOB column.
Double click on the cell.
Check the 'text' value.
Voila.

RTF to plain text in SQL with read only permissions

I have a MSSQL 2005 database which also stores RTF-like text format. I'd like to strip off all formatting code and just get the plain text. Now the tricky part; I only have read access to the database. So, unfortunately I can't use any CREATE FUNCTION solutions...
For example, a column starts with something like:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}} \viewkind4\uc1\pard\lang1043\ul\b\f0\fs22
Can this be done?