Using DECODE() to insert to DATE field
I'm trying to use the DECODE function to test for NULL before inserting to a DATE field. However, it seems to only insert the DATE, with a "default" time of 12:00 - it isn't properly inserting the time.
Basically I need to test if Date1 is NULL. If it isn't I need to concatenate the DATE from Date1 with the TIME from Date2 to get a full date/time... then insert this new value.
Generic Example:
CREATE TABLE DATETEST (TestID NUMBER(1), TestDate DATE);
DECLARE
v_Date1 DATE;
v_Date2 DATE;
BEGIN
v_Date1 := TO_DATE('01-JAN-11 05:53:12', 'DD-MON-YY HH:MI:SS');
v_Date2 := TO_DATE('08-FEB-11 02:18:31', 'DD-MON-YY HH:MI:SS');
INSERT INTO DATETEST (TestID, TestDate) VALUES ('1', DECODE(v_Date1, NULL, NULL, TO_DATE(To_Char(v_Date1, 'DD-MON-YY') || ' ' || TO_CHAR(v_Date2, 'HH:MI:SS'),'DD-MON-YY HH:MI:SS')));
INSERT INTO DATETEST (TestID, TestDate) VALUES ('2', TO_DATE(To_Char(v_Date1, 'DD-MON-YY') || ' ' || TO_CHAR(v_Date2, 'HH:MI:SS'),'DD-MON-YY HH:MI:SS'));
END;
SELECT TestID, TO_CHAR(TestDate, 'DD-MON-YY HH:MI:SS') from DATETEST;
This example performs two inserts. One with the DECODE function, and one without. The one without inserts the time properly. Can anyone tell me why the one with the DECODE function doesn't? I realize I can use a simple if/then to check if the date is null above and put the date/time in a variable, but since my real scenario is in a large chunk of other stuff, I'm trying to keep it as streamlined as possible.
Edited by: BoredBillJ on Jul 14, 2011 6:39 AM
The problem you are having is due to the nature of how DECODE and CASE determine what datatype to return, and you nls_date_format settings. Both use the data type of the first returnable argument to determine all of them. So, in your decode statement, the first returnable value is NULL which, in the absence of a cast (either implicit or explicit), is a varchar2 column. So, if the date is not null, the implicit conversion to a varchar to match the retunr type, then back to date to insert into the table is losing the time. you need something more like:
INSERT INTO test_date (Test_ID, TestDate)
VALUES ('1', DECODE(v_Date1, NULL, TO_DATE(NULL),
TO_DATE(To_Char(v_Date1, 'DD-MON-YY') || ' ' ||
TO_CHAR(v_Date2, 'HH:MI:SS'),'DD-MON-YY HH:MI:SS')));Even if you use Solomon's method of generating the date, if you need the decode/case, then you will have to either use the TO_DATE(NULL) or use case instead of decode and reverse the test so the first returnable is a date like:
SQL> DECLARE
2 v_Date1 DATE;
3 v_Date2 DATE;
4 BEGIN
5 v_Date1 := TO_DATE('01-JAN-11 05:53:12', 'DD-MON-YY HH:MI:SS');
6 v_Date2 := TO_DATE('08-FEB-11 02:18:31', 'DD-MON-YY HH:MI:SS');
7 INSERT INTO test_date (Test_ID, TestDate)
8 VALUES ('1', CASE WHEN v_date1 IS NOT NULL
9 THEN TO_DATE(To_Char(v_Date1, 'DD-MON-YY') || ' ' ||
10 TO_CHAR(v_Date2, 'HH:MI:SS'),'DD-MON-YY HH:MI:SS')
11 ELSE NULL END);
12 INSERT INTO test_date (Test_ID, TestDate)
13 VALUES ('2', TO_DATE(To_Char(v_Date1, 'DD-MON-YY') || ' ' ||
14 TO_CHAR(v_Date2, 'HH:MI:SS'),'DD-MON-YY HH:MI:SS'));
15 END;
16 /
PL/SQL procedure successfully completed.
SQL> select test_id, to_char(testdate, 'dd-mon-yyyy hh24:mi:ss')
2 from test_date;
TEST_ID TO_CHAR(TESTDATE,'DD
1 01-jan-2011 02:18:31
2 01-jan-2011 02:18:31John
Similar Messages
-
How do i insert a drop down calender to insert the date field.
How do i insert a drop down calender to insert the date field i my create a form
Hi,
You can use the date object FormsCentral provides. When you test the form in browser, the date field will show a pulldown calendar when clicked upon.
Thanks,
Wenlan -
Acrobat x pro crashes when I try to flatten a pdf after using typewriter to insert a date
acrobat x pro crashes when I try to flatten a pdf after using typewriter to insert a date.
Has anybody else seen this problem? Is there a fix?
I wanted to download the demo of acrobat XI but it says the previous version will be removed and deactivate the license. That sucks!Yes it is up to date.
I can use the stamp tool and flatten it after with no problems, but the typewriter tool crashes it upon attempting to flatten. -
Use of revision no,revision date field in bom header details screen
Hi all,
Please let me know use of revision no,revision date field(customer fields tab) in bom header details screen.I tried with F1 ,no information.
Thanks
SukumarDear,
In standard SAP in BOM header overview there are 4 tabs.
Quants/Long text.
Further Data
Admin Data
Doc Assignment.
I think Customer fields tab may be customized based on client's requirement.
I Know about revision level. It Identifies the change status of a material.
The revision level can be uniquely assigned to changes made using a change number.
Hope this helps. Correct me if i my understanding of the problem is wrong.
Thanks and Regds
Sridhara K N -
How to filter a table using column filter on a date field with time?
Hi,
I have a date field where I am inserting a date+time value, for example: 01/01/2012 09:30:00 So, I would like to filter an adf table using a column inputdate filter to filter only by date this field.
I was testing using formats but with no luck.
Any Idea?
Thanks,
jdev 11.1.2.3
Edited by: jhon.carrillo on Oct 29, 2012 12:23 AMThen, try to add another attribute in your SELECT VO statement, which truncates the original date_and_time field:
SELECT.... TRUNC(DATE_AND_TIME) as truncated_dateAfter that, put reference to that attribute in the filter facet, as follows
<f:facet name="filter">
<af:inputDate value="#{vs.filterCriteria.TruncatedDate}" id=.../>
</facet>Do not forget to add the TruncatedDate attribute in the <tree...> binding in the pageDef, along with others VO attributes. Do that manually. -
How do i insert a date field?
I download a date field widget but i can't seem to make it work. Any suggestions?
How exactly have you downloaded the file ? You can import the library file and then use on pages or if you have downloaded the widget from CC addon then first sync with CC in assets section and then use in Muse.
Thanks,
Sanjit -
Using a Converter on a date field
Hi all. I’m having a problem using a converter in JSF. I’m pulling a lot of information from a database and throwing it all on a page. I’ve set up a custom converter for all my values that are of a String type. This converter basically says “if there is something in this variable, put it on the page, otherwise, put ‘N/A’ on the page”. The code for this converter is below:
public String getAsString(FacesContext context, UIComponent component,
Object value)
String stringValue = value.toString().trim();
return StringUtils.isNotBlank(stringValue) ? stringValue : "N/A";
...This code works. I’m having trouble doing the exact same thing for date fields. If I run it through the same converter, then it will show me the date if there is one, but if there isn’t anything in the variable, it just gives me nothing. No date, no “N/A”, nothing. I’ve seen that there is a separate converter called DateTimeConverter, but it looks like this is basically just used to format the date.
Anybody know how I can get this working?I'm still having this problem if anyone has any ideas. When I run it in debug, the value that's getting sent is "". There is a separate DateTimeConverter, but all it seems to do is format a date. I can't see a way to spit out a "N/A" if there isn't one.
-
Registering a logistic User to use a FMS on a data-field
Dear Community,
you should be able to help me out on this:
I got a couple of logistic users, who have a very restricted access to the system.
Anyway, I still need them to use some FMS on data fields like batch number creation.
Unfortunately I cannot find the correct authorization to activate the usage of Formated Searches on certain datafields.
Where can I find it??
Greetings, danielHi there,
I found the correct authorization:
(in german:)
the category "Berichtsauswahl" --> Abfragegenerator
After handing out the rights of this category the users are able to use FMS etc.
Thanks for your replies and help!
daniel -
Using DECODE Function to change data
I am trying to use the Decode function in a SQL statement to find a field that has a specific type, and when it finds that type, I want to blank out the results in a different field.
For example:
DECODE(ADDR_TYPE,'HOME',PHONE='') HOME_PHONEsomething like:
SQL> with t as
2 (select 219 id,
3 'BUS' addr_type,
4 '505-555-5555' phone
5 from dual
6 union
7 select 219 id,
8 'HOME' addr_type,
9 null phone
10 from dual
11 union
12 select 220 id,
13 'BUS' addr_type,
14 '101-111-1111' phone
15 from dual
16 union
17 select 220 id,
18 'HOME' addr_type,
19 null phone
20 from dual
21 union
22 select 223 id,
23 'BUS' addr_type,
24 '202-222-2222' phone
25 from dual
26 union
27 select 224 id,
28 'HOME' addr_type,
29 '303-333-3333' phone
30 from dual
31 union
32 select 225 id,
33 'BUS' addr_type,
34 null phone
35 from dual
36 union
37 select 226 id,
38 'HOME' addr_type,
39 null phone
40 from dual)
41 select a.id,
42 a.addr_type,
43 decode(a.addr_type,'BUS',phone,null) phone
44 from (select id, addr_type, phone,
45 row_number() over (partition by id order by id, decode(addr_type,'BUS',1,2)) rn
46 from t) a
47 where a.rn = 1;
ID ADDR PHONE
219 BUS 505-555-5555
220 BUS 101-111-1111
223 BUS 202-222-2222
224 HOME
225 BUS
226 HOME
6 rows selected.
SQL> -
How to insert/update Date field in Oracle with java code
Dear All
I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.
By using these 3 lines i am able to insert/update only date.
java.util.Date date = new java.util.Date();
long dateLong = date.getTime();
stmtPrep.setDate(33, new java.sql.Date(dateLong));
Below code retrives the date exactly what i need but unable to pass in the statement:
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a");
java.util.Date d = (Date) new java.util.Date();
String stringdate = formatter.format(d);
String tmpdate = dateFormat();
stmtPrep.setString(33, tmpdate); -- I tried with setObject as well but same error coming.
Error is:
ORA-01830: date format picture ends before converting entire input string
Can u guide me how to get full date time with AM/PM?sasikrishna wrote:
Dear All
I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.
By using these 3 lines i am able to insert/update only date.
java.util.Date date = new java.util.Date();
long dateLong = date.getTime();
stmtPrep.setDate(33, new java.sql.Date(dateLong));That's by design. A java.sql.Date object matches an SQL DATE column (which doesn't include a time component). If you want something which matches an SQL TIMESTAMP colum (which includes both date and time components) then you should use a java.sql.Timestamp object. -
Using F4-Help for a DATS-Field
I have an input field that is bound to a context attribute of type DATS and some output fields that depend on the value of the input field.
Is there any chance to throw an event when the user changes the value of the input field via F4-help (calendar help) without pressing enter afterwards?
Or is there any possibility to change the values of the output fields in another way?Hello,
I suggest you to use the [OVS Value Help|http://help.sap.com/saphelp_nw04s/helpdata/en/47/9ef8c99b5e3c5ce10000000a421937/frameset.htm].
Regards, -
BI UDI data load conflict using MS SQL Server and date fields
Hi BW Experts!
We have found some unexpected problems when we are trying to perform a data extraction process from an SQL database (non-SAP application).
We are using the BI UDI tool (JDBC Driver/Connector). The basic data extraction works properly, however we have some specific problems to work with SQL Server fields defined as Date Time.
The JDBC driver automatically intermediate the communication and translate these fields splitting the original SQL date time field into two separated fields with suffix _D (for date) and _T (for time).
It works perfect for extraction, but it doesnt work well when we try to restrict the data selection based on these fields.
When we put a date selection into the infopackage data selection area (we already have tried several date formats), the system simply ignores these selection parameters and send a SQL statement without WHERE clause to DBMS.
Please, anybody has experienced anything like this or know somethings that could help us?
This is a standard limitation from SAP BI UDI?
Thanks in advance and best regards,Hi Matt and Thomas
Many thanks for your replies.
Yes I have to do the join. Even worse I have to write an Aggregate query like this!
Select o.F1,o.F2, m.F1,m.F2, count(*)
from
table@oracleServer o,
table@microsoftSQLServer m
where o.F1=m.F1
group by o.F1,o.F2, m.F1,m.F2;
These are 2 different systems (hardware & software) which actually do the same job, they produce transactions for a common business entity. Kind of, both sell tickets for the same ABC ferry company.
I can not put them side by side on the dashboard, as I need to aggregate the data and present it maybe in a Oracle BI Report for Accounting and Financial reconciliation purposes.
The truth is, as it is. I can't change it, is too late.
I have to device a way to harvest both systems as they are. I don't want to move around data. I thought looking at Oracle BI I could write SQL against multiple Data Sources. I am struggling to find a way. As it seems that it can "SQL query" 1 data source at a time.
I have been hinted on another forum (OracleTURK) to use Oracle Transparent Gateways and Generic Connectivity. http://download.oracle.com/docs/cd/B19306_01/server.102/b14232/toc.htm
Shame, I have to pay licenses for OWB and Oracle Transparent Gateways. I thought DB vendors can do better. Why do I have to pay to access the other 50% of the market.
I can understand the performance implications this might have. Because of it I might even be forced at the end to move data (ETL) into a separate database, slice it into partitions and manage it that way. Pitty because currenlty I only need one report out of these systems but seems like will be dear to get.
Thank you for all your help.
Kubilay -
Using decode for range of data
hi experts
i want to dicode distance which are between
1 to 50
51 to 100
101 to 150
i am using this query but it is giving some error
please tell me that how should solve this problem
select a.fr_wh,a.to_wh,nvl(a.distance,0) distance,
DECODE(a.distance,(select distance from evhdist_mst where distance between 0 and 50) , 25,
(select distance from evhdist_mst where distance between 0 and 100) , 50,
100) cost,
b.rkpt_name "Source" , c.party_name "Destination"
from
evhdist_mst a,
evm_rkpt b,
evm_rkpt_wh d,
evm_party c
where
a.to_wh=c.party_cd
and a.fr_wh=d.wh_cd
and b.rkpt_cd=d.rkpt_cd
and (substr(a.TO_WH,1,6) = 'NPAM01')
AND b.rkpt_cd IN( 'NPAM0101','NPAM0102','NPAM0103')
and to_wh='NPAM01028'
thanks in advance
regards
manojThis is your formatted code.
select a.fr_wh,
a.to_wh,
nvl(a.distance,0) distance,
DECODE(a.distance,(select distance from evhdist_mst where distance between 0 and 50) , 25,
(select distance from evhdist_mst where distance between 0 and 100), 50, /*Should this be 0 to 100 or 51 to 100? */
100) cost, /* In place of this, you need to have a CASE */
b.rkpt_name "Source" ,
c.party_name "Destination"
from evhdist_mst a,
evm_rkpt b,
evm_rkpt_wh d,
evm_party c
where a.to_wh=c.party_cd
and a.fr_wh=d.wh_cd
and b.rkpt_cd=d.rkpt_cd
and (substr(a.TO_WH,1,6) = 'NPAM01')
AND b.rkpt_cd IN( 'NPAM0101','NPAM0102','NPAM0103')
and to_wh='NPAM01028'Like this
case when a.distance >= 0 and a.distance <= 50 then 25
when a.distance >= 51 and a.distance <= 100 then 50
else 100
end cost More over your scalar sub-query is not correct. It may result in more than one row and may fail during run-time.
Cheers
Sarma. -
Sorting of Date field in the SQL Query useing ORDER BY
Hi
I am facing a problem when I am getting the results of a query from the ORacle 8i database using jdbc connection.
The query is having a date field and I have to sort the query results using ORDER By for the Date field. The query is giving exact results in the SQL PLus interface.
When I am getting this results in the GUI where servlets are being used an Exception is coming as not supported RefreshRow method.
If anyone has faced this problem and have got the solutions please let me know.
thanks
sulfyThat doesn't sound at all like an SQL problem.
More like you trying to do updates on the resultset which is not allowed ...
send a some code (not to much pls :) and we'll be
able to help more
cu
Spieler -
Get the error "Make an entry" in the date field
Hallo Experts,
I have the following problem. I have a date filed with value help. In the Getter-Method, I inserted the following code to get a value help:
CALL METHOD CL_CRM_UIU_BT_DATE_TOOLS=>GET_DATE
EXPORTING
IV_ATTRIBUTE_PATH = ATTRIBUTE_PATH
IR_BTDATE = current
IR_MODEL_UTIL = me
RECEIVING
RV_VALUE = value
EXCEPTIONS
CONVERSION_ERROR = 1
* others = 2
so far is everything is ok, I can select my date in the field. But the problem is, if I select an other button without any funktion (no event) in the same viewset I get the error message: Make an entry in field "Date". By the way, the field date is a mandantoy field.
My intention is, that the entry of the date filed is still exist (without to save) if I push an other button to invoke an event.
Could anyone help me?
Best regards,
JohnHi,
You are only displaying the date in getter method. To set the date in the entity it should be done using set_property.
current->set_property( iv_attr_name = 'date field' iv_value = 'value' ).
Check whether the date is set in setter method. If not add the above code.
Regards,
Arun
Maybe you are looking for
-
Report for pending shipments, PGI and Picking
Hi All, We have few issues with the orders not being picked, if picked some are not being able to PGI and few are not going to the Shipments process. this is creating a backlog. I was wondering if we have any Report or transaction where i can check o
-
DB adapter wizard console disappears
Hi, I am facing this weird error. I configure a database adapter on my Jdeveloper. steps i follow is.. 1. Give name 2. Select the connection 3. slect Operatioion type ( Select operation) 4. select tables, 5. Create a parent child relation 7. Input pa
-
Hi Jdev Team: Since there no success to create application using JDeveloper3.2 after connecting to SQL Sever 7.0. Just wandering if there are some examples or instructions to demonstrate how to develop an application based on SQL Server or other non-
-
Java 3d into android or nokia symbian
Hi all i've done my little java3d app and i wonder if it is possible to export it to nokia symbian or android Ciao gio
-
Icons disappear in Download stack fan
When I fan out my downloads stack, the icons and file names do not appear. They appear in grid, but not fan. I have repaired permissions, restarted computer, but nothing works. How do I fix it?