获取后PLSQL无效数字错误

时间:2015-06-07 23:18:14

标签: plsql numbers fetch

抱歉,如果这是一个令人困惑的帖子,风格不合适,但这是我的第一个问题,但我想要获取c_latlong后出错:

他要取的东西是:
LAT值:50,9459744669855
LON值:5,9704909091251

ORA-01722:无效的号码
ORA-06512:at" DOMINOS.GETLATLONG",第14行
ORA-06512:at" DOMINOS.ZOEKWINKELVOORADRES2",第34行
ORA-06512:第9行

这是我使用的代码:

create or replace FUNCTION getLatLong(v_postcode varchar2, v_huisnummer varchar2)  
RETURN varchar2  
IS  
  v_lat NVARCHAR2(38) ;  
  v_long NVARCHAR2(38);  
  v_postcode_id varchar2(200);  
  v_all varchar2(200);   
  CURSOR c_latlong IS  
     SELECT LAT, LON  
     FROM POSTCODE  
     WHERE POSTCODE =  v_postcode AND v_huisnummer BETWEEN MINNUMBER AND   MAXNUMBER;  
BEGIN  
  OPEN c_latlong;  
  FETCH c_latlong INTO v_lat, v_long;  
    v_all := v_lat || '-' || v_long;  
   -- print(v_all);  
    RETURN v_all;
  CLOSE c_latlong;
END getLatLong;

create or replace FUNCTION zoekWinkelVoorAdres2(v_postcode varchar2, v_huisnummer varchar2)  
RETURN varchar2  
IS  
  v_array_this apex_application_global.vc_arr2 := apex_util.string_to_table(getLatLong(v_postcode,v_huisnummer), '-');  
  v_temp_postcode varchar2(200);  
  v_temp_huisnummer varchar2(200);  
  v_temp_id varchar2(200);  
  v_temp_winkel apex_application_global.vc_arr2;  
  v_array dbms_sql.varchar2_table;  
  v_max number;  

  v_closest_winkel varchar2(200);  
  v_closest_dis varchar2(200);  

  CURSOR c_all_stores_max IS  
    SELECT count(*)  
    FROM WINKEL;  
  CURSOR c_all_stores IS  
    SELECT ID, POSTCODE, HUISNR  
    FROM WINKEL;  
  CURSOR c_select_dis IS  
  SELECT WINKEL_ID, DISTANCE   
  FROM allwinkeldis ORDER BY DISTANCE DESC;  
BEGIN  
  --DELETE FROM allwinkeldis;  
  OPEN c_all_stores_max;  
    FETCH c_all_stores_max INTO v_max;  
  CLOSE c_all_stores_max;  
  OPEN c_all_stores;  
    FOR i IN 1..v_max  
    LOOP  
      FETCH c_all_stores INTO v_temp_id, v_temp_postcode, v_temp_huisnummer;  
     -- print('-------------------1---------------------' ||v_temp_postcode);  
     print(getLatLong(v_temp_postcode,v_temp_huisnummer));  
      v_temp_winkel :=apex_util.string_to_table(getLatLong(v_temp_postcode,v_temp_huisnummer), '-');  
    --  print(v_temp_id || ' ' || v_temp_winkel(1) || ' ' || v_temp_winkel(2));  
     --   print('-------------------2---------------------');  
      --v_array(i) := v_temp_id ||','||distance(v_array_this(2), v_array_this(3),v_temp_winkel(2),  v_temp_winkel(3));  
      INSERT INTO allwinkeldis(winkel_id, distance) VALUES (v_temp_id, distance(v_array_this(1), v_array_this(2), v_temp_winkel(1),  v_temp_winkel(2)));  
      --print(v_temp_id ||' -------------- '||distance(v_array_this(2), v_array_this(3), v_temp_winkel(2),v_temp_winkel(3)));  
    END LOOP;  
  CLOSE c_all_stores;  
  OPEN c_select_dis;  
      FETCH c_select_dis INTO v_closest_winkel, v_closest_dis;  
  CLOSE c_select_dis;  
  print(v_closest_winkel || '--------------' || v_closest_dis);  

END zoekWinkelVoorAdres2;

2 个答案:

答案 0 :(得分:0)

我不确定您的表LATLONPOSTCODE的数据类型是什么。 但无论您为获取数据定义的变量如何,它们都必须匹配这些类型。

例如,假设LATLON属于NVARCHAR2类型,那么我将按如下方式重写您的声明部分:

CREATE OR REPLACE FUNCTION getLatLong(v_postcode varchar2, v_huisnummer varchar2)  
RETURN varchar2  
IS  
  v_postcode_id varchar2(200);  
  v_all varchar2(200);  

  CURSOR c_latlong IS  
     SELECT LAT, LON  
     FROM POSTCODE  
     WHERE POSTCODE =  v_postcode AND v_huisnummer BETWEEN MINNUMBER AND   MAXNUMBER;  

     TYPE temp_nvarchar2 IS TABLE OF NVARCHAR2(38);
     v_lat   temp_nvarchar2;  
     v_long  temp_nvarchar2;  
BEGIN  
     ....

答案 1 :(得分:0)

invalid number错误发生在它需要一个数字并获得其他内容时,就像varchar一样。

v_latv_lon被声明为NVARCHAR2。这与POSTCODE中存储的数据类型相同吗?如果不是,这就是错误的原因。

v_all := v_lat || '-' || v_long;也可能遇到问题。如果v_latv_long是数字,那么您需要将它们转换为字符,如下所示:

v_all := TO_CHAR(v_lat) || '-' || TO_CHAR(v_long);