PARSE (Transact-SQL)PARSE (Transact-SQL)
SQL Server
Banco de Dados SQL do Azure
Azure Synapse Analytics (SQL DW)
Parallel Data Warehouse
SQL Server
Azure SQL Database
Azure Synapse Analytics (SQL DW)
Parallel Data Warehouse
Retorna o resultado de uma expressão, convertida no tipo de dados solicitado no SQL ServerSQL Server.Returns the result of an expression, translated to the requested data type in SQL ServerSQL Server.
Convenções de sintaxe de Transact-SQL
Transact-SQL Syntax Conventions
SintaxeSyntax
PARSE ( string_value AS data_type [ USING culture ] )
ArgumentosArguments
string_valuestring_value
Valor nvarchar(4000) que representa o valor formatado a ser analisado no tipo de dados especificado.nvarchar(4000) value representing the formatted value to parse into the specified data type.
string_value deve ser uma representação válida do tipo de dados solicitado, ou PARSE gera um erro.string_value must be a valid representation of the requested data type, or PARSE raises an error.
data_typedata_type
Valor literal que representa o tipo de dados solicitado para o resultado.Literal value representing the data type requested for the result.
cultureculture
Cadeia de caracteres opcional que identifica a cultura na qual string_value é formatado.Optional string that identifies the culture in which string_value is formatted.
Se o argumento culture não for fornecido, o idioma da sessão atual será usado.If the culture argument is not provided, then the language of the current session is used. Esse idioma é definido implícita ou explicitamente com o uso da instrução SET LANGUAGE.This language is set either implicitly, or explicitly by using the SET LANGUAGE statement. culture aceita qualquer cultura compatível com o .NET Framework; não se limita aos idiomas explicitamente compatíveis do SQL ServerSQL Server.culture accepts any culture supported by the .NET Framework; it is not limited to the languages explicitly supported by SQL ServerSQL Server. Se o argumento culture não for válido, PARSE gerará um erro.If the culture argument is not valid, PARSE raises an error.
Tipos de retornoReturn Types
Retorna o resultado da expressão, convertida no tipo de dados solicitado.Returns the result of the expression, translated to the requested data type.
RemarksRemarks
Os valores nulos transmitidos como argumentos para PARSE são tratados de dois modos:Null values passed as arguments to PARSE are treated in two ways:
Se uma constante nula for transmitida, um erro ocorrerá.If a null constant is passed, an error is raised. Um valor nulo não pode ser analisado em um tipo de dados diferente de maneira cultural.A null value cannot be parsed into a different data type in a culturally aware manner.
Se um parâmetro com um valor nulo for transmitido no momento da execução, um valor nulo será retornado, para evitar o cancelamento do lote inteiro.If a parameter with a null value is passed at run time, then a null is returned, to avoid canceling the whole batch.
Use PARSE somente para converter de cadeia de caracteres em data/hora e tipos numéricos.Use PARSE only for converting from string to date/time and number types. Para conversões de tipos gerais, continue a usar CAST ou CONVERT.For general type conversions, continue to use CAST or CONVERT. Lembre-se de que há uma certa sobrecarga de desempenho na análise do valor da cadeia de caracteres.Keep in mind that there is a certain performance overhead in parsing the string value.
PARSE depende da presença do CLR (Common Language Runtime) do .NET Framework.PARSE relies on the presence of the .NET Framework Common Language Runtime (CLR).
Essa função não será remota uma vez que ela depende da presença do CLR.This function will not be remoted since it depends on the presence of the CLR. Uma função remota que exige o CLR provocará um erro no servidor remoto.Remoting a function that requires the CLR would cause an error on the remote server.
Mais informações sobre o parâmetro data_typeMore information about the data_type parameter
Os valores para o parâmetro data_type serão restritos aos tipos mostrados na tabela a seguir, juntamente com estilos.The values for the data_type parameter are restricted to the types shown in the following table, together with styles. As informações de estilo são fornecidas para ajudar a determinar que tipos de padrões são permitidos.The style information is provided to help determine what types of patterns are allowed. Para obter mais informações sobre estilos, veja a documentação do .NET Framework para as enumerações System.Globalization.NumberStyles e DateTimeStyles.For more information on styles, see the .NET Framework documentation for the System.Globalization.NumberStyles and DateTimeStyles enumerations.
CategoriaCategory | TipoType | Tipo de .NET Framework.NET Framework type | Estilos usadosStyles used |
---|---|---|---|
NuméricoNumeric | BIGINTbigint | Int64Int64 | NumberStyles.NumberNumberStyles.Number |
NuméricoNumeric | INTint | Int32Int32 | NumberStyles.NumberNumberStyles.Number |
NuméricoNumeric | SMALLINTsmallint | Int16Int16 | NumberStyles.NumberNumberStyles.Number |
NuméricoNumeric | TINYINTtinyint | ByteByte | NumberStyles.NumberNumberStyles.Number |
NuméricoNumeric | Decimaldecimal | DecimalDecimal | NumberStyles.NumberNumberStyles.Number |
NuméricoNumeric | NUMERICnumeric | DecimalDecimal | NumberStyles.NumberNumberStyles.Number |
NuméricoNumeric | FLOATfloat | DoubleDouble | NumberStyles.FloatNumberStyles.Float |
NuméricoNumeric | REALreal | SingleSingle | NumberStyles.FloatNumberStyles.Float |
NuméricoNumeric | SMALLMONEYsmallmoney | DecimalDecimal | NumberStyles.CurrencyNumberStyles.Currency |
NuméricoNumeric | moneymoney | DecimalDecimal | NumberStyles.CurrencyNumberStyles.Currency |
Data e horaDate and Time | Datadate | DateTimeDateTime | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversalDateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal |
Data e horaDate and Time | timetime | TimeSpanTimeSpan | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversalDateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal |
Data e horaDate and Time | DATETIMEdatetime | DateTimeDateTime | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversalDateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal |
Data e horaDate and Time | smalldatetimesmalldatetime | DateTimeDateTime | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversalDateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal |
Data e horaDate and Time | datetime2datetime2 | DateTimeDateTime | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversalDateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal |
Data e horaDate and Time | datetimeoffsetdatetimeoffset | DateTimeOffsetDateTimeOffset | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversalDateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal |
Mais informações sobre o parâmetro cultureMore information about the culture parameter
A tabela a seguir mostra os mapeamentos de idiomas do SQL ServerSQL Server para culturas do .NET Framework.The following table shows the mappings from SQL ServerSQL Server languages to .NET Framework cultures.
Nome completoFull name | AliasAlias | LCIDLCID | Cultura específicaSpecific culture |
---|---|---|---|
us_englishus_english | InglêsEnglish | 10461033 | en-USen-US |
DeutschDeutsch | GermanGerman | 10311031 | de-DEde-DE |
FrançaisFrançais | FrancêsFrench | 10361036 | fr-FRfr-FR |
日本語日本語 | JaponêsJapanese | 10411041 | ja-JPja-JP |
DanskDansk | DanishDanish | 10301030 | da-DKda-DK |
EspañolEspañol | EspanholSpanish | 30823082 | es-ESes-ES |
ItalianoItaliano | ItalianoItalian | 10401040 | it-ITit-IT |
NederlandsNederlands | HolandêsDutch | 10431043 | nl-NLnl-NL |
NorskNorsk | NorueguêsNorwegian | 20682068 | nn-NOnn-NO |
PortuguêsPortuguês | PortuguêsPortuguese | 20702070 | pt-PTpt-PT |
SuomiSuomi | FinlandêsFinnish | 10351035 | fi-FIfi-FI |
SvenskaSvenska | SuecoSwedish | 10531053 | sv-SEsv-SE |
češtinačeština | CzechCzech | 10291029 | Cs-CZCs-CZ |
magyarmagyar | HúngaroHungarian | 10381038 | Hu-HUHu-HU |
polskipolski | PolonêsPolish | 10451045 | Pl-PLPl-PL |
românăromână | RomenoRomanian | 10481048 | Ro-RORo-RO |
hrvatskihrvatski | CroataCroatian | 10501050 | hr-HRhr-HR |
slovenčinaslovenčina | EslovacoSlovak | 10511051 | Sk-SKSk-SK |
slovenskislovenski | EslovenoSlovenian | 10601060 | Sl-SISl-SI |
ελληνικάελληνικά | GreekGreek | 10321032 | El-GREl-GR |
българскибългарски | BúlgaroBulgarian | 10261026 | bg-BGbg-BG |
русскийрусский | RussoRussian | 10491049 | Ru-RURu-RU |
TürkçeTürkçe | TurcoTurkish | 10551055 | Tr-TRTr-TR |
BritishBritish | British EnglishBritish English | 20572057 | en-GBen-GB |
eestieesti | EstonianoEstonian | 10611061 | Et-EEEt-EE |
latviešulatviešu | LetãoLatvian | 10621062 | lv-LVlv-LV |
lietuviųlietuvių | LituanoLithuanian | 10631063 | lt-LTlt-LT |
Português (Brasil)Português (Brasil) | BrasileiroBrazilian | 10461046 | pt-BRpt-BR |
繁體中文繁體中文 | Chinês tradicionalTraditional Chinese | 10281028 | zh-TWzh-TW |
한국어한국어 | CoreanoKorean | 10421042 | Ko-KRKo-KR |
简体中文简体中文 | Chinês simplificadoSimplified Chinese | 20522052 | zh-CNzh-CN |
ÁrabeArabic | ÁrabeArabic | 10251025 | ar-SAar-SA |
ไทยไทย | TailandêsThai | 10541054 | Th-THTh-TH |
ExemplosExamples
A.A. PARSE em datetime2PARSE into datetime2
SELECT PARSE('Monday, 13 December 2010' AS datetime2 USING 'en-US') AS Result;
Aqui está o conjunto de resultados.Here is the result set.
Result
---------------
2010-12-13 00:00:00.0000000
(1 row(s) affected)
B.B. PARSE com símbolo de moedaPARSE with currency symbol
SELECT PARSE('€345,98' AS money USING 'de-DE') AS Result;
Aqui está o conjunto de resultados.Here is the result set.
Result
---------------
345.98
(1 row(s) affected)
C.C. PARSE com configuração implícita de idiomaPARSE with implicit setting of language
-- The English language is mapped to en-US specific culture
SET LANGUAGE 'English';
SELECT PARSE('12/16/2010' AS datetime2) AS Result;
Aqui está o conjunto de resultados.Here is the result set.
Result
---------------
2010-12-16 00:00:00.0000000
(1 row(s) affected)
Comentários
Carregando comentários...