数字或值错误:字符到数字的转换错误pl / sql

时间:2018-10-11 19:57:20

标签: sql oracle plsql

所以我实际上只是想将行输出到圣诞节的12天,只是为了处理PL / SQL中的循环,而且我什至似乎都无法正确地声明一个简单的数组。这是代码:

CREATE OR REPLACE
    TYPE all_gifts is object (first_words varchar2(20), second_words varchar2(50));
/
DECLARE
type gifts is table of all_gifts;
type daysarray IS VARRAY(12) OF VARCHAR2(20); 


lv_gifts GIFTS := gifts(  all_gifts('and a','Partridge in a pear tree')
                        , all_gifts('Two','Turtle Doves')
                        , all_gifts('Three','French Hens')
                        , all_gifts('Four','Calling Birds')
                        , all_gifts('Five','Golden Rings')
                        , all_gifts('Six','Geese a laying')
                        , all_gifts('Seven','Swans a Swimming')
                        , all_gifts('Eight','Maids a milking')
                        , all_gifts('Nine','Ladies Dancing')
                        , all_gifts('Ten','Lords a leaping')
                        , all_gifts('Eleven','Pipers piping')
                        , all_gifts('Twelve','Drummers drumming')
                        );
second_array_elem varchar2(50);
lv_counter NUMBER := 1;
lv_days daysarray;
lv_first_word VARCHAR2(50);
BEGIN
lv_days := daysarray('First','Second','Third','Fourth','Fifth','Sixth','Seventh','Eigth','Ninth','Tenth','Eleventh','Twelefth');

FOR day in 1 .. lv_days.count loop

    IF day != 'first' THEN
        lv_first_word := second_array_elem;
    ELSE 
        lv_first_word := 'A';
        second_array_elem := lv_gifts.first;
    END IF;

    dbms_output.put_line('On the ['||lv_days(day)||'] day of Christmas');

    second_array_elem := lv_gifts.next(second_array_elem);

END LOOP;

END;
/

控制台在我的BEGIN语句(我试图声明lv_days数组)之后的行上抛出错误,说:

numeric or value error: character to number conversion error

但是,在上面的声明语句中,我将其作为12个索引的变化数组,类型为varchar2(20)
我在这里错过了哪个简单的步骤?

1 个答案:

答案 0 :(得分:1)

问题与下面的代码行..

IF day != 'first' THEN

根据代码,系统正在尝试将循环变量与字符串'first'

进行比较

您可以使用以下代码

IF lv_days(day) != 'first' THEN