将varchar转换为varchar Ingres DB

时间:2016-11-10 01:20:36

标签: sql varchar ingres

我有INGRES DB 10.0

我有LONG VARCHSR数据类型的变量。用户提交长字符串, 然后我有while循环,从这个字符串中取+2000个字符并将其放在表中,其中列具有varchar(255)数据类型。当我试图编译这个程序时,我收到错误E_US0971 Target list expression of type 'long varchar' cannot be coerced into local variable/parameter of type 'varchar'

这是我的while循环

    :notelinenumber = 1; 
    :i = 1;

WHILE :i < LENGTH(:note_text)
    do 
    select SUBSTRING (:note_text, :i, 1900) into :note_part;

    INSERT INTO NOTE
            (note_number,
             note_line_number,
             note_date_stamp,
             note_text)
    VALUES  ( :note_number,
              :notelinenumber,
              Date( 'now' ),
              :note_part); 

        :i = :i+1900;
        :notelinenumber = :notelinenumber+1;        
ENDWHILE;

这里是:note_text = long varchar数据类型,但是note_part = varchar(255)。

如何将我从while var循环接收的那部分从long varchar转换为varchar(255)?

1 个答案:

答案 0 :(得分:-2)

答案非常简单,只需将long varchar转换为varchar

即可
    :notelinenumber = 1; 
    :i = 1;

WHILE :i < LENGTH(:note_text)
    do 
    select varchar( SUBSTRING (:note_text, :i, 1900)) into :note_part;

    INSERT INTO NOTE
            (note_number,
             note_line_number,
             note_date_stamp,
             note_text)
    VALUES  ( :note_number,
              :notelinenumber,
              Date( 'now' ),
              :note_part); 

        :i = :i+1900;
        :notelinenumber = :notelinenumber+1;        
ENDWHILE;