Home > database >  Oracle date fields for varchar2 type, why can directly compare
Oracle date fields for varchar2 type, why can directly compare

Time:09-26

Like this query select * from BUDGET_LOGIN_LOG where OPTTIME BETWEEN '2015-06-15' and '2015-06-16'. To get the correct result set

CodePudding user response:

String comparison sequence is comparing the first character first, and then the second, and a on
So if your field format strictly in accordance with the specific format (including digits), can use the string to compare directly

CodePudding user response:

reference 1st floor wildwave response:
string comparison sequence is comparing the first character first, and then the second, and a on
So if your field format strictly in accordance with the specific format (including digits), can use the string to directly compare

See clear title

CodePudding user response:

You also see clear what I said, if not character type, no format?

CodePudding user response:

reference wildwave reply: 3/f
you also see clear what I said, if not character type, no format?

What do you mean, as long as they are in accordance with the date format is ah

CodePudding user response:

As long as the date format is fixed, whether - dd yyyy - mm or yyyymmdd or yyyy/mm/dd
Can directly be compared

CodePudding user response:

The predicate and, of course, the parameters of the format string format correspond to those on the field

CodePudding user response:

You as long as it is in the table field VARCHAR2 type, no matter what is of value, is a character, character and character is you can compare the size, also see your description can get the correct result sets, needless to say that your table OPTTIME field remaining string must be "YYYY - MM - DD" format,

CodePudding user response:

That's your lucky oracle itself will be implicit transformation can just get better matching
Don't entanglements this problem code inside is not recommend this way

CodePudding user response:

You this kind of circumstance should be system session date format just agree with you, so can need not to_date to transform;
You check with the following statements to know,
Select * from nls_session_parameters a where Amy polumbo arameter='NLS_TIME_FORMAT';

CodePudding user response:

Because OPTTIME is varchar2 type, so, can directly compare, do not need to undertake any type conversion,
If you want to check all of 2015 data, can use the following comparison way,
OPTTIME BETWEEN '2015' and '2016'

CodePudding user response:

A type is varchar2 type, the where condition is also, so can compare

CodePudding user response:

11 references leq3915 response:
is a type varchar2 types, the where condition is also, so can compare

The fields, and mobile phone reply, wrong character

CodePudding user response:

In the final analysis is the comparison of character, when inserted into the unified time format, can compare, why not compare,

CodePudding user response:

Save your data on the specific? In addition to date, there is time? To see if there are any spare space,

CodePudding user response:

This date and it doesn't matter, you define varchar2, do you think it is a date, but the database is by definition varchar2 identify it will only string, and just the string comparison rules similar to date in accordance with the rules. Is to compare the first character, if the same, or the next, until is different.

CodePudding user response:

The string comparison in oracle and Java string comparison rule is the same, all is according to the figures one by one corresponding comparison, so under the date in a uniform format, can be normal to compare the size

CodePudding user response:

refer to the eighth floor kingkingzhu response:
that's your lucky oracle itself will be implicit transformation can just get better matching
Don't entanglements this problem inside the code is not recommend this way

Type conversion, did not actually do you define varchar2, just give it represents the significance of the date, in fact is not a date type,
As for string comparison, you have been very thorough analysis of the above,
You can use two ways to test and experience:
1, BETWEEN '2015-07-15' and '2015-6-16' and see who who big small
2, BETWEEN the date '2015-07-15' and the date '2015-6-16' to see who big small

CodePudding user response:

The top! Don't sink!

CodePudding user response:

learning

CodePudding user response:

reference 23 f jdsnhan response:
Quote: refer to the eighth floor kingkingzhu response:

That's your lucky oracle itself will be implicit transformation can just get better matching
Don't entanglements this problem inside the code is not recommend this way

Type conversion, did not actually do you define varchar2, just give it represents the significance of the date, in fact is not a date type,
As for string comparison, you have been very thorough analysis of the above,
You can use two ways to test and experience:
1, BETWEEN '2015-07-15' and '2015-6-16' and see who who big small
2, BETWEEN the date '2015-07-15' and the date '2015-6-16' to see who big small

Wrong thought OPTTIME is the date type

CodePudding user response:

The code inside is not recommend this way

CodePudding user response:

Date type, varchar, digital type is an implicit conversion

CodePudding user response:

It is or change my doctor

CodePudding user response:

String is inherently can be compared, but is a one-to-one ratio

CodePudding user response:

As a character comparison, essentially characters,

CodePudding user response:

Thanks for sharing, learning!

CodePudding user response:

Because you're format and are varchar2 types, characters, of course, you can compare,

CodePudding user response:

Strings can be compared, can a one character more size, if the date format string length is fixed is can get the desired results,

CodePudding user response:

And Java in the comparison of similar rules

CodePudding user response:

Because OPTTIME is varchar2 type, so, can directly compare, do not need to undertake any type conversion, if you want to check all of 2015 data, can use the following way of comparison, OPTTIME BETWEEN '2015' and '2016'

CodePudding user response:

String comparison sequence is comparing the first character first, and then the second, and a on
So if your field format strictly in accordance with the specific format (including digits), can use the string to compare directly

CodePudding user response:

Learn about

CodePudding user response:

Why can't you field type is varchar2 type that check?
  • Related