VALIDATE_CONVERSION
Syntax
Purpose
VALIDATE_CONVERSION determines whether expr can be converted to the specified data type. If expr can be successfully converted, then this function returns 1; otherwise, this function returns 0. If expr evaluates to null, then this function returns 1. If an error occurs while evaluating expr, then this function returns the error.
For expr, specify a SQL expression. The acceptable data types for expr, and the purpose of the optional fmt and nlsparam arguments, depend on the data type you specify for type_name.
For type_name, specify the data type to which you want to convert expr. You can specify the following data types:
-
BINARY_DOUBLEIf you specify
BINARY_DOUBLE, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type, or a numeric value of typeNUMBER,BINARY_FLOAT, orBINARY_DOUBLE. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_BINARY_DOUBLEfunction. Refer to TO_BINARY_DOUBLE for more information. -
BINARY_FLOATIf you specify
BINARY_FLOAT, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type, or a numeric value of typeNUMBER,BINARY_FLOAT, orBINARY_DOUBLE. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_BINARY_FLOATfunction. Refer to TO_BINARY_FLOAT for more information. -
DATEIf you specify
DATE, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_DATEfunction. Refer to TO_DATE for more information. -
INTERVALDAYTOSECONDIf you specify
INTERVALDAYTOSECOND, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type, and must contain a value in either the SQL interval format or the ISO duration format. The optionalfmtandnlsparamarguments do not apply for this data type. Refer to TO_DSINTERVAL for more information on the SQL interval format and the ISO duration format. -
INTERVALYEARTOMONTHIf you specify
INTERVALYEARTOMONTH, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type, and must contain a value in either the SQL interval format or the ISO duration format. The optionalfmtandnlsparamarguments do not apply for this data type. Refer to TO_YMINTERVAL for more information on the SQL interval format and the ISO duration format. -
NUMBERIf you specify
NUMBER, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type, a numeric value of typeNUMBER,BINARY_FLOAT, orBINARY_DOUBLEor value of typeBOOLEAN. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_NUMBERfunction. Refer to TO_NUMBER for more information.If
expris a value of typeNUMBER, then theVALIDATE_CONVERSIONfunction verifies thatexpris a legal numeric value. Ifexpris not a legal numeric value, then the function returns 0. This enables you to identify corrupt numeric values in your database. -
TIMESTAMPIf you specify
TIMESTAMP, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_TIMESTAMPfunction. If you omitfmt, thenexprmust be in the default format of theTIMESTAMPdata type, which is determined by theNLS_TIMESTAMP_FORMATinitialization parameter. Refer to TO_TIMESTAMP for more information. -
TIMESTAMPWITHTIMEZONEIf you specify
TIMESTAMPWITHTIMEZONE, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_TIMESTAMP_TZfunction. If you omitfmt, thenexprmust be in the default format of theTIMESTAMPWITHTIMEZONEdata type, which is determined by theNLS_TIMESTAMP_TZ_FORMATinitialization parameter. Refer to TO_TIMESTAMP_TZ for more information. -
TIMESTAMPWITHLOCALTIMEZONEIf you specify
TIMESTAMP, thenexprcan be any expression that evaluates to a character string ofCHAR,VARCHAR2,NCHAR, orNVARCHAR2data type. The optionalfmtandnlsparamarguments serve the same purpose as for theTO_TIMESTAMPfunction. If you omitfmt, thenexprmust be in the default format of theTIMESTAMPdata type, which is determined by theNLS_TIMESTAMP_FORMATinitialization parameter. Refer to TO_TIMESTAMP for more information. -
BOOLEANBOOLEANis supported as a target type. It supportsNUMBERtype family,VARCHARtype family, andBOOLEANitself as input.
Examples
In each of the following statements, the specified value can be successfully converted to the specified data type. Therefore, each of these statements returns a value of 1.
SELECT VALIDATE_CONVERSION(1000 AS BINARY_DOUBLE)
FROM DUAL;
SELECT VALIDATE_CONVERSION('1234.56' AS BINARY_FLOAT)
FROM DUAL;
SELECT VALIDATE_CONVERSION('July 20, 1969, 20:18' AS DATE,
'Month dd, YYYY, HH24:MI', 'NLS_DATE_LANGUAGE = American')
FROM DUAL;
SELECT VALIDATE_CONVERSION('200 00:00:00' AS INTERVAL DAY TO SECOND)
FROM DUAL;
SELECT VALIDATE_CONVERSION('P1Y2M' AS INTERVAL YEAR TO MONTH)
FROM DUAL;
SELECT VALIDATE_CONVERSION('$100,00' AS NUMBER,
'$999D99', 'NLS_NUMERIC_CHARACTERS = '',.''')
FROM DUAL;
SELECT VALIDATE_CONVERSION('29-Jan-02 17:24:00' AS TIMESTAMP,
'DD-MON-YY HH24:MI:SS')
FROM DUAL;
SELECT VALIDATE_CONVERSION('1999-12-01 11:00:00 -8:00'
AS TIMESTAMP WITH TIME ZONE, 'YYYY-MM-DD HH:MI:SS TZH:TZM')
FROM DUAL;
SELECT VALIDATE_CONVERSION('11-May-16 17:30:00'
AS TIMESTAMP WITH LOCAL TIME ZONE, 'DD-MON-YY HH24:MI:SS')
FROM DUAL;The following statement returns 0, because the specified value cannot be converted to BINARY_FLOAT:
SELECT VALIDATE_CONVERSION('$29.99' AS BINARY_FLOAT)
FROM DUAL;The following statement returns 1, because the specified number format model enables the value to be converted to BINARY_FLOAT:
SELECT VALIDATE_CONVERSION('$29.99' AS BINARY_FLOAT, '$99D99')
FROM DUAL;