How to insert data from text file where date column has date as "00-00-0000" - sqlplus

I have a text file and it contains one column as "NPA_DATE", in which few rows contain date as "00-00-000".
I am unable to load data where date is in "00-00-0000" format. I am getting the error as "Record 1: Rejected - Error on table MIS_PNPA, column NPA_DATE. ORA-01847: day of month must be between 1 and last day of month". However I want to load the data with NPA_DATE as "00-00-0000" along with other data. All other rows are getting uploaded in database. I use toad for oracle 9.0.1.8

You should add the SQLPlus tag to your original post as this is really a SQLPlus question.
Anyway alter your control file to this to set the date to NULL if it comes in as '00-00-0000' in the data file:
...
npa_date date "DD-MM-YYYY" NULLIF (npa_date="00-00-0000")
...

Related

How can I filter my data down to a given Year or Month in a PSQL v13 Database

I get a syntax error in PSQL Control Center on an Actian 13 database when using Date_Part and I'm out of ideas on how to proceed.
There are two fields in the table I am querying 'Date' and 'CreateDate'. I get the same error when I involve either field. I have tried both 'month' and 'year' and have confirmed the field in the database is a Date field.
I have tried the following with no luck.
select date_part('month',CreateDate) from gl_trx3 where CreateDate = '2021-10-13'
I am using this specific date for example because there are records with that date saved.
The error message I get is below.
[LNA][PSQL][SQL Engine]Error in expression: date_part('month',CreateDate)
Anyone know what I am missing?
In the list of Time and Date Functions for Pervasive SQL13 the function date_part does not exist.
Using MONTH(dateexp) returns the month as an integer in the range of 1 to 12.

Save only time in rails

I have two time fields in the table i.e. start_time and end_time .
When I execute MyModel.save(start_time: '12:34'), it gets saved with appending a date(Sat, 01 Jan 2000 07:25:00 UTC +00:00).
I want to save time only. I am using Rails5
When we execute, a = MyModel.save(start_time: '12:34'), it saves only time in the database. But when we display the value in the console(a.start_time), we gets time with date. So we have to retrieve time from it by the following:
a.start_time.strftime("%H:%M")
Data gets correctly saved in the database
Rails will always append date with time even its type is "time".
You can achieve storing only time using sql query.
But i would suggest you to use one of the following options:
1)store time in column of type fixnum or decimal in 24hrs format like "22.44"
2) Store number of seconds in column of type integer & then write a helper method to confirm it into time.
3)Use column type :time and ignore the date whole querying.

My Time Field in my DBGrid is showing the date and time instead of time only - delphi

I have a field in my database called 'Times', it's a date/time format and its format is set to 'short time'. In my database the date does not show, nor is it being add to the database as I know. It is only the time value. My DBGrid shows the time field with the time value and the date '12/30/1899'. How do I get rid of the date in my time field.
Here is the code I used to submit to the database.
Get time value:
bookingtimes:= timeof(dttime.Time);
Submit to Database:
tblbooking.FieldByName('Times').AsDateTime:=bookingtimes;
Example of DBGrid 'Times' column output:
12/30/1899 7:02:01AM
If I understand what you mean this will work for you, just follow this steps:
This is your issue:
Double click on your table, and select Times field:
After you click on your field, go to the Object Inspector and find DisplayFormat property:
Write the format, in your case hh:mm:ss:
Now let's see the result:
That's it.

issue to query data filtered by Date from fusion table

I'm trying to write a small javascript code to query data filtered by date.
If I write the following sentence in my browser, I can get data :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883"
but if I write the same thing, except I want only data after a certain date :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883 WHERE Date > 2/29/12"
From the SQL-like API, https://developers.google.com/fusiontables/docs/developers_reference#Select, it should work
I get an error witch is "'internal_error', message:'Could not parse query'"
-Date is a DATETIME format in my fusion table.
-I've tried different format, but I can not get data.
What am I doing wrong?
Thank you very much for your help.
The Date value must be quoted and the format is MM/dd/yy so you must pad single digits with leading zeros.
I had success with:
select Date,Poids from 3049883 where Date >= '02/29/12'
Note: I did not test with gvizdata, just with the FT JSONP API

ruby/rails - Converting Entire Database Field (from string to date)

I have made a huge mistake.
Initially I created my model with a field called start_date and made it a string to keep track of event dates.
Now I'm realizing it would be nice to have this field as a date type so I could do calculations like find events where start_date is between today and 1 month from now.
This issue is I already have 500 records so starting over would suck....
The format of the start_date field is in a rails compatible type " 2011-02-21 22:00:00 " but its just a string...
Is there anything I can do?
Create a migration to add a start_date_2 column of the type you want
Model.find(:all).each { |i| i.update_attributes(:start_date_2, Date.new(i.start_date)) }
Create a migration to delete start_date and to rename start_date_2 to start_date
This should work, out of the top of my head.
You could try just doing an EXPORT on the table (making sure to only export data, do not include CREATE and/or DROP table commands).
Create a migration to change the datatype
TRUNCATE the table
IMPORT the data
Since the column is now a date field, it should parse the input of a string just fine, considering that's what you provide it anyway
Perhaps, you can do away with the risk of changing column type if there is live data. The parse methods can save you. From Ruby-doc:
parse(str='-4712-01-01', comp=true, sg=ITALY)
Create a new Date object by parsing from a String, without specifying the format.
str is a String holding a date representation. comp specifies whether to interpret 2-digit years as 19XX (>= 69) or 20XX (< 69); the default is not to. The method will attempt to parse a date from the String using various heuristics; see _parse in date/format.rb for more details. If parsing fails, an ArgumentError will be raised.
Here and here are some more examples / explanations. Hope this helps.

Resources