• 相关软件
    >TEXTPTR 创建者:webmaster 更新时间:2006-02-16 15:51

    varbinary 格式返回对应于 textntextimage 列的文本指针值。检索到的文本指针值可用于 READTEXT、WRITETEXT 和 UPDATETEXT 语句。



    语法


    TEXTPTR ( column )



    参数


    column



    待使用的 textntextimage 列。



    返回类型


    varbinary



    注释


    在 Microsoft SQL Server™ 2000 中,对于带行内文本的表,TEXTPTR 为要处理的文本返回一个句柄。即使文本值为空,用户仍能获得有效的文本指针。



    如果表不带行内文本,并且 textntextimage 列还未由 UPDATETEXT 语句初始化,则 TEXTPTR 将返回空指针。



    可使用 TEXTVALID 来检查文本指针是否存在。在无有效文本指针时,不能使用 UPDATETEXT、WRITETEXT 或 READTEXT。



    下列函数和语句对 textntextimage 数据同样有用。





























    函数或语句描述
    PATINDEX('%pattern%', expression)返回给定字符串在 textntext 列中的字符位置。
    DATALENGTH(expression)返回 textntextimage 列的数据长度。
    SET TEXTSIZE返回可用 SELECT 语句返回的 textntextimage 数据的极限大小(以字节为单位)。
    SUBSTRING(text_column, start, length)返回由给定 start 偏移量和 length 所指定的 varchar 字符串。此长度应小于 8 KB。



    示例


    A. 使用 TEXTPTR


    下例使用 TEXTPTR 函数在 pubs 数据库的 pub_info 表中查找与 New Moon Books 相关联的 image logo。文本指针放置在局部变量 @ptrval 中。



    USE pubs
    GO
    DECLARE @ptrval varbinary(16)
    SELECT @ptrval = TEXTPTR(logo)
    FROM pub_info pr, publishers p
    WHERE p.pub_id = pr.pub_id
      AND p.pub_name = 'New Moon Books'
    GO


    B. 使用带行内文本的 TEXTPTR


    在 SQL Server 2000 中,行内文本指针必须在事务内部使用。示例如下:



    CREATE TABLE t1 (c1 int, c2 text)
    EXEC sp_tableoption 't1', 'text in row', 'on'

    INSERT t1 VALUES ('1', 'This is text.')
    GO

    BEGIN TRAN
      DECLARE @ptrval VARBINARY(16)
      SELECT @ptrval = TEXTPTR(c2)
      FROM t1
      WHERE c1 = 1
      READTEXT t1.c2 @ptrval 0 1
    COMMIT



    C. 返回文本数据


    下例从 pub_info 表中选择 pub_id 列和 pr_info 列的 16 字节文本指针。



    USE pubs
    GO
    SELECT pub_id, TEXTPTR(pr_info)
    FROM pub_info
    ORDER BY pub_id
    GO


    下面是结果集:



    pub_id                                    
    ------ ----------------------------------
    0736   0x6c0000000000feffb801000001000100
    0877   0x6d0000000000feffb801000001000300
    1389   0x6e0000000000feffb801000001000500
    1622   0x700000000000feffb801000001000900
    1756   0x710000000000feffb801000001000b00
    9901   0x720000000000feffb801000001000d00
    9952   0x6f0000000000feffb801000001000700
    9999   0x730000000000feffb801000001000f00

    (8 row(s) affected)


    下例显示如何在不使用 TEXTPTR 的情况下返回文本的前 8,000 个字节。



    USE pubs
    GO
    SET TEXTSIZE 8000
    SELECT pub_id, pr_info
    FROM pub_info
    ORDER BY pub_id
    GO


    下面是结果集:



    pub_id pr_info                                                                                                                                                                                                                                                         
    ------ -----------------------------------------------------------------
    0736   New Moon Books (NMB) has just released another top ten publication. With the latest publication this makes NMB the hottest new publisher of the year!                                                                      
    0877   This is sample text data for Binnet & Hardley, publisher 0877 in the pubs database. Binnet & Hardley is located in Washington, D.C.

    This is sample text data for Binnet & Hardley, publisher 0877 in the pubs database. Binnet & Hardley is located in Washi
    1389   This is sample text data for Algodata Infosystems, publisher 1389 in the pubs database. Algodata Infosystems is located in Berkeley, California.

    9999   This is sample text data for Lucerne Publishing, publisher 9999 in the pubs database. Lucerne publishing is located in Paris, France.

    This is sample text data for Lucerne Publishing, publisher 9999 in the pubs database. Lucerne publishing is located in

    (8 row(s) affected)


    D. 返回特定文本数据


    下例在 pubs 数据库的 pub_info 表中查找与 pub_id 0736 相关联的 text 列 (pr_info)。下例首先声明一个局部变量 @val。然后将文本指针(长二进制字符串)置于 @val 中,并将其作为参数提供给 READTEXT 语句,该语句将返回从第五个字节(偏移量为 4)开始的 10 个字节。



    USE pubs
    GO
    DECLARE @val varbinary(16)
    SELECT @val = TEXTPTR(pr_info)
    FROM pub_info
    WHERE pub_id = '0736'
    READTEXT pub_info.pr_info @val 4 10
    GO


    下面是结果集:



    (1 row(s) affected)

    pr_info                                                                                                                                                                      
    ------------------------------------------------------------------------
    is sample
    相关文章
    本页查看次数: