Sybase database is today in the UNIX environment, one of the most popular large databases, I under Sybase development and maintenance of software in the process, found some of Sybase's internal rules, in the program design is very easy to cause misunderstanding, and not achieve the intended purpose. A few of the issues that I have identified and their solutions are described below:
1. In sybase11.5, combine two fixed-length char (x) = "AAA", char (Y) = "BBB"; char (x) +char (y)!= "aaabbb"
declare @val_1 char(8)
declare @val_2 char(1)
select @val_2 = ’x’
select @val_1 = "0000"
select @var_1= @val_1 + @val_2
select @var_1
We expect the result to be 0000x, but the result is actually 0000.
Workaround One: When we change the "select @var_1 = @val_1 + @val_2" to "Select @var_1 =rtrim (@var_1) + @var_2, we see the results we expect. Why, then? When a char (n) is stored in some Sybase versions, the corresponding amount of space is filled after its true value, in this case, 0000 (four spaces after 0000) in the @var_1. You can add the following two sentences to verify:
declare @val3 char(10)
select @val3 = @val_1 + @val_2
select @val3
Then you'll get the result is 0000 x (four spaces after 0000).
Workaround two: changing char to varchar can also achieve the desired purpose.
2. When the table structure is added with ALTER TABLE, although the affected database objects are recompiled with sp_recompile tablename, the stored process does not recognize the use of alter when running some stored procedures that contain the SELECT * from TableName. Table to increase the column. Cases:
1> create table tmp(aa int,bb int)
2> go
1> create table b_tmp(aa int,bb int)
2>go
1> create proc tmpstore
2> as
1> insert b_tmp select * from tmp
2> return
3> go
1> alter table tmp add cc char(8) null
2> go
1> alter table b_tmp add cc char(8) null
2> go
1> sp_recompile tmp
2> go
1>insert tmp values(12,1234,"abcdefg")
2>go
1> exec tmpstore
2> go
1> select * from b_tmp
2> go
aa bb cc
----------- ------------- -------------
12 1234 NULL
Why is the CC field null instead of "ABCDEFG"? After adding the table structure with ALTER TABLE, the stored procedure containing the "SELECT * from TableName", which is sp_recompile tablename recompile, still does not allow the new column to be recognized by the stored procedure. There is only one solution: the deletion of reconstruction.