How to run this query to get the minutes between two hours?
Hi all,
Hope doing well,
sir i am running one query which is:
v_TotalHrsMin1 := LPAD((extract(minute from TO_TIMESTAMP (v_Temphrs,'HH24:mi:ss')) - extract(minute from TO_TIMESTAMP (v_Outtime1,'HH24:mi:ss'))), 2, '0');--select to_date(v_temphrs,'YYYY-MM-DD HH:mi:ss')-to_date(v_OutPunch,'YYYY-MM-DD HH:mi:ss')*1440;
in this v_TotalHrsMin1 is number datatype and v_Temphrs is varchar2 which is storing this value: 12:00:00
and v_Outtime1 is varchar2 which is storing 06:00:00
now i want the minute difference between both times
and insert into v_Totalmin1.
but getting null value in v_totalmin1.
thanks
952646 wrote:
Hi Sir,
i used query like this: v_TotalHrsMin1 := extract(hour from time_interval) * 60 + extract(minute from time_interval) from (select to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS') time_interval from dual);That is not a query - that is a PL/SQL assignment expression. You should learn the differences between SQL and PL/SQL and how they work together ;-)
When doing it in PL/SQL, you do not need a query at all. Why would you do a select from dual in the PL/SQL assignment.
But you should be able to take the SQL example I gave you and write the equivalent PL/SQL code.
We do not want to do your work for you - we want to teach you how to do it yourself.
You should try and understand the examples we give you - not just cut-and-paste it and cry for help when you are cut-and-pasting a SQL example into PL/SQL code.
Anyway - here's a way to do it in PL/SQL:
declare
v_outtime1 varchar2(8);
v_temphrs varchar2(8);
v_interval interval day to second;
v_totalhrsmin1 number;
begin
v_outtime1 := '06:00:00';
v_temphrs := '12:00:00';
v_interval := to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS');
v_totalhrsmin1 := extract(hour from v_interval) * 60 + extract(minute from v_interval);
end;
/What's so difficult about taking my SQL example, understanding what the differenct functions do, and then write that piece of PL/SQL? ;-)
Similar Messages
-
How to modify this query to get the desired output format
I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
FROM ALL_CONS_COLUMNS
WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
FROM ALL_CONSTRAINTS AC
WHERE AC.TABLE_NAME=TABLE_NAME
AND AC.TABLE_NAME='&TABLE'
AND AC.R_CONSTRAINT_NAME IS NOT NULL);
This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
For Example I want the output as follows...
TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
EMP DEPTNO DEPT DEPTNO
In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
any help on how to tackle would be appreciated.Try this query
SELECT c.table_name child_table,
c.column_name child_column,
p.table_name parent_table,
p.column_name parent_column
FROM user_constraints a,user_constraints b,user_cons_columns c,
user_cons_columns p
WHERE a.r_constraint_name=b.constraint_name and
a.constraint_name=c.constraint_name and
b.constraint_name=p.constraint_name and
c.position=p.position
ORDER BY c.constraint_name,c.position
Anwar -
I have a database table where it keeps record of the transaction when it starts at StartTime and when it ends at EndTime. Both these entries are having the timestamp entries. Say for example, I have a tuple with Entries like 'Transaction A' starts at '2014-05-07
20:55:03.170' and ends at '2014-05-08 08:56:03.170'. I need to find the difference between these two timestamps and my expected output is 12:01:00.000. Let me know how to achieve this ?Hi,
You can use below script which calculates difference as DD:HH:MM:SS. You can modify the same:
DECLARE @startTime DATETIME
DECLARE @endTime DATETIME
SET @startTime = '2013-11-05 12:20:35'
SET @endTime = '2013-11-10 01:22:30'
SELECT [DD:HH:MM:SS] =
CAST((DATEDIFF(HOUR, @startTime, @endTime) / 24) AS VARCHAR)
+ ':' +
CAST((DATEDIFF(HOUR, @startTime, @endTime) % 24) AS VARCHAR)
+ ':' +
CASE WHEN DATEPART(SECOND, @endTime) >= DATEPART(SECOND, @startTime)
THEN CAST((DATEDIFF(MINUTE, @startTime, @endTime) % 60) AS VARCHAR)
ELSE
CAST((DATEDIFF(MINUTE, DATEADD(MINUTE, -1, @endTime), @endTime) % 60)
AS VARCHAR)
END
+ ':' + CAST((DATEDIFF(SECOND, @startTime, @endTime) % 60) AS VARCHAR),
[StringFormat] =
CAST((DATEDIFF(HOUR , @startTime, @endTime) / 24) AS VARCHAR) +
' Days ' +
CAST((DATEDIFF(HOUR , @startTime, @endTime) % 24) AS VARCHAR) +
' Hours ' +
CASE WHEN DATEPART(SECOND, @endTime) >= DATEPART(SECOND, @startTime)
THEN CAST((DATEDIFF(MINUTE, @startTime, @endTime) % 60) AS VARCHAR)
ELSE
CAST((DATEDIFF(MINUTE, DATEADD(MINUTE, -1, @endTime), @endTime) % 60)
AS VARCHAR)
END +
' Minutes ' +
CAST((DATEDIFF(SECOND, @startTime, @endTime) % 60) AS VARCHAR) +
' Seconds '
Reference:
http://sqlandme.com/2013/12/23/sql-server-calculating-elapsed-time-from-datetime/
- Vishal
SqlAndMe.com -
I am looking for only column compare for making my target table same as source table.
My query:
select case when column_name_s is null and column_name_t is not null
then 'alter table GRADE_CONVERSION drop ' || column_name_t || ';'
when column_name_s is not null and column_name_t is null
then 'alter table GRADE_CONVERSION add ' || column_name_s || ' ' || data_type_s ||';'
else 'alter table GRADE_CONVERSION modify ' || column_name_t || ' ' || data_type_t ||';'
end alterations
from (select s.column_name column_name_s,t.column_name column_name_t,
s.data_type data_type_s,t.data_type data_type_t
from (select column_id,column_name,data_type
from all_tab_cols@database
where owner = 'erhan'
and table_name = 'GRADE_CONVERSION'
) s
full outer join
(select column_id,column_name,data_type
from all_tab_cols@database
where owner = 'sarigul'
and table_name = 'GRADE_CONVERSION'
) t
on s.column_name = t.column_name
Tables:
Target table: GRADE_CONVERSION table in sarigul@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
Source table: GRADE_CONVERSION table in erhan@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
CREATED_BY
VARCHAR2(30)
CREATED_DATE
DATE
MODIFIED_BY
VARCHAR2(30)
MODIFIED_DATE
DATE
want to see the result similar to this *(please ignore the column names here this is just a plain exemple:)
Alter table Target_table modify BOOK_ID Varchar2 (4);
Alter table Target_table add ISBN_10 Varchar2(13), null;
Alter table Target_table drop TITLE;I am looking for only column compare for making my target table same as source table.
My query:
select case when column_name_s is null and column_name_t is not null
then 'alter table GRADE_CONVERSION drop ' || column_name_t || ';'
when column_name_s is not null and column_name_t is null
then 'alter table GRADE_CONVERSION add ' || column_name_s || ' ' || data_type_s ||';'
else 'alter table GRADE_CONVERSION modify ' || column_name_t || ' ' || data_type_t ||';'
end alterations
from (select s.column_name column_name_s,t.column_name column_name_t,
s.data_type data_type_s,t.data_type data_type_t
from (select column_id,column_name,data_type
from all_tab_cols@database
where owner = 'erhan'
and table_name = 'GRADE_CONVERSION'
) s
full outer join
(select column_id,column_name,data_type
from all_tab_cols@database
where owner = 'sarigul'
and table_name = 'GRADE_CONVERSION'
) t
on s.column_name = t.column_name
Tables:
Target table: GRADE_CONVERSION table in sarigul@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
Source table: GRADE_CONVERSION table in erhan@database
LETTER_GRADE
VARCHAR2(2)
GRADE_POINT
NUMBER(3,2)
MAX_GRADE
NUMBER(3)
MIN_GRADE
NUMBER(3)
CREATED_BY
VARCHAR2(30)
CREATED_DATE
DATE
MODIFIED_BY
VARCHAR2(30)
MODIFIED_DATE
DATE
want to see the result similar to this *(please ignore the column names here this is just a plain exemple:)
Alter table Target_table modify BOOK_ID Varchar2 (4);
Alter table Target_table add ISBN_10 Varchar2(13), null;
Alter table Target_table drop TITLE; -
How to get the difference between two columns in a column group
Hi All,
My first time here and really new to programming. I would like to get the difference between 2 columns that are inside
a column group.
Here is my sample table below: The Column Group is PeriodNumber and can only choose 2. like 1 and 2.. I would like to have a third row which will simply calculate the difference between the amounts in PeriodNumber 1 and 2.
PeriodNumber
Account 1 2
1) Cash 10,000 15,000
2) Receivables 12,000 11,500
3) Equipment 5,000 5,500
Total Assets 27,000 32,000Hi yabgestopa,
From your description, you want to get the difference between two columns in a column group. After testing it in my environment, we can use custom code to achieve your requirement. For more details, you can refer to the following steps:
Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
Dim Shared Num1 As Integer
Dim shared Num2 As Integer
Public Function GetAmount(Amount as Integer, Type as String)
If Type = "1" Then
Num1=Amount
Else
Num2=Amount
End If
Return Amount
End Function
Public Function GetDif()
Return Num1-Num2
End function
Right-click the second column to insert a third column with Outside Group-Right.
Then use the expressions below in the matrix.
=Code.GetAmount(Fields!Amount.Value,Fields!PeriodNumber.Value)
=code.GetAmount(Sum(Fields!Amount.Value),Fields!PeriodNumber.Value)
=Code.GetDif()
The report looks like below.
If you have any questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Getting the length between two points
Hi All,
I am trying to get the distance between two points and came across the SDO_LENGTH function in the manual - however there is no example on how to use it.
I was expecting the following statement to return me the value 9 but instead I am getting errors along the lines of SDO_GEOM.SDO_LENGTH must be declared etc.
=============================================
SDO_GEOM.SD0_LENGTH(
MDSYS.SDO_GEOMETRY(2
,NULL
,NULL
,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1)
,MDSYS.SDO_ORDINATE_ARRAY(1,1,10,10))
,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.0001)
,MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.0001))
============================================
what am I missing
any help appreciated
Brent GloverI think I have found my answer
============================================
DECLARE
v_length NUMBER;
BEGIN
v_length := SDO_GEOM.SDO_LENGTH(
MDSYS.SDO_GEOMETRY(2
,NULL
,NULL
,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1)
,MDSYS.SDO_ORDINATE_ARRAY(1,1,10,10))
,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.0001)
,MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.0001))
DBMS_OUTPUT.put_line(v_length);
END;
============================================= -
Java code to get the difference between two dates in days
Hi ppl,
I need to write a user defined function to get the difference between two date nodes, in days.Please help me out
regards,
PrashanthHi,
have a look at those two:
(How do I calculate the difference between two dates?)
http://joda-time.sourceforge.net/faq.html
Calculating the Difference Between Two Datetime Stamps
http://www.xmission.com/~goodhill/dates/deltaDates.html
Get difference in days
http://javaalmanac.com/egs/java.util/CompDates.html
Regards,
michal -
Query to get the difference between 2 totals from 2 different queries
I wanted to know if it is possible to get the difference between 2 totals from 2 different queries. I would explain with an example:
1st query - Select sum(homepass) from table 1
2nd query – select sum(homepass) from table2
Is it possible to display the difference like-
Select sum(homepass) from table 1 - sum(homepass) from table2
I know the above query would gives syntax error but is there a better way or a trick to get the above task accomplished from a single query.
I hope, my question is clear.
Please revert with the reply to my query.
Regardstomernitin wrote:
Try this one also:
WITH adtn1
AS
SELECT 110 val1 FROM dual UNION ALL
SELECT 100 FROM dual UNION ALL
SELECT 90 FROM dual UNION ALL
SELECT 10 FROM dual
adtn2
AS
SELECT 10 val2 FROM dual UNION ALL
SELECT 20 FROM dual UNION ALL
SELECT 30 FROM dual UNION ALL
SELECT 100 FROM dual
SELECT(Sum(a1.val1)-Sum(a2.val2)) Diff FROM adtn1 a1,adtn2 a2;
let me know if you still have any doubt.
Um.... I don't think so. Not with the cartesian join between a1 and 2. -
How to get the difference between two date
Hello,
I want to know how to write a code the tell me the difference between two date, I am using
oracle.jbo.domain.Date
i have a rent date and return date so my code is
Date rent=(Date)nr.getAttrbute("RentDate"),ret=(Date)nr.getAttrbute("ReturnDate");
is there a way to know the difference in days between those two dates ?
Thankshi,
try this.....
DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
Date date = (Date)formatter.parse(dateStr); //// dateStr <- from date value (that is string value)
Date dateto = (Date)formatter.parse(datetostr); //// datetostr <- to date value (to date getting from as a string)
Calendar cal = Calendar.getInstance();
cal.setTime(date);
Calendar calto = Calendar.getInstance();
calto.setTime(dateto);
fromDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR);
toDate = calto.get(Calendar.DATE) + "/" + (calto.get(Calendar.MONTH) + 1) + "/" + calto.get(Calendar.YEAR);
// System.out.println("from Date : " + fromDate);
if ((fromDate != null && toDate != null) && (date.compareTo(dateto) > -1) ) {
fc.addMessage("VacationQueryComponent", new FacesMessage(FacesMessage.SEVERITY_ERROR, "From Date cannot be lower than To Date", "From Date cannot be lower than To Date"));
fc.renderResponse();
thks. -
How to get the data between two dates?
Hi all,
I am facing a problem of getting the data betwwen two dates.
I have written a query as
"select * from table1 a where a.dt between trunc(sysdate) and trunc(sysdate)-30"
It is not showing any errors or warnings.But the data is not coming though the data is in the table1 between these two dates.
Regards,
KumarYour ordering is probably wrong:
SELECT *
FROM table1 a
WHERE a.dt BETWEEN TRUNC (SYSDATE) - 30 AND TRUNC (SYSDATE) -
How to get the difference between two HashMaps
i have two HashMaps
HashMap first = new HashMap<Integer,Object>();
HashMap second = new HashMap<Integer,Object>();
How to get the difference between one and two and put the result in the third
HashMap third = new HashMap<Integer,Object>();My bad, difference of course means removeAll():Map<Integer,Object> first = new HashMap<Integer,Object>();
Map<Integer,Object> second = new HashMap<Integer,Object>();
Map<Integer,Object> third = new HashMap<Integer, Object>(first);
third.keySet().removeAll(second.keySet());No loops needed. -
Trying to Get the "Difference" Between Two Tracks
What I am trying to accomplish is this: I have an audio track of a voiceover with a music bed beneath it. I also have the bed music by itsself, without the voiceover. I want only the voice portion. Is there a way that I can "cancel out" the music portion or get the difference between the two tracks (just the voice portion)? It seems that there should be some means of doing this, but for the life of me I cannot figure out how to do it!
Any advice?If it's exactly the same music track, then as long as you line it up sample-accurate and the levels co-incide, you can do a simple subtractive process. You need both files available, trimmed to length. Open them both in Edit View, and copy one of them to the clipboard. Open the other, and select Mix-paste, and use the 'invert' option. That will effectively subtract one from the other, with the difference being your vocal.
Have to tell you though that the chances of getting this spot on are amazingly low... any errors at all leave you with bleed-through, about which you can do nothing. -
Need to get the difference between two period
Hi All,
I need to get the difference of two posting period like period is in format YYYYMM.
I need to subtract posting perid '200512' FROM '200601' how will be it possible.
Please suggest.
Thanks,
SandyHi,
YOu can also do like the following.
Determine you first day of first period and last day of second period.
data: first_day type datum,
last_day type datum,
days type i.
first_day = date from FM RKE_GET_FIRST_DAY_IN_PERIOD
last_day = date from FM RKE_GET_LAST_DAY_IN_PERIOD
days = last_day-first_day.
Thanks,
Ramakrishna -
Function Module to get the difference between two times.
Hi All,
I want to know if there is any function module that gives me the difference between two specified times.
For Ex: Time 1: 12/01/2007 00:01 A.M
Time 2: Time 1 - 180 Seconds. This changes the time, also may even change the Date. (As in above situation, the Time 2 will be 11/30/2007 11:58 P.M)
Could some one please suggest if there is any function module for this case.
Thanks in Advance.Hi, You can use the following function module to calculate the diffrence between to dates in the unit that you want.
COPF_DETERMINE_DURATION calculates the difference between two dates and time in minutes and hours.
Parameters:
EXPORTING
I_START_DATE "The start date of the time interval
I_START_TIME "The start time of the time interval
I_END_DATE "The end date of the time interval
I_END_TIME "The end time of the time interval
I_UNIT_OF_DURATION "Time unit of the duration if not to be calculated in days.
Value ===== Meaning
' ' ===== Day (default)
D ===== Days
H ===== Hours
MIN ===== Minutes
MON ===== Months
S ===== Seconds
WK ===== Weeks
YR ===== Years
I_FACTORY_CALENDER "A factory calender if not using the Gregorian calender
IMPORTING
E_DURATION "Time difference in unit specified.
Message was edited by:
Rajesh Soman -
Need help - how to run this particular method in the main method?
Hi all,
I have a problem with methods that involves objects such as:
public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
For example this code:
import java.util.Scanner;
interface Animal {
void soundOff();
class Elephant implements Animal {
public void soundOff() {
System.out.println("Trumpet");
class Lion implements Animal {
public void soundOff() {
System.out.println("Roar");
class TestAnimal {
public static void main(String[] args) {
TestAnimal ta = new TestAnimal();
ta.get(); // error
// doing Animal a = new Animal() is horrible... :(
public static Animal get(String choice) {
Scanner myScanner = new Scanner(System.in);
choice = myScanner.nextLine();
if (choice.equalsIgnoreCase("meat eater")) {
return new Lion();
} else {
return new Elephant();
}Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
Thank you.Hi paulcw,
Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
refactored:
import java.util.Scanner;
interface Animal {
void soundOff();
class Elephant implements Animal {
public void soundOff() {
System.out.println("Trumpet");
class Lion implements Animal {
public void soundOff() {
System.out.println("Roar");
class TestAnimal {
public static void main(String[] args) {
Animal a = get();
public static Animal get() {
Scanner myScanner = new Scanner(System.in);
System.out.println("Meat eater or not?");
String choice = myScanner.nextLine();
if (choice.equalsIgnoreCase("meat eater")) {
return new Lion();
} else {
return new Elephant();
}The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..
Maybe you are looking for
-
How to send long voice memos?
Hello I have long voice memos (up to 35 minutes), I want them on my Mac, but the problem is that it only allows 2 minutes to be sent via email. Is there any other ways I can transfer them to my Mac? Thanks
-
HT203175 I Tunes wont open.
Error message states, ITunes has encountered a problem and needs to close. Error signature = AppName: itunes.exe, AppVer 11.0.1.12, ModName: corefoundation.dlll ModVer: 1.630.18.0 Offset: 0005e550. Was working fine previously any help much appreciate
-
URGENT HELP-Connecting 2 Switches
Hi All, I need to connect 2 switches (2960 & 2960S) with only one single link in our LAN network. This is to get extra number of ports. Requesting your help with the followings: Please confirm if straight throug cable will work to connect between the
-
Using an N95 and SIP without a SIM card
Hello All, I recently upgraded to a N95 (S/W V20.0.016). As soon as I got the phone I configured it to use SIP through my home wireless point to my asterisk server. All worked well with the phone auto-connecting to my wireless network, registering wi
-
Zen Micro defect with Firmware upd
(Zen Micro version 2.00.2) I updated my Zen Micro's firmware/drivers/applications the other day and now the player is not detected by creative media source organizer or zen micro media explorer - I have to transfer my songs through Real Player or WMP