首页 文章

查看本月未付的账单

提问于
浏览
0

我的目标是查看SEP / 2012月份尚未支付的账单

create view Viewe as
  select companyname,salutation,firstname,lastname, billingadd, billing.latestatus
  from CUSTOMER, CUST_NONRES, BILLING
  where cust_nonres.customerid = billing.custid
  and to_date(to_char(billingdate, 'MON-YYYY')) = to_date('092012', 'MON-YYYY')
  and PAID = 'NO';

当我从viewe中选择*时,这是我的错误

ORA-01858:找到一个非数字字符,其中数字是预期的01858. 00000 - “找到一个非数字字符,其中数字是预期的”*原因:使用日期格式模型转换的输入数据是不正确 . 输入数据不包含格式模型需要数字的数字 . *操作:修复输入数据或日期格式模型,以确保元素的数量和类型匹配 . 然后重试该操作 .

谢谢你的帮助 .


我把它改成了:

create view Viewe as
select companyname,salutation,firstname,lastname, billingadd, billingdate, billing.latestatus, amount
from CUSTOMER, CUST_NONRES, BILLING
where cust_nonres.customerid = billing.custid
and customer.customerid = cust_nonres.customerid
and TRUNC(billingdate, 'MM') = to_date('092012', 'MMYYYY')
and PAID = 'NO';

---------------------------更新

嗨,伙计们,任何人都可以帮助我,我怎么可能总结一下,我可以使用什么语法来汇总生成的条目 . 谢谢 .

1 回答

  • 1

    试试这个吧

    create view Viewe as
    select companyname,salutation,firstname,lastname, billingadd, billing.latestatus
    from CUSTOMER, CUST_NONRES, BILLING
    where cust_nonres.customerid = billing.custid
    and TRUNC(billingdate, 'MM') = to_date('092012', 'MMYYYY')
    and PAID = 'NO';
    

    这将解决日期错误消息的问题 .

    其背后的逻辑是 TRUNC 函数将日期(因此名称)截断为指定的字段 . 它可能比转换为字符串然后更新要快得多 .

    However 你会得到不好的结果!你有 3 表,只有 1 表达式指定它们之间的连接!这将给你非常奇怪的结果(由未指定的链接引起的笛卡尔积产生的重复) . 我还建议使用 JOIN ON 语法,因为它更具可读性(无论如何优化器都会处理它):

    create view Viewe as
    select companyname,salutation,firstname,lastname, billingadd, billing.latestatus
    from CUSTOMER
    JOIN CUST_NONRES ON cust_nonres.customerid = customer.customerid --this is just a guess
    JOIN BILLING ON cust_nonres.customerid = billing.custid
    where 
    and TRUNC(billing.billingdate, 'MM') = to_date('092012', 'MMYYYY')
    and PAID = 'NO';
    

    由于我以这种方式编写查询,因此我永远不会忘记添加正确的表达式来连接表,而使用WHERE子句连接表我偶尔犯了一个错误 - 有时确实需要时间来找到错误 .

    另外,请记住,如果你做了很多这样的连接,你应该考虑使用Oracle function based indexes,就像这样:

    CREATE INDEX IDX_BILLINGDATE_TRUNC_MM ON BILLING(TRUNC(BILLINGDATE,'MM'));
    

    因为这将显着提高连接性能 .

    此外,根据手头数据的数量,您可能会阅读partitioning .

    推荐阅读

相关问题