|
-
May 19th, 2010, 05:45 AM
#1
[RESOLVED] Date Parameter in OracleParamater
Hi all,
I am using this SQL statement to fetch data from oracle
Code:
str = "select * from Master where CreatedDttm = TO_DATE(:p_StartDate,'MM/DD/YYYY')"
and passing the date to oracle parameter as
Code:
oParameter.ParameterName = "p_StartDate"
oParameter.Value = "01/01/2009"
oParameter.OracleType = OracleType.DateTime
oParameterList(0) = oParameter
And executing this command I getting error that
Invalid varriable name or number ?
What I am doing wrong here ?
I did the steps mentioned in post. But the same error
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 06:16 AM
#2
Re: Date Parameter in OracleParamater
This also produces the same error...
Code:
str = "select * from Master where CreatedDttm = :startDate"
oParameter.ParameterName = "p_StartDate"
oParameter.OracleType = OracleType.DateTime
oParameter.Value = DateTime.ParseExact("01/01/2009", "MM/dd/yyyy", CultureInfo.InvariantCulture)
oParameterList(0) = oParameter
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 06:30 AM
#3
Re: Date Parameter in OracleParamater
Without DateConversion it is working...
Code:
str = "select * from Master where CreatedDttm > :p_StartDate"
But I need to format it as MM/DD/YYYY hh:mm:ss AM
Last edited by danasegarane; May 19th, 2010 at 06:34 AM.
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 06:33 AM
#4
Re: Date Parameter in OracleParamater
What happens if you substitute @ instead of :
Code:
str = "select * from Master where CreatedDttm = TO_DATE(@p_StartDate,'MM/DD/YYYY')"
-
May 19th, 2010, 06:39 AM
#5
Re: Date Parameter in OracleParamater
 Originally Posted by Pradeep1210
What happens if you substitute @ instead of :
Code:
str = "select * from Master where CreatedDttm = TO_DATE(@p_StartDate,'MM/DD/YYYY')"
I am getting the same Error "Illegal Varriable/Number "
Code:
str = "select * from vehicleMaster where CreatedDttm =TO_DATE(@p_StartDate,'MM/DD/YYYY')"
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 06:51 AM
#6
Re: Date Parameter in OracleParamater
I think you would need to use the conversion in the SELECT list, since you are already passing a date value in the WHERE clause anyways.
Code:
str = "select *, TO_DATE(CreatedDttm, 'MM/DD/YYYY') from Master where CreatedDttm = :p_StartDate"
-
May 19th, 2010, 06:57 AM
#7
Re: Date Parameter in OracleParamater
I have the User Enter the date in format dd/MM/yyyy and I need to convert, before matching with the table.
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 07:58 AM
#8
Re: Date Parameter in OracleParamater
Your CreatedDttm is a date column, and you can't alter how it is stored internally. A date column is a date column for the database, irrespective of how it got it. Since you want the output in dd/MM/yyyy format, you would specify it in the SELECT list.
Since you have already specified that the parameter you are passing is of date type (oParameter.OracleType = OracleType.DateTime), that should be sufficient.
-
May 19th, 2010, 08:03 AM
#9
Re: Date Parameter in OracleParamater
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
May 19th, 2010, 08:57 AM
#10
Re: Date Parameter in OracleParamater
 Originally Posted by danasegarane
Without DateConversion it is working...
Code:
str = "select * from Master where CreatedDttm > :p_StartDate"
But I need to format it as MM/DD/YYYY hh:mm:ss AM
You should be able to use it with the timestamp. I tried something very similar using ODP.NET.
C# Code:
OracleConnection oConn;
OracleCommand oCmd;
OracleParameter oPrm;
string strSQL = "SELECT lease_no, lease_create_date, creation_date, customer_name," +
"lease_status FROM lease_header WHERE "+
"lease_create_date > :p_startdate";
try
{
oConn = new OracleConnection();
oConn.ConnectionString = "Data Source=mydb;User Id=abhijit;Password=xfiles;";
oConn.Open();
Console.WriteLine(oConn.State);
oCmd = new OracleCommand();
oCmd.CommandText = strSQL;
oCmd.CommandType = System.Data.CommandType.Text;
oCmd.Connection = oConn;
oPrm = oCmd.CreateParameter();
oPrm.ParameterName ="p_startdate";
oPrm.OracleDbType = OracleDbType.Date;
oPrm.Value = DateTime.Parse("4/9/2010 10:17:17 AM");
oCmd.Parameters.Add(oPrm);
Console.WriteLine(oCmd.CommandText);
using (OracleDataReader reader = oCmd.ExecuteReader())
{
// Always call Read before accessing data.
while (reader.Read())
{
Console.WriteLine("{0}:{1}:{2}:{3}", reader[0], reader[1], reader[2], reader[3]);
}
}
oConn.Dispose();
}
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
May 19th, 2010, 09:40 AM
#11
Re: Date Parameter in OracleParamater
 Originally Posted by abhijit
You should be able to use it with the timestamp. I tried something very similar using ODP.NET.
C# Code:
OracleConnection oConn;
OracleCommand oCmd;
OracleParameter oPrm;
string strSQL = "SELECT lease_no, lease_create_date, creation_date, customer_name," +
"lease_status FROM lease_header WHERE "+
"lease_create_date > :p_startdate";
try
{
oConn = new OracleConnection();
oConn.ConnectionString = "Data Source=mydb;User Id=abhijit;Password=xfiles;";
oConn.Open();
Console.WriteLine(oConn.State);
oCmd = new OracleCommand();
oCmd.CommandText = strSQL;
oCmd.CommandType = System.Data.CommandType.Text;
oCmd.Connection = oConn;
oPrm = oCmd.CreateParameter();
oPrm.ParameterName ="p_startdate";
oPrm.OracleDbType = OracleDbType.Date;
oPrm.Value = DateTime.Parse("4/9/2010 10:17:17 AM");
oCmd.Parameters.Add(oPrm);
Console.WriteLine(oCmd.CommandText);
using (OracleDataReader reader = oCmd.ExecuteReader())
{
// Always call Read before accessing data.
while (reader.Read())
{
Console.WriteLine("{0}:{1}:{2}:{3}", reader[0], reader[1], reader[2], reader[3]);
}
}
oConn.Dispose();
}
I tried the TimeStamp Column . But It was not working. I change the type to Varchar. And it worke
Code:
'
str = "select * from vehicleMaster where CreatedDttm > TO_DATE(:p_StartDate,'MM/DD/YYYY HH24:Mi:SS')"
oParameter.ParameterName = "p_StartDate"
oParameter.OracleType = OracleType.VarChar
oParameter.Value = "01/01/2009"
oParameterList(0) = oParameter
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 09:45 AM
#12
Re: [RESOLVED] Date Parameter in OracleParamater
What happens if you change to Date instead of a varchar?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
May 19th, 2010, 10:00 AM
#13
Re: [RESOLVED] Date Parameter in OracleParamater
 Originally Posted by abhijit
What happens if you change to Date instead of a varchar?
I am getting the same Error "Illegal Varriable/Number "
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 10:32 AM
#14
Re: [RESOLVED] Date Parameter in OracleParamater
 Originally Posted by abhijit
What happens if you change to Date instead of a varchar?
 Originally Posted by danasegarane
I am getting the same Error "Illegal Varriable/Number "
You would need to get rid of the TO_DATE function in your Oracle query.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
May 19th, 2010, 10:38 AM
#15
Re: [RESOLVED] Date Parameter in OracleParamater
 Originally Posted by abhijit
You would need to get rid of the TO_DATE function in your Oracle query.
No I cannot . I need to format the data as 24 hr format and check
Please mark you thread resolved using the Thread Tools as shown
-
May 19th, 2010, 10:49 AM
#16
Re: [RESOLVED] Date Parameter in OracleParamater
 Originally Posted by danasegarane
No I cannot . I need to format the data as 24 hr format and check 
Agreed. What I am saying is that if you get rid of the TO_DATE and use the parameter type OracleDbDate to assign a date value with a timestamp, it will work.
That's an alternative solution. I tried that out here and it works correctly.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
May 19th, 2010, 10:57 AM
#17
Re: [RESOLVED] Date Parameter in OracleParamater
That I have tried in Post Number #3
Please mark you thread resolved using the Thread Tools as shown
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|