Using trunc in oracle
I get this error message saying literal does not match format string every time i type in the simple query below
select trunc(t1.transaction_date) from table_done t1
where trunc(t1.transaction_date, 'YYYY-MM-DD') < '2006-01-01'
and trunc(t1.transaction_date, 'YYYY-MM-DD')>= '2006-12-31';
Kindly note, the main reason, I am doing a trunc is because the date in the table contains hours and mins and I only want to get the years, month and day as string charater for a particular range. Thank you.
I am still new to oracle. thank you
Is t1.transaction_date already a DATE data type? If so all you need to do is apply the TRUNC() function with only the column as the argument which will remove the hour, minute and second components. It looks like some of your post got cut off so I'll guess at what it should be.
SELECT TRUNC(t1.transaction_date)
FROM table_done t1
WHERE trunc(t1.transaction_date) BETWEEN TO_DATE('2006-01-01','YYYY-MM-DD') AND TO_DATE('2006-12-31','YYYY-MM-DD')Additionally you shouldn't compare dates to strings as you have done. Always convert the strings to DATEs if you want to compare dates.
If t1.transaction_date isn't a DATE (always store DATEs as DATEs not strings!) then you'll need to apply the TO_DATE() function.
Similar Messages
-
Sir,
As you know we were using TRUNC function in DATE datatype. But I want to use it with TIMESTAMP datatypes. For example:
select trunc(systimestamp,'hh24:mi:ss') from dual;
The main idea to get some part of given timestamp without using type conversions (i.e. TO_CHAR).
Note that this is useful when you want to ADD or Subtract the time side from timestamp with interval values and comparing them to another timestamps fields or values.
Thank you in advance.Trunc is not working in 9i
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
2 FROM dual
3 /
SELECT current_timestamp - TRUNC (current_timestamp) time
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP
SQL>
But in 10g...
Personal Oracle Database 10g Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
2 FROM dual;
TIME
+000000000 14:53:04.941000
SQL>
Why? -
Error while using P2V in Oracle VM 2.2 version
Error while using P2V in Oracle VM 2.2 version
I tried using this option by using the steps given on one link but it didnt worked...
Error:
code 404, message No permission to list directory.
I ve tried giving full permissions on for /OVS on Server but invain.
Can U pls help me...
Thanks in advance.
Edited by: user10310678 on Sep 16, 2009 3:32 AMuser10310678 wrote:
I am using beta version. Oracle VM Manager 2.2.0If you have a beta version of 2.2, then you should be an Oracle employee. Please ask this question on an internal mailing list. If you are not an Oracle employee, please ask the employee that gave you this beta. As this is a beta, some functionality may not be operational yet, so I can't answer why this particular feature seems not to work. -
Query on using Variables in Oracle Query
Hi
i am new to Oracle, i have tried extracting data from the Oracle Database using the following Query which includes 1 variable SYSDATE_UTS, however when i try to execute the Query i get an error. Please let me know what am i doing wrong and how can i correct it.
Error Message
ORA-06550: line 4, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
Oracle Query
DECLARE SYSDATE_UTS NUMBER := (sysdate-to_date('19700101','yyyymmdd'))*86400;
BEGIN
SELECT
INCIDENT_NUMBER,
to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME,
,GROUP_TRANSFERS
,LAST_MODIFIED_BY
,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
,CASE
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
ELSE 'UNKNOWN'
END AS AGE_GROUP
FROM IncidentDataBase
and STATUS not in (4,5,6)
and rownum <10;
END;Hi Frank
i am using the following Oracle Version
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
and Quest Toad for Oracle to write and execute the queries:
Toad for Oracle Xpert
Version 10.1.1.8
The code i am using is:
variable SYSDATE_UTS NUMBER;
exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
SELECT
INCIDENT_NUMBER,
to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME
,GROUP_TRANSFERS
,LAST_MODIFIED_BY
,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
,CASE
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
ELSE 'UNKNOWN'
END AS AGE_GROUP
FROM IncidentDataBase
WHERE STATUS not in (4,5,6)
and rownum <10;
Notes:
1. When i put the cursor before "variable" (starting of the query) and execute the script i get an Error: ORA-00900: invalid SQL statement.
2. When i put the cursor just before "SELECT" i get a pop up.
a. it is a Toad window which displays the available variables (in this case :SYSDATE_UTS).
b. gives me a dropdown option to select the type (by default VARCHAR2 is selected).
c. there is a value field where i need to enter the value for the Variable.
d. the SQL statement shown in this dilog box does not include the 1st 2 lines
variable SYSDATE_UTS NUMBER;
exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
Q: is there something wrong in the syntax i am using?
Sven W. - I have been using your method all these days, which works just fine. i wanted to know how i could use a variable instead.
Business Requirement - My whole intent is to calculate the Age of an incident (Difference between "Reported Date" and current date) and to assign Age Groups (0-1 Days, 2-4 Days,....,20+ Days).
Edited by: 921713 on Mar 19, 2012 12:23 PM -
Can we use Trunc,Substr in Excel templates
Hi All,
I have a date xml tag with value like "2012/04/01 00:00:00" i need to show this in excel output as "01-APR-2012".
I am using Excel template, need your help to achieve the same.
I tired to use Trunc,Substr,Format date but nothing is working.
Please give me your valuable inputs to solve this issue.
Thanks
RajehsVarma,
Thanks for the reply, i have already checked the link but it doesn't have syntax to use Trunc,substr etc. functions.
Also date in example is - "1996-02-03T00:00:00.000-07:00" , but in my case date format is different "2012/01/01 00:00:00".
Thanks
Rajesh -
Can we use different Databases (Oracle & SQL Server) in one report?
Post Author: venki5star
CA Forum: .NET
Hi there.
Can we use different databases (Oracle & SQL Server) in a same report?
If possible how?
Another question,
Can we change the Provider Name at runtime of the given report. If so the above question is useless...
Thanks in Advance.I tried this using Oracle Provider for OLEDB (the one that supplied by Oracle Client) and Crystal Reports 9. you can drag the column into designer but the image does not appear in preview.
I guess it's because CR does not recognized it as image, and there are no information that the blob data is an image at all. -
Using Coherence and Oracle Database as the CacheStore
We are working on implementing a solution using Coherence and Oracle Database as the CacheStore. We initially implemented the Cache as a distributed-scheme which in turn uses the backing-map-scheme. We are trying to introduce transaction management and I used a scheme-ref in a transactional-scheme to point to an already existing distributed-scheme. However when I bring up the server, my custom coherence-cache-config.xml file is not recognized and Coherence comes up with the default setting. Given below is the snippet of my configuration file.
1) I would like to understand why the below configuration doesn’t work and am I doing it the right way? If not, what is the correct way of doing it?
2) There are a multiple transaction management options given in the documentation. Which are the ones that will work with a distributed-scheme and read-write-backing-map-scheme?
3) If transactional-schemes cannot work with distributed-scheme, what is the best way to have a distributed cache with a oracle database as a cache store?
<caching-scheme-mapping>
<cache-mapping>
<cache-name>id<cache-name>
<scheme-name>example-transactional<scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<transactional-scheme>
<scheme-name>example-transactional</scheme-name>
<scheme-ref>distributedcustomcache</scheme-ref>
<thread-count>10</thread-count>
</transactional-scheme>
<distributed-scheme>
<scheme-name>distributedcustomcache</scheme-name>
<service-name>DistributedCache</service-name>
<backing-map-scheme>
<read-write-backing-map-scheme>
<internal-cache-scheme>
<local-scheme>
<!--scheme-ref>categories-eviction</scheme-ref-->
<scheme-name>inMemory</scheme-name>
</local-scheme>
</internal-cache-scheme>
<cachestore-scheme>
<class-scheme>
<class-name>spring-bean:coherenceCacheStore</class-name>
<init-params>
<init-param>
<param-name>setEntityName</param-name>
<param-value>{cache-name}</param-value>
</init-param>
</init-params>
</class-scheme>
</cachestore-scheme>
<!--refresh-ahead-factor>0.5</refresh-ahead-factor-->
</read-write-backing-map-scheme>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>Hi,
If you look at the documentation for transactional-scheme here: http://docs.oracle.com/cd/E24290_01/coh.371/e22837/appendix_cacheconfig.htm#BHCIABHA
you will see that it says The transactional-scheme element defines a transactional cache, which is a specialized distributed cache. That means that a transactional-scheme is already a distributed-scheme.
You will see from the same documentation above that there is no way in a transactional-scheme to configure things like cache-stores or listeners or even the backing-map-scheme as these are not supported on a transactional-scheme - so you cannot use a cache store.
Personally I would not use transactional-scheme unless you have some really big reason to do so - the restrictions far outweigh any perceived advantage of having a transaction. There are better ways to build applications so they do not require transactions, that is what we have been doing for years with Coherence so far, and there is no real reason to change that.
JK -
How to find out the Non Partitioned Tables used 2Gb on oracle
Hi team
how to find out the Non Partitioned Tables used > 2Gb on oracle where not is sys & system
regardsheres 1 I made earlier
set pagesize 999
set linesize 132
col owner format a25
col segment_name format a60
select owner,segment_name,segment_type,(bytes/1024/1024)"MB size"
from dba_segments
where owner not in ('SYS','SYSTEM','XDB','MDSYS','SYSMAN') -- edit for taste
and segment_type = 'TABLE'
having (bytes/1024/1024) > 2000
group by bytes, segment_Type, segment_name, owner
order by 4 asc -
How to copy file to another server from database using FTP in oracle
How to copy file to another server from database using FTP in oracle.
Please do the needfaul.Billy Verreynne wrote:
BluShadow wrote:
Not to mention that some FTP servers can return more than one return message per operation whereas others may return one message for the same operation.I had the problem using the LIST command to determine if a file exists on the server. Cannot be determined via the FTP server's return code. Which means parsing and checking the text response from the server to the command. And this vary from server to server.
But the basics were quite easy to code. The entire package is 500 lines, includes comments and blank lines for formatting, and supports the basic FTP client command set. Not really a complex piece of software to write - but I found that many developers seem to think that writing network socket software is complex. Not really the case...Mine's a big larger, but incorporates functionality similar to what Chris provided in his, such as being able to use SQL to query a remote file using pipelined functions, or functionality to write the results of a query directly to a remove file.
:) -
Hello
I'm working with Oracle Forms 6i and I need to check if a certain folder exists before I make an action, I think there's no way to do it with Oracle Forms only, so I tough doing it with vba.
Is there some controller that allow me to use vba in Oracle Forms? Or maybe I can do this another way.
ThanksYou can use this piece of code to check if a directory exists:
declare
l_hostcommand varchar2(1000);
l_dir varchar2(200) := 'f:\oracle';
begin
l_hostcommand := 'cmd /c if not exist '||l_dir||' exit 100';
host(l_hostcommand, no_screen);
if form_success then
message('Directory found');
else
message('Directory not found');
end if;
end; If you have no drive mapping, just use UNC (\\server\oracle). -
Error when trying to use LogMiner with Oracle 8.1.6.0.0
Hi everybody,
I'm trying to use LogMiner with Oracle 8.1.6.0.0. When I execute the following code with SQL*Plus, I have an error.
BEGIN
DBMS_LOGMNR.START_LOGMNR
(options =>
dbms_logmnr.dict_from_online_catalog);
END;
The error displayed by SQL*Plus is:
PLS-00302: 'DICT_FROM_ONLINE_CATALOG' must be declared.
Please, how to solve this problem?
Thanks you in advance for your answers.user639304 wrote:
Hi everybody,
I'm trying to use LogMiner with Oracle 8.1.6.0.0. When I execute the following code with SQL*Plus, I have an error.
BEGIN
DBMS_LOGMNR.START_LOGMNR
(options =>
dbms_logmnr.dict_from_online_catalog);
END;
The error displayed by SQL*Plus is:
PLS-00302: 'DICT_FROM_ONLINE_CATALOG' must be declared.
Please, how to solve this problem?
Thanks you in advance for your answers.Looking at the 8.1.7 doc set (the oldest available on tahiti) I get no hits when searching for 'dict_from_online_catalog'. Searching the 9.2 doc set turns up a reference. Looks like you are trying to use an option that isn't available in your version of Oracle. -
Hi,
I am using java and oracle and I want to know the way to achieve the "user-defined variables" functionality of mysql
[http://dev.mysql.com/doc/refman/4.1/en/user-variables.html]
Basically I want my update query/PL-SQL block to first define a variable and then refer it multiple times in the query.I also want to return the number of updated rows to my application code in java
I saw DEFINE variable,bind variables etc,but dont know what exactly should I use
Thanks in advance
AnanthI am looking to use the variables in the query
itself.
Ex: select @t1:=100,@t2:=@t1+10 from tbl_name where
col_name > @t1 and col_name < @t2
[This is a simple ex.I want to use current timestamp
instead of 100 as first variable's value]
Also,as I have mentioned,I need to use these in
update statements also and return the no. of updated
rows to java codeUse Declare on the beginning of a PL/SQL block to declare variable names and types. Then just use them in the code (including update statements) without any prefix (@ is not needed in oracle). As a clear difference from MySQL, you don't need to use select to set a variable value if it does not depend on a query, just use the := operator. To read values from a query into variables, use "select ... into" syntax.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm#LNPLS01345
gojko adzic
http://gojko.net -
Having problem in using RUN_PRODUCT in oracle apps 11.0.3
I am having problem in using RUN_PRODUCT in oracle apps 11.0.3. Error in oracle apps is
FRM-40733 PL/SQL built-in RUN_PRODUCT failed
What could be the possible cause for this error ?Hi again;
I found this please also check this:
Price List Migration from 11.0.3 to 11.5.10/R12.
Regard
Helios -
How to use css in oracle forms
Hello, I am using oracle forms 11g with weblogic server 10.3.5 at windows 7.I have to use CSS in oracle forms.i have tried to search it but no profit.please some one else tell me that how can use css in oracle forms. Thnak You regards aaditya
Hi
As Francois pointed out Oracle forms has nothing to do with html based technology. The way you can get the equivalent effect of creating consistancy in the way your objects are displayed is by creating a set of items you want and alter their apperance and behaviour and place them into object libraries (one library should do the trick). From there you subclass all of you forms items off these libraries.
Regards
Quintin -
Using Tuxedo with Oracle Real Application Clusters (RAC)
Hi all ,
Our present Producation environment is Tuxedo8.0 with Oracle 9i as database .
We are planning to implement oracle RAC .
Can any one tell us , with the current tuxedo version which is 8.0 ,can we for RAC Or we need to upgrade Tuxedo to 9.1 for RAC Implementation?
If anyone has Implemented Tuxedo and Oracle with RAC successfully
Pls share your experience.
Thanks In Adavance
Nadeer .Subbu,
As I mentioned earlier in this thread, support for Oracle RAC has been
implemented in Tuxedo 9.1 and in the Tuxedo 8.1 and Tuxedo 9.0 rolling patch
streams. There are no plans to backport this feature to Tuxedo 8.0. If you
plan to use RAC transactionally and if it is possible for multiple services
that could be located on different RAC instances to be accessed in a single
transaction (which will be true for most applications), then you should
upgrade to a version of Tuxedo with support for Oracle RAC. The
documentation at http://e-docs.bea.com/tuxedo/tux91/ads/adorac.htm#248431
gives an overview of RAC support in Tuxedo.
Ed
<Subramonian Arumugom> wrote in message news:[email protected]..
Hello Nadeer, Hello Ed,
Has the implementation of Tuxedo8.0 with Oracle RAC was completed
successfully ?.
If it is done , I have few doubts. Could you please help me ?.
1) I hope your Tuxedo middleware connects to the oracle Database using
Oracle XA resource manager and the TMS server built using buildtms with
oracle as RM .As per the mail from Ed, migration of Tuxedo9.1 should be done
before moving to Oracle RAC.
Also from BEA documentation, Oracle RAC support was given as new feature in
Tuxedo9.1.
Our Application uses Oracle RM to connect to Oracle DB[ Oracle 10g] from
Tuxedo8.0. So do we need to upgrade to Tuxedo9.1. for using Oracle RAC ?.
Thanks for your help
Best Regards
Subbu
#9880278452
Edited by subramonian.a at 04/16/2007 12:15 AM
Edited by subramonian.a at 04/16/2007 12:19 AM
Edited by subramonian.a at 04/16/2007 1:37 AM
Edited by subramonian.a at 04/16/2007 8:20 AM
Maybe you are looking for
-
purchased adobe 10 and 7 -- 2012 and 2013 -- trying to install on new computer. old one crashed. shows i need serial number. where do i get it. only have 6 discs.
-
Hi all. @I'm new here , just updated my iPad 2 to iOS 8.1.2 and PE app has stopped reading my streamed photos. Anyone has the same problem? thanks.
-
Occi problem about object cache!
Hello! I have a table named "ggg" which include two column in the oracle database,and the datatype of one colume is "mdsys.sdo_geometry".I insert 1000000 rows record into the "ggg" table.Now I want to download all the data with occi.At the client,i u
-
Hi Guys, I am trying to deploy the .jar file for an EJB as a part of adapter module ejb deployment and i am getting the following error have an ejb file in .jar and when i try to deploy it using sdm i am getting the following error. any body has the
-
App prototype--How to do on-click depression?
I'm using Keynote '09 version 5.3 on Mountain Lion 10.8.2 I have been trying to do a " button on-click highlight" for an app prototype. By "on-click" I mean when I click the button it's state changes from an inactive to a clicked/depressed state. Usi