Avatar of Lawrence Avery
Lawrence AveryFlag for United States of America

asked on 

Using SQL*PLUS issue with where statement with trunc function

In running the following I receive no rows selected but if I take the where clause off I receive a row.
In the tool called sql developer , I run the same sql statement the where clause works.
Why? Is it because the trunc function is not valid?

sqlplus -s 1234/1234<<END
spool farmerList.csv replace
select service_date, open_qty, closed_qty, cancelled_qty, open_closed_canc_qty
 from dashboard_servticket_dispstats where trunc(service_date) = trunc(sysdate -1);
spool off;
exit;
END
Oracle DatabaseSQL

Avatar of undefined
Last Comment
Lawrence Avery
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sean Stuber
Sean Stuber

If you have an index on service_date,  you might not want to use trunc on the column, instead, provide a date range that allows the index to be used.
This would be for performance only.  This is the same functionality as what you had but more efficient

SELECT service_date,
       open_qty,
       closed_qty,
       cancelled_qty,
       open_closed_canc_qty
  FROM dashboard_servticket_dispstats
 WHERE service_date >= TRUNC(SYSDATE - 1) AND service_date < TRUNC(sydate)
Avatar of Lawrence Avery

ASKER

I did forget to commit in sql developer. Thanks
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo