create or replace procedure save_pod_place_tag1 ( p_START_DATE in varchar2,
p_END_DATE in varchar2,
p_USER_ID in number,
p_TAG_ID in out number,
p_status out varchar2,
p_status_dtl out varchar2) is
v_rec_cnt number;
v_ID Number;
v_CNT Number;
type l_START_DATE is table of varchar2(100);
type l_END_DATE is table of varchar2(100);
v_st_dt l_START_DATE := l_START_DATE();
v_ed_dt l_END_DATE := l_END_DATE();
begin
v_ID := pod_unique_val_seq.nextval;
select to_char(start_date,'dd-mon-yyyy'),to_char(end_date,'dd-mon-yyyy')
bulk collect into v_st_dt,v_ed_dt
from pod_place_tag_tb;
for i in v_st_dt.first .. v_st_dt.count loop
if nvl(v_st_dt(i),chr(0)) < nvl(p_START_DATE,chr(0)) or nvl(v_st_dt.last,chr(0)) < nvl
(p_START_DATE,chr(0)) then
dbms_output.put_line('START_DATES are' ||' ' ||v_st_dt(i));
dbms_output.put_line('INSERTION IS ALLOWED');
else
dbms_output.put_line('INSERTION NOT ALLOWED');
end if;
end loop;
最后一次开始_date没有得到比较,即使我正在通过正确的p_START_DATE,也无法进行o / p插入
答案 0 :(得分:0)
我认为这在根本上是错误的...你不能在varchar2类型上比较期望结果作为日期,因为varchar2以其他方式命令。
例如
select to_char(sysdate+level,'dd-mon-yyyy') dates from dual connect by level<=100 order by dates;
结果
01-aug-2014
01-jul-2014
01-jun-2014
01-sep-2014
02-aug-2014
02-jul-2014
02-jun-2014
03-aug-2014
03-jul-2014
03-jun-2014
04-aug-2014
04-jul-2014
04-jun-2014
...
select trunc(sysdate)+level dates from dual connect by level<=100 order by dates ASC
result
2014/05/25/
2014/05/26/
2014/05/27/
2014/05/28/
...
检查anonimos块
declare
v_date1 date;
v_date2 date;
v_check_date boolean;
v_char_date1 varchar2(200);
v_char_date2 varchar2(200);
v_check_char_date boolean;
v_start_date date:=to_date('01.01.2014','dd.mm.yyyy');
v_count pls_integer:=0;
begin
for i IN 1 .. 300
LOOP
v_char_date1:=to_char(v_start_date+i,'dd-mon-yyyy');
v_date1 :=v_start_date+i;
for i1 IN 1..300
LOOP
v_char_date2:=to_char(v_start_date+i1,'dd-mon-yyyy');
v_date2 :=v_start_date+i1;
IF v_date1<v_date2 THEN
v_check_date:=true;
ELSIF v_date1>v_date2 THEN
v_check_date:=false;
END IF;
IF v_char_date1<v_char_date2 THEN
v_check_char_date:=true;
ELSIF v_char_date1>v_char_date2 THEN
v_check_char_date:=false;
END IF;
IF (v_check_char_date AND not v_check_date) THEN
dbms_output.put_line ('v_date1='||v_date1||' > '||'v_date2='||v_date2||' AND '||'v_char_date1='||v_char_date1||' < '||'v_char_date2='||v_char_date2);
exit;
ELSIF (not v_check_char_date AND v_check_date) THEN
dbms_output.put_line ('v_date1='||v_date1||' < '||'v_date2='||v_date2||' AND '||'v_char_date1='||v_char_date1||' > '||'v_char_date2='||v_char_date2);
exit;
END IF;
v_count:=v_count+1;
END LOOP;
IF (v_check_char_date AND not v_check_date) OR (not v_check_char_date AND v_check_date) THEN
exit;
END IF;
END LOOP;
dbms_output.put_line ('count='||v_count);
end;