简体   繁体   English

获取准确插入的date_from和date_to

[英]Get exactly inserted date_from and date_to

I am working in an application in which I need to filter policy by date. 我在一个需要按日期过滤策略的应用程序中工作。 For example if user enter date_from:'21-jul-2017' and date_to:'21-jul-2019' it should display all policies which were created in this period. 例如,如果用户输入date_from:'21-jul-2017'date_to:'21-jul-2019' ,则应显示在此期间创建的所有策略。

So far what I did: 到目前为止,我做了什么:

cursor o1 is 
 select substr(tarifa,1,2), count(*)
    from   pol p, uvod u, doppov d
    WHERE (izdavanje >=:prebacivanje.od)  AND (izdavanje<=:prebacivanje.do)
    and izdavanje>='01-jul-07'
    and p.orgjed = u.sorgz (+)
    and DATUM_PREKIDA is not null
    and p.polica=d.polica and d.pov_dopl='P'
    and d.status='F'
    and cisti_ao(p.polica)!=0 
    group by substr(tarifa,1,2);

:prebacivanje.od and :prebacivanje.do are date_from and date_to . :prebacivanje.od:prebacivanje.dodate_fromdate_to Both are DATE fields in the database. 两者都是数据库中的DATE字段。

So I need to modify this query to return inserted date_from and date_to depending of what user entered. 因此,我需要修改此查询以根据用户输入的内容返回插入的date_fromdate_to

在此处输入图片说明

As this is a cursor which exists somewhere in a form, that code should probably be executed somehow . 由于这是一个存在于表单中某处的游标,因此该代码可能应该以某种方式执行。 Is it when you push a button, or what? 按下按钮时是什么?

Anyway: although you never said what the problem is (do you get an error? If so, which one? ORA-xxxxx, FRM-xxxxx?) (my guess is that query doesn't return anything), it seems that parameters bother you. 无论如何:尽管您从未说过问题出在哪里(是否出错?如果是,是哪个错误?ORA-xxxxx,FRM-xxxxx?)(我猜是查询什么都不会返回),但似乎参数很麻烦您。

Query - as is - is correctly written. 查询-按原样-正确编写。 Those columns' datatype is DATE - that's what items' datatype should be as well. 这些列的数据类型为DATE这也应该是项目的数据类型。 If it is not (but a CHAR ), you'll have to convert it to DATE using TO_DATE , eg 如果不是(而是CHAR ),则必须使用TO_DATE将其转换为DATE ,例如

 WHERE izdavanje >= to_date(:prebacivanje.od, 'dd-mon-yy')  
   AND izdavanje <= to_date(:prebacivanje.do, 'dd-mon-yy')
   AND izdavanje >= to_date('01-jul-07'     , 'dd-mon-yy')

In order to make sure which format mask to use, display items' values at the beginning of that PL/SQL procedure, using the MESSAGE built-in: 为了确保使用哪种格式掩码,请使用内置的MESSAGE在该PL / SQL过程的开头显示项目的值:

declare
  cursor o1 is ...
begin
  message('od = ' || :prebacivanje.od);
  message('do = ' || :prebacivanje.do);

  ... the rest of your code goes here
end;

Generally speaking, your best option is to make sure that datatypes match; 一般来说,最好的选择是确保数据类型匹配。 otherwise, you have to take care about conversion or (worse) rely on implicit conversion Oracle will try to perform; 否则,您必须注意转换,否则(更糟糕)依赖于Oracle将尝试执行的隐式转换; sometimes it'll succeed, sometimes not. 有时会成功,有时却不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取 date_from 和 date_to 之间的日期集 - How to get the set of dates between date_from and date_to 在MySQL中创建date_from和date_to列 - Create date_from and date_to columns in mysql 有没有办法在新字段中显示日期范围或 date_from 和 date_to,其中 YYYYMM 作为 BM - Is there a way to show date range or date_from & date_to in a new field with YYYYMM as a BM 按ID对行进行分组,并查找带有日期间隔的最大/最小值(date_from,date_to) - Group rows by ID and find max/min(date_from, date_to) with date gaps 如何将结果表中具有相同值的连续行分组为具有 date_from 和 date_until 的组 - How to group consecutive rows with same values in a result table into groups with date_from and date_until 如何从特定日期插入的表中获取所有行。 - How to get all rows from a table inserted in a particular date. 获取插入行的日期MySQL - Get the date when the row was inserted MySQL 如何将文本框中插入的日期与MYSQL数据库中的日期进行比较 - How to compare date inserted from textbox with date from MYSQL db 如何获得从今天起的下个月日期(即)从今天起的一个月到期 - How to get Next month date from today date (i.e) exactly one month expires from today date 从日期获取“星期”日期 - Get 'Week Of' Date from Date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM