以上就是给各位分享BLOB转换为字符串,SQLServer,其中也会对sqlserverblob转换为字符串函数进行解释,同时本文还将给你拓展BLOB转换为字符串或图像/PHP或SQL、javascr
以上就是给各位分享BLOB转换为字符串,SQL Server,其中也会对sqlserver blob转换为字符串函数进行解释,同时本文还将给你拓展BLOB转换为字符串或图像/ PHP或SQL、javascript – 同步将Blob转换为二进制字符串、java读取blob,clob转换为字符串、mssql sqlserver sql 对使用逗号分隔的字符串 转换为数据表的另类方法实现等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- BLOB转换为字符串,SQL Server(sqlserver blob转换为字符串函数)
- BLOB转换为字符串或图像/ PHP或SQL
- javascript – 同步将Blob转换为二进制字符串
- java读取blob,clob转换为字符串
- mssql sqlserver sql 对使用逗号分隔的字符串 转换为数据表的另类方法实现
BLOB转换为字符串,SQL Server(sqlserver blob转换为字符串函数)
我有一个文本字符串作为BLOB
数据类型存储在数据库中。我想通过SQL选择查询将其提取,但是在从/转换BLOB
为可读时遇到了问题text
。
我试过了
select convert(nvarchar(40),convert(varbinary(40),BLOBTextToExtract))
from [NavisionSQL$Customer]
我想我需要类似的东西,但是我无法确切地知道我需要执行什么转换。有人可以给我一些指示吗?
问候
BLOB转换为字符串或图像/ PHP或SQL
我有一个数组,在第3维上给了我一个图像斑点.
但是我需要图像,我尝试使用sql
<?PHP $global = \Database::getInstance()->execute('SELECT CONVERT(VarChar(40), image)
FROM mm_product2
WHERE id = '.$referenzen['id'])->fetchAllAssoc(); ?>
<?PHP print_r($global);?>
它显示此错误:
Fatal error: Uncaught exception Exception with message Query error:
You have an error in your sql Syntax; check the manual that corresponds
to your MysqL server version for the right Syntax to use near 'VarChar(40),
image) FROM mm_product2 WHERE id = 23' at line 1 (SELECT CONVERT(VarChar(40),
image) FROM mm_product2 WHERE id = 23
没有表达式,它可以工作,但我又像在标准数组中那样得到那个blob值:
[image] => 85392c33-a0f7-11e4-acb9-08606e695836 )
我可以知道如何在PHP或仅在sql中转换该值吗?
解决方法:
使用mySQL查询获取变量中的blob数据,然后使用它
'<img src="data:image/jpeg;base64,' . base64_encode($image) . '" width="200" height="200">'
javascript – 同步将Blob转换为二进制字符串
所以我认为正确的方法是将canvas tu dataURL,dataURL转换为blob和blob转换为二进制字符串.
理论上应该可以跳过blob,但我不知道为什么.
所以这就是我做的:
function copy(event) { console.log("copy"); console.log(event); //Get DataTransfer object var items = (event.clipboardData || event.originalEvent.clipboardData); //Canvas to blob var blob = Blob.fromDataURL(_this.editor.selection.getSelectedImage().toDataURL("image/png")); //File reader to convert blob to binary string var reader = new FileReader(); //File reader is for some reason asynchronous reader.onloadend = function () { items.setData(reader.result,"image/png"); } //This starts the conversion reader.readAsBinaryString(blob); //Prevent default copy operation event.preventDefault(); event.cancelBubble = true; return false; } div.addEventListener('copy',copy);
但是当在粘贴事件线程之外使用DataTransfer对象时,setData不再有任何生效的机会.
如何在同一个函数线程中进行转换?
解决方法
function blobToUint8Array(b) { var uri = URL.createObjectURL(b),xhr = new XMLHttpRequest(),i,ui8; xhr.open('GET',uri,false); xhr.send(); URL.revokeObjectURL(uri); ui8 = new Uint8Array(xhr.response.length); for (i = 0; i < xhr.response.length; ++i) { ui8[i] = xhr.response.charCodeAt(i); } return ui8; } var b = new Blob(['abc'],{type: 'application/octet-stream'}); blobToUint8Array(b); // [97,98,99]
你应该考虑让它保持异步但是让它成为两个阶段,因为你最终可能会锁定浏览器.
此外,您可以通过包含二进制安全的Base64解码器完全跳过Blob,您可能不需要通过Base64 AND Blob,只需其中一个.
java读取blob,clob转换为字符串
package com.it.test;
import java.io.BufferedReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.sql.BLOB;
public class Test {
/***
* 读取oracleCLOB字段内容
*
* @param conn
* @return
*/
public static String readCLOB(Connection conn) {
String sql = "select 大字段1,大字段2 from 印章基本信息_char_ccbb where yzbm=''2''";
String content = "";
try {
conn.setAutoCommit(false);
PreparedStatement ps1 = conn.prepareStatement(sql);
ResultSet rs1 = ps1.executeQuery();
while (rs1.next()) {
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs1.getClob("大字段1");
BufferedReader in = new BufferedReader(clob.getCharacterStream());
StringWriter out = new StringWriter();
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
content = out.toString();
System.out.println(content);// 输出CLOB内容
}
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
/***
* 读取oracle的blob转换为字符串
*
* @param conn
* @return
*/
public static String ConvertBLOBtoString(Connection conn) {
String newStr = ""; // 返回字符串
long BlobLength; // BLOB字段长度
byte[] bytes; // BLOB临时存储字节数组
int i = 1; // 循环变量
Statement st = null;
try {
st = conn.createStatement();
ResultSet rs = st.executeQuery("select 大字段2 from 印章基本信息_char_ccbb where yzbm=''2''");
while (rs.next()) {
BLOB blob = (BLOB) rs.getBlob("大字段2");
byte[] msgContent = blob.getBytes(); // BLOB转换为字节数组
BlobLength = blob.length(); // 获取BLOB长度
if (msgContent == null || BlobLength == 0) // 如果为空,返回空值
{
return "";
} else {
while (i < BlobLength) // 循环处理字符串转换,每次1024;Oracle字符串限制最大4k
{
bytes = blob.getBytes(i, 1024);
i = i + 1024;
newStr = newStr + new String(bytes, "gb2312");
}
}
}
System.out.println(newStr);
System.out.println(newStr.length());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return newStr;
}
}
mssql sqlserver sql 对使用逗号分隔的字符串 转换为数据表的另类方法实现
转自:http://www.maomao365.com/?p=10739
摘要:
下文讲述在 sqlserver 对逗号分隔的字符串转换为数据表的另类方法实现,如下所示:
实验环境:sql server 2008 R2
实现思路:
将组合字符串中的逗号替换为 “''as n union all select ''”, 然后将替换后的字符串加上 select 和 前后加上单引号 是其成为可执行 sql 脚本,
最后运行替换后的字符串,就可以得到一张数据表,如下所示:
declare @maomao365 varchar(1000)
set @maomao365 =''sqlserver,blog,other'';
---将逗号替换为 ''as n union all select ''
set @maomao365 = REPLACE(@maomao365,'','',
'''''' as n union all select ''''''
);
---在字符串前面加上select 和单引号 ,后面也加上单引号
set @maomao365 ='' select ''''''+ @maomao365 + '''''''';
print @maomao365
exec (@maomao365)
今天关于BLOB转换为字符串,SQL Server和sqlserver blob转换为字符串函数的介绍到此结束,谢谢您的阅读,有关BLOB转换为字符串或图像/ PHP或SQL、javascript – 同步将Blob转换为二进制字符串、java读取blob,clob转换为字符串、mssql sqlserver sql 对使用逗号分隔的字符串 转换为数据表的另类方法实现等更多相关知识的信息可以在本站进行查询。
本文标签: