Solved

How do I get the difference between a TIMESTAMP and a NUMBER?

Posted on 2007-12-01
2
1,308 Views
Last Modified: 2013-12-18
I am working on a Hospital database.  The variable 'RMS' represents the charge per day for staying in a hospital room.  I need to repeat the 'RMS' charge for each date till 04/09/2007.  How do I get the difference between 04/09/2007 and Charge_Date?

create table PATIENT_CHARGES(
Patient_ID                  NUMBER NOT NULL,
Charge_Code          VARCHAR2(3),
Charge_Date              TIMESTAMP,
Charge_Value             NUMBER,
constraint PATIENT_CHARGES_PK primary key (Patient_ID, Charge_Code, Charge_Date),
constraint PC_PATIENT_ID_FK foreign key (Patient_ID)
references PATIENT_ADMISSION (Patient_ID),
constraint CHARGE_CODE_FK foreign key (Charge_Code)
references CHARGE_CODE (Charge_Code)
);


insert into PATIENT_CHARGES
values (SEQ_PATIENT_ADMISSION_PK.CurrVal, 'RMS', '02-APR-07', '750');

insert into PATIENT_CHARGES
values (SEQ_PATIENT_ADMISSION_PK.CurrVal, 'PRD', '04-APR-07', '350');

insert into PATIENT_CHARGES
values (SEQ_PATIENT_ADMISSION_PK.CurrVal, 'EKG', '08-APR-07', '650');


I have tried the following and I get these errors:

update PATIENT_CHARGES set Charge_Value = '04/09/2007' - to_date(Charge_Date) * Charge_Value
where Charge_Code = 'RMS';

update PATIENT_CHARGES set Charge_Value = '04/09/2007' - to_date(Charge_Date) * Charge_Value
                                                                                                     *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE


update PATIENT_CHARGES set Charge_Value = (to_date('04/09/2007','mm/dd/yyyy'))
- Charge_Date * Charge_Value
where Charge_Code = 'RMS';

- Charge_Date * Charge_Value
  *
ERROR at line 2:
ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP


update PATIENT_CHARGES set Charge_Value = cast(to_date('04/09/2007','mm/dd/yyyy'))
- Charge_Date * Charge_Value
where Charge_Code = 'RMS';

update PATIENT_CHARGES set Charge_Value = cast(to_date('04/09/2007','mm/dd/yyyy'))
                                                                                                                                              *
ERROR at line 1:
ORA-00905: missing keyword
0
Comment
Question by:CharleneS77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
mohammadzahid earned 500 total points
ID: 20390174
update PATIENT_CHARGES set Charge_Value = (to_Date('04092007','mmddyyyy') - to_Date(to_char(charge_date,'mmddyyyy'),'mmddyyyy'))  * Charge_Value
where Charge_Code = 'RMS';
0
 

Author Closing Comment

by:CharleneS77
ID: 31412160
Perfect.  Thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question