<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sybase数据库技术，数据库恢复专家 &#187; TEXT</title>
	<atom:link href="http://www.dbainfo.net/tag/text/feed" rel="self" type="application/rss+xml" />
	<link>https://www.dbainfo.net</link>
	<description>提供Sybase ASE及Sybase SQL Anywhere数据库修复服务，电话：13811580958(微信)，QQ：289965371！We have many years of experience in recovering data from damanged Sybase devices. Contact us by Phone: +86 13811580958 Wechat: 13811580958 Email: 289965371@qq.com</description>
	<lastBuildDate>Sat, 14 Jun 2025 16:28:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ASE中对于大文本字段的使用方法</title>
		<link>https://www.dbainfo.net/ase-lob-text-image-usage.htm</link>
		<comments>https://www.dbainfo.net/ase-lob-text-image-usage.htm#comments</comments>
		<pubDate>Tue, 02 Apr 2013 03:47:57 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Sybase ASE]]></category>
		<category><![CDATA[readtext]]></category>
		<category><![CDATA[TEXT]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/?p=2048</guid>
		<description><![CDATA[ASE中对 text、image 和 unitext 列的限制 不能在以下情况中使用 text、image 或 unitext 列： &#160; 用作存储过程的参数或传递给这些参数的值 &#160; 作为局部变量 &#160; 在 order by clause、compute clause、group by 和 union 子句中 &#160; 用于索引 &#160; 用于子查询或连接 &#160; 在 where 子句中，除非带有关键字 like &#160; 同 + 并置运算符一起使用 建立测试数据： create table test_lob(id int not null,notes text null) go insert into test_lob values(1,replicate(&#39;x&#39;,1024)) go insert into test_lob [...]]]></description>
			<content:encoded><![CDATA[<p><strong>ASE中对 text、image 和 unitext 列的限制</strong><br />
	不能在以下情况中使用 text、image 或 unitext 列：</p>
<ol>
<li>&nbsp; 用作存储过程的参数或传递给这些参数的值</li>
<li>&nbsp; 作为局部变量</li>
<li>&nbsp; 在 order by clause、compute clause、group by 和 union 子句中</li>
<li>&nbsp; 用于索引</li>
<li>&nbsp; 用于子查询或连接</li>
<li>&nbsp; 在 where 子句中，除非带有关键字 like</li>
<li>&nbsp; 同 + 并置运算符一起使用</li>
</ol>
<p>建立测试数据：<br />
	create table test_lob(id int not null,notes text null)<br />
	go<br />
	insert into test_lob values(1,replicate(&#39;x&#39;,1024))<br />
	go<br />
	insert into test_lob values(2,replicate(&#39;y&#39;,16384))<br />
	go<br />
	如果想造text类型字段的数据的话，因为ASE中字符串函数、变量等受限于16384，可以先bcp导出，编辑后再导入。</p>
<p>	查看text类型字段的长度，使用函数： datalength 。<br />
	select id,datalength(notes) from test_lob <br />
	go<br />
	<span id="more-2048"></span></p>
<p>	<strong>一、如果text类型字段的长度小于16384字节的话，建议使用convert将text类型转化为varchar,然后再对字符串进行处理。</strong><br />
	比如：提取text字段每行数据的前1000字节<br />
	declare @len int<br />
	select @len=1000<br />
	select substring(convert(varchar(16384),notes) ,1 ,@len) from test_lob<br />
	go</p>
<p>	<strong>&nbsp;二、如果text类型字段的长度大于16384字节的话，建议使用textptr、readtext等命令来处理text类型字段。</strong><br />
	对于text类型字段，先使用textptr返回16字节的指针，然后用readtext读取该指针的响应内容。<br />
	readtext命令第一个参数为text类型字段名，第二个字节为16字节的指针，第三个字段为偏移量（第一个字符的偏移为0），第四个字节为想要提取的字符长度。<br />
	使用函数textvalid判断LOB列的指针是否有效？ select textvalid(&quot;test_lob.notes&quot;,textptr(notes)) from test_lob</p>
<p>	declare @val binary(16),@len int<br />
	select @len=datalength(notes),@val=textptr(notes) from test_lob where id = 2<br />
	readtext test_lob.notes @val 0 @len<br />
	go</p>
<p>	注意：在使用readtext读取text类型字段的时候，能够显示的内容的最大长度受限于@@textsize，该全局变量默认值为：32768。查看当前textsize的值，使用：select @@textsize<br />
	在当前会话中设置textsize,使用： set textsize 1000000<br />
	可以在数据库连接串中设置textsize选项。</p>
<p>
	<strong>三、循环读取text类型字段的值</strong><br />
	例如：每次读取500字节，</p>
<blockquote>
<p>declare @val binary(16),@len int<br />
		declare @i int,@loop_times int,@offset int,@get_len int<br />
		--each time get 500 chars<br />
		select @get_len=500<br />
		select @len=datalength(notes),@val=textptr(notes) from test_lob where id = 1<br />
		select @loop_times=ceiling(1.0*@len/@get_len),@i=0,@offset=0<br />
		if @len &lt; @get_len select @get_len = @len<br />
		while (@i &lt; @loop_times)<br />
		begin<br />
		&nbsp; readtext test_lob.notes @val @offset @get_len<br />
		&nbsp; select @i=@i+1<br />
		&nbsp; select @offset=@i*500<br />
		&nbsp; if (@i = @loop_times - 1) select @get_len=@len-@i*500<br />
		end<br />
		go</p>
</blockquote>
<p>对于substring函数，如果想要获取的长度大于当前内容长度，则提取所有字符。<br />
	readtext的最后一个参数必须保证offset+length小于或等于text字段最大长度。否则，报：<br />
	Msg 7124, Level 16, State 1:<br />
	The offset and length specified in the READTEXT command is greater than the actual data length of 1024.</p>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/ase-lob-text-image-usage.htm">https://www.dbainfo.net/ase-lob-text-image-usage.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/ase-lob-text-image-usage.htm">ASE中对于大文本字段的使用方法</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">随机日志</h2><ul class="related_post"><li>2010-04-09 -- <a href="https://www.dbainfo.net/sybase1503-cross-platform-recovery.htm" title="Sybase15.0.3跨平台恢复过程">Sybase15.0.3跨平台恢复过程</a> (0)</li><li>2010-06-01 -- <a href="https://www.dbainfo.net/sybase-ase-initialize-service-solaris-share-memory-segment-projadd.htm" title="解决solaris10上因为共享内存不足导致不能初始化sybase15.0.3服务的问题">解决solaris10上因为共享内存不足导致不能初始化sybase15.0.3服务的问题</a> (0)</li><li>2015-03-08 -- <a href="https://www.dbainfo.net/sap-pb-cr-number-2.htm" title="SAP PB Enterprise的所有已知BUG列表（2）">SAP PB Enterprise的所有已知BUG列表（2）</a> (1)</li><li>2010-08-10 -- <a href="https://www.dbainfo.net/oracle10g-create-database-manully-ora-02778.htm" title="手动创建oracle数据库时报错：ORA-02778">手动创建oracle数据库时报错：ORA-02778</a> (0)</li><li>2011-09-20 -- <a href="https://www.dbainfo.net/isqlbcp_news.htm" title="Sybase ASE 15.x版本中bcp和isql工具的新特性">Sybase ASE 15.x版本中bcp和isql工具的新特性</a> (0)</li><li>2010-10-12 -- <a href="https://www.dbainfo.net/sybase-ase-sameas-sqlplus-desc-sp_desc.htm" title="Sybase ASE中实现类似oracle的sqlplus中desc命令来简要显示表结构的存储过程">Sybase ASE中实现类似oracle的sqlplus中desc命令来简要显示表结构的存储过程</a> (0)</li><li>2011-07-18 -- <a href="https://www.dbainfo.net/sybase-ase-v15-7-getting-released-in-sep2011-techwave.htm" title="Sybase ASE V15.7将在2011年9月发布">Sybase ASE V15.7将在2011年9月发布</a> (0)</li><li>2013-11-19 -- <a href="https://www.dbainfo.net/showplan_html_format.htm" title="以HTML格式显示ASE查询计划">以HTML格式显示ASE查询计划</a> (0)</li><li>2010-09-10 -- <a href="https://www.dbainfo.net/ase-device-dsync-directio-introduction.htm" title="ASE设备中的dsync和directio属性介绍">ASE设备中的dsync和directio属性介绍</a> (1)</li><li>2014-06-24 -- <a href="https://www.dbainfo.net/find_suspect_index.htm" title="查找并修复损坏的索引">查找并修复损坏的索引</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/ase-lob-text-image-usage.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
