A table is created ...
... and filled with text of which some can be converted to numbers:
insert into safe_to_number_t values ('1.0' );
insert into safe_to_number_t values ('1' );
insert into safe_to_number_t values ('22.9' );
insert into safe_to_number_t values ('FOO' );
insert into safe_to_number_t values ('-8.99' );
insert into safe_to_number_t values ('-.22' );
insert into safe_to_number_t values ('-BAR' );
insert into safe_to_number_t values ('23-45' );
However, some txts cannot be converted...
... and an error is thrown:
ERROR:
ORA-01722: invalid number
So, a function is created that can safely convert strings to numbers. When the string is inconvertable, it returns null:
create function safe_to_number(txt in varchar2) return number is
begin
return to_number(txt);
exception when value_error then
return null;
end safe_to_number;
/
select safe_to_number(txt), txt from safe_to_number_t;
SAFE_TO_NUMBER(TXT) TXT
------------------- ----------
1 1.0
1 1
22.9 22.9
FOO
-8.99 -8.99
-.22 -.22
-BAR
23-45
select safe_to_number(txt), txt from safe_to_number_t;
With regexp_substr
select to_number(
regexp_substr(txt,'^[-]?[[:digit:]]*\.?[[:digit:]]*$')
) the_number,
txt
from safe_to_number_t;
|
相关推荐
书中讲解了如何对数字进行四舍五入(Rounding numbers)、生成随机数(Generating random numbers)、将字符串转换为整数和小数(Converting ...)、以及将数字转换为字符串(Converting numbers to strings)...
- Easy converting of text to hex string in dialogs (e.g. "abc" -> "61 62 63") - Decoding and encoding of 1, 2, 4, and 8 byte integers or 4/8 byte floats in 2 possible byte orders - Bit manipulation ...
27. Converting strings to numbers, numbers to strings(字符串和数字的互相转换):了解不同数据类型之间的转换方法。 28. Controlling the length of decimals(控制小数点长度):通过四舍五入、向下取整等方式...
- change in DBWPRich.pas to use LoadFromString instead of Text - fix possible range check error - change in WPTbar.pas to use different default for BevelOuter - change in WPIOHTML to use default ...
- FIX: The PointOnLine() function calulations have "single" type numbers overflow problem (changed to "double"). - FIX: The pfJoin and pfClose flags incorrectly calculates in GetEditPathCaps(). ...
- Converting numbers to strings. - Joining strings using the `join()` method. 29. **Add Numbers** - **Objective:** Add a list of numbers. - **Key Concepts:** - Using loops to iterate over ...
Converting Between Types Chapter 6. Capstone: The Vigenère Cipher Unit 3 - BUILDING BLOCKS Chapter 1. Functions Chapter 2. Methods Chapter 3. First-Class Functions Chapter 4. Capstone: Temperature ...
Converting HTML Documents to Texton a Unix Terminal Chapter 2. Files Introduction Recipe 2.1. Reading from a File Recipe 2.2. Writing to a File Recipe 2.3. Searching and Replacing Text in a...
It can be added to the 'Tools' menu in DevStudio."<END><br>53,convertbase.zip VB has built in functions for converting from decimal to Hex and Octal, but nothing for converting from Octal and Hex ...
Chapter 3, Handling Text: This chapter demonstrates how to control font size, color, and position using any of the font typefaces installed on the specific operating system being used. A simple ...
+ added a property TruncateLongTexts to the XLS OLE export that allows to disable truncating texts longer than a specified limit + added option EmbedProt which allows to disable embedding fonts into ...
- **From Problem to Program**: This discusses the process of converting a problem statement into a program, including understanding the problem, designing an algorithm, coding, testing, and debugging....
Twitter Digg Facebook Del.icio.us Reddit Stumbleupon Newsvine Technorati Mr....Add to your CodeProject bookmarks ...In v2.3 a single simple change of converting internal classes ...
- **Random Sequences**: Functions like `rnorm()`, `runif()`, etc., can be used to generate random numbers following specific distributions. ##### Manipulating Objects R offers a wide range of ...
- **Adding Controls**: In Interface Builder, you can drag and drop various UI elements such as buttons, labels, and text fields onto your view controller. You can also customize their appearance and ...
Text Vs. Data Instead Of Unicode Vs. 8-bit Overview Of Syntax Changes New Syntax Changed Syntax Removed Syntax Changes Already Present In Python 2.6 Library Changes PEP 3101: A New Approach To ...
3 Organization of This Text and Pedagogical Concerns 4 Obtaining Program Source Listings and Other Materials in This Text <br>Section One: Machine Organization <br>Art of Assembly ...
DECNUM: Converting an Integer to Decimal Format Section 6.7. Using C for ASCII Input and Output Section 6.8. BACKWARD: Using Byte Manipulations Summary References Exercises Chapter 7. ...