Home » SQL & PL/SQL » SQL & PL/SQL » Set a range into in time (Forms,)
|
|
|
Re: Set a range into in time [message #652378 is a reply to message #652327] |
Tue, 07 June 2016 23:34 |
|
Salehin
Messages: 62 Registered: March 2013 Location: Chittagong, Bangladesh
|
Member |
|
|
Thank's Michel
I tried this code but it only select, not updated. how can I update my in_time? sorry I am just learning coding.
INSERT INTO AD.IN_TIME to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS') from dual;
SELECT AD.EMPNO, AD.OUT_TIME, AD.IN_TIME
FROM ATTENDANCE_DETAILS AD
WHERE AD.OUT_TIME IS NOT NULL
and ad.in_time is null
AND AD.ATT_DATE= TO_DATE ('13-06-2015', 'dd-MM-yyyy');
I also tried this code
SQL> UPDATE ATTENDANCE_DETAILS AD
2 SET AD.IN_TIME to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS') fr
om dual
3 where AD.ATT_DATE= TO_DATE ('13-06-15', 'dd-MM-yy')
4 AND AD.OUT_TIME IS NOT NULL
5 and ad.in_time is null;
SET AD.IN_TIME to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS') from du
*
ERROR at line 2:
ORA-00927: missing equal sign
[Updated on: Tue, 07 June 2016 23:46] Report message to a moderator
|
|
|
|
Re: Set a range into in time [message #652386 is a reply to message #652378] |
Wed, 08 June 2016 01:00 |
|
Barbara Boehmer
Messages: 9090 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
Salehin wrote on Tue, 07 June 2016 21:34
SQL> UPDATE ATTENDANCE_DETAILS AD
2 SET AD.IN_TIME to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS') fr
om dual
3 where AD.ATT_DATE= TO_DATE ('13-06-15', 'dd-MM-yy')
4 AND AD.OUT_TIME IS NOT NULL
5 and ad.in_time is null;
SET AD.IN_TIME to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS') from du
*
ERROR at line 2:
ORA-00927: missing equal sign
This tells you that you are missing an equal sign (=) on line 2:
ERROR at line 2:
ORA-00927: missing equal sign
This is line 2 that is missing the = sign:
SET AD.IN_TIME to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS') fr
om dual
The proper syntax for an update statement is:
UPDATE ...
SET ... = ...
So, you need to put the = sign where it belongs in line 2:
SET AD.IN_TIME = ...
That will fix that error, then you will have to figure out what causes the next error and so on.
You should probably be truncating the ad.in_time, not sysdate, which was just used as an example and you don't need from dual, which was also just part of the example to show how to generate the date and time, not how to update.
Filling in a random time sounds like a strange business requirement.
|
|
|
|
Re: Set a range into in time [message #652388 is a reply to message #652386] |
Wed, 08 June 2016 01:13 |
|
Salehin
Messages: 62 Registered: March 2013 Location: Chittagong, Bangladesh
|
Member |
|
|
Thank's
I tired this code
SQL> UPDATE ATTENDANCE_DETAILS AD
2 SET AD.IN_TIME = to_char(trunc(AD.IN_TIME)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS'
)
3 where AD.ATT_DATE= TO_DATE ('13-06-15', 'dd-MM-yy')
4 AND AD.OUT_TIME IS NOT NULL
5 and ad.in_time is null;
132 rows updated.
But I don't find any update.
thank's Michel I tried your one
SQL> UPDATE ATTENDANCE_DETAILS AD
2 SET AD.IN_TIME = to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS')
3 where AD.ATT_DATE= TO_DATE ('13-06-15', 'dd-MM-yy')
4 AND AD.OUT_TIME IS NOT NULL
5 and ad.in_time is null;
SET AD.IN_TIME = to_char(trunc(sysdate)+dbms_random.value(28200,29400)/86400,'HH24:MI:SS')
*
ERROR at line 2:
ORA-01843: not a valid month
[Updated on: Wed, 08 June 2016 01:15] Report message to a moderator
|
|
|
|
Re: Set a range into in time [message #652394 is a reply to message #652389] |
Wed, 08 June 2016 01:32 |
|
Salehin
Messages: 62 Registered: March 2013 Location: Chittagong, Bangladesh
|
Member |
|
|
EMPNO IN_TIME OUT_TIME
-------------------- --------- ---------
00032157 01-JUN-15
00033379 13-JUN-15
00033405 13-JUN-15
00001609 13-JUN-15
00001677 13-JUN-15
00001694 13-JUN-15
00001699 13-JUN-15
00001701 13-JUN-15
00001719 13-JUN-15
00001726 14-JUN-15
00001731 13-JUN-15
EMPNO IN_TIME OUT_TIME
-------------------- --------- ---------
00004473 13-JUN-15
00075713 13-JUN-15
00073194 14-JUN-15
00062509 14-JUN-15
00062521 13-JUN-15
00062587 14-JUN-15
00050899 14-JUN-15
00051909 14-JUN-15
00047087 14-JUN-15
00038722 14-JUN-15
00037360 13-JUN-15
132 rows selected.
not updated. here I see may be some problem in date. It show 13-JUN-15, 14-JUN-15
[Updated on: Wed, 08 June 2016 01:37] Report message to a moderator
|
|
|
|
|
Re: Set a range into in time [message #652401 is a reply to message #652397] |
Wed, 08 June 2016 03:53 |
|
Salehin
Messages: 62 Registered: March 2013 Location: Chittagong, Bangladesh
|
Member |
|
|
Wow!! Its working, but I want to set late='00:00:00' and trying to to this syntex
SQL> UPDATE attendance_details ad
2 SET ad.in_time2= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400),
3 ad.in_time= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400), ad.status='P', ad.st
atus2='P', ad.late=to_char('00:00:00','HH24:MI:SS')
4 WHERE ad.att_date = TO_DATE ('13-06-2015', 'dd-MM-yyyy')
5 AND ad.out_time IS NOT NULL
6 AND ad.in_time2 IS NULL;
ad.in_time= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400), ad.status='P', ad.status2
ERROR at line 3:
ORA-01722: invalid number
|
|
|
|
Re: Set a range into in time [message #652407 is a reply to message #652401] |
Wed, 08 June 2016 05:00 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Salehin wrote on Wed, 08 June 2016 10:53Wow!! Its working, but I want to set late='00:00:00' and trying to to this syntex
Based on your first post, the column LATE has data type NUMBER.
'00:00:00' is a string literal. It is not a number. Or is it meant to be a simple zero (0)? Then, why not use it directly?
Maybe you should realize the difference between storing data (NUMBER) and their presentation (which may be done by Forms in any format, e.g. 01:02:03 for 3723).
Additionally, you really should get acquainted with the functions which you use.
Some nice guys from Oracle already did that job of documenting them and their output is available e.g. online on http://docs.oracle.com/en/.
For the version 12c, the function TO_CHAR has three implementations:
http://docs.oracle.com/database/121/SQLRF/functions215.htm#SQLRF06128 for string parameter (note that there are no other parameters)
http://docs.oracle.com/database/121/SQLRF/functions216.htm#SQLRF06129 for date parameter (with conditional format parameter)
http://docs.oracle.com/database/121/SQLRF/functions217.htm#SQLRF06130 for numeric parameter (with conditional format parameter)
So, you pass it a string and a format parameter. You may be calling the one with the first date or numeric parameter; regarding the message, Oracle chooses the latter conversion, so you do this:
to_char(TO_NUMBER('00:00:00'),'HH24:MI:SS')
which fails as '00:00:00' is not a NUMBER.
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Set a range into in time [message #653748 is a reply to message #653747] |
Mon, 18 July 2016 03:19 |
|
Salehin
Messages: 62 Registered: March 2013 Location: Chittagong, Bangladesh
|
Member |
|
|
UPDATE attendance_details ad
SET ad.in_time2= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400),
ad.in_time= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400),
ad.status='P',ad.status2='P', ad.late=0, ad.late2=0
WHERE ad.att_date = TO_DATE ('16-07-2016', 'dd-MM-yyyy')
AND ad.out_time IS NOT NULL
AND ad.in_time2 IS NULL;
In my office I have two shift i.e day shift, Night shift and they have code for day 'SH105' and night 'SH108' but this column is in emp_official table. Now how can I add this shift code to my syntex.
thank's in advance.
|
|
|
|
Re: Set a range into in time [message #653758 is a reply to message #653753] |
Mon, 18 July 2016 05:48 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
salehin,
What is the difference between in_time2 and in_time. I don't know if your aware but two calls to DBMS_RANDOM will produce 2 different values (see below). Also what links emp_official to the attendance_details table? The task is easy to do, just need some more information.
test>select DBMS_RANDOM.VALUE (28200,29400),DBMS_RANDOM.VALUE (28200,29400) from dual;
DBMS_RANDOM.VALUE(28200,29400) DBMS_RANDOM.VALUE(28200,29400)
------------------------------ ------------------------------
28612.4758 28668.7093
[Updated on: Mon, 18 July 2016 05:48] Report message to a moderator
|
|
|
|
|
Re: Set a range into in time [message #653838 is a reply to message #653833] |
Wed, 20 July 2016 01:54 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Have you considered consulting the documentation (available under the links I provided earlier) about UPDATE statement and all its possibilities?
So, for the last time, I will navigate you directly to the UPDATE statement for 12c: http://docs.oracle.com/database/121/SQLRF/statements_10008.htm#SQLRF01708
(by the way, I cannot find whether you posted the Oracle version you use; I used the latest one anyway)
It seems like you want to use correlated subquery in the SET clause. There are also SQL examples on the bottom of that page.
Unfortunately, people here can work only with known objects - tables with known structure (columns including type) and sample data for illustrating the requirements.
You provided only table name which is quite useless, do you not think?
|
|
|
Re: Set a range into in time [message #653948 is a reply to message #653838] |
Sat, 23 July 2016 06:35 |
|
Salehin
Messages: 62 Registered: March 2013 Location: Chittagong, Bangladesh
|
Member |
|
|
SQL> UPDATE attendance_details ad
2 SET ad.in_time2= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400),
3 ad.in_time= TRUNC (ad.att_date) + (DBMS_RANDOM.VALUE (28200,29400)/86400),
4 ad.status='P',ad.status2='P', ad.late=0, ad.late2=0
5 WHERE empno IN
6 (select eo.empno
7 from emp_official eo
8 where eo.shift_code='SH105'
9 and ad.att_date = TO_DATE ('09-01-2016', 'dd-MM-yyyy')
10 AND ad.out_time IS NOT NULL
11 AND ad.in_time2 IS NULL)
12 /
110 rows updated.
Thank you everybody finally I done it.
Bless for me
|
|
|
|
Goto Forum:
Current Time: Thu Apr 25 02:01:30 CDT 2024
|