Search code examples
sap-ase

I need Sybase datatype to save string of indefinite Length.


My requirement is to declare a datatype which accepts xml value with maximum size.
Question: Do we have text, xml or varchar(max) datatype in Sybase?


Solution

  • There is text datatype. You can find More information here.

    How to use it with procedure:

    create procedure settxt
    (
      @txt text
    )
    as
    begin
      select @txt
    end
    

    How to run the procedure:

    declare @txt  text
    select @txt = 'Hello world'
    execute settxt @txt
    

    The code works for me, but maybe not for everyone.

    Here is solution with temporary table:

    create table #texttab
    (
      txt varchar(100)
    )
    go
    insert into #texttab
    values ('Hello ')
    
    insert into #texttab
    values  (' wolrd!')
    go
    create procedure settxt
    as
    begin
      declare @txt text, 
              @txtval varchar(100)  
    
      select @txt=' '
    
      declare curTXT cursor for 
      select txt from #texttab
    
    
      open curTXT
      fetch curTXT into @txtval  
      while @@sqlstatus=0 begin
        select @txtval
        select @txt=@txt+@txtval
        select @txt
        fetch curTXT into @txtval
      end
      close curTXT
      deallocate cursor curTXT
    
      select @txt
    
    end
    go
    execute settxt