Overview Classes of datatypes available in Oracle 10g – Character – Numeric – Long, Raw –...
-
Upload
amos-singleton -
Category
Documents
-
view
217 -
download
2
Transcript of Overview Classes of datatypes available in Oracle 10g – Character – Numeric – Long, Raw –...
1
Overview
• Classes of datatypes available in Oracle 10g– Character– Numeric– Long, Raw– Dates/Times– Large Objects (LOBs)– ROWID– Specialized
2
Usage of Fonts
• Normal text• SQL SYNTAX or ORACLE FUNCTIONS• datatype or function parameter• datatype or function optional parameter
3
Character Datatypes
• 4 Datatypes– CHAR and NCHAR
• Fixed-length character literals• NCHAR used to represent Unicode characters (UTF8)• Store up to 2,000 bytes
– VARCHAR2 and NVARCHAR2• Variable-length character literals• Store up to 4,000 bytes
– VARCHAR• DON’T USE!! But, it is synonymous with the VARCHAR2 datatype• Shame on you if you use this datatype, Oracle may change this datatype
to use different comparison semantics in the future
– LONG (deprecated)• Store up to (2 gig -1) of char data
4
Character Datatype Declarations
CHAR(size,{BYTE,CHAR ;DEFAULT=BYTE})VARCHAR2(size,{BYTE,CHAR ;DEFAULT=BYTE})NCHAR(size)NVCHAR2(size)• Size can also be specified globally in NLS_LENGTH_SEMANTICS
5
Numeric Datatypes
• 3 Datatypes– NUMBER
• Fixed or floating point numbers• 38 decimal digits of precision• Represent from 1x10-130 to 9.99 x 10125
• Variable storage – 1 to 22 bytes per entry
– BINARY_FLOAT• Stores floats in 32-bit IEEE 754 format
– BINARY_DOUBLE• Stores floats in 64-bit IEEE 754 format
• BINARY_FLOAT and BINARY_DOUBLE advantages– Usually faster computations than NUMBER operations– Use less space to hold data
• IEEE 754 datatype disadvantages– Fixed size may not be optimal use of space
6
Numeric Datatype Declarations
NUMBER(precision,size)1 <= precision <= 37
-84 <= size <= 127
BINARY_FLOATBINARY_DOUBLE
7
Numeric Operators and Functions
• Operators
• Functions– TO_BINARY_DOUBLE – Convert float or decimal to double– TO_BINARY_FLOAT – Convert double or decimal to float– TO_CHAR – Convert float or double to decimal– TO_NUMBER – Convert a float, double or decimal to a number
– Addition– Multiplication– Remainder (modulus)– Subtraction
– Division– Square Root– Equality
8
Time / Date Data
• Datatypes– DATE
• Stored as {century, year, month, day, hour, minute, second}
– TIMESTAMP• Same as DATE, but with fractional seconds• Specify the number of seconds of precision, up to 9 digits• TIMESTAMP WITH TIME ZONE
– Stores TIMESTAMP with displacement between local and UTC time• TIMESTAMP WITH LOCAL TIME ZONE
– Stores TIMESTAMP but time is normalized to time of database upon entry. Query results return time relative to user
– INTERVAL YEAR(precision)TO MONTH– INTERVAL MONTH(precision)TO SECOND
9
Date / Time Operators and Functions
• Operators– Addition, subtraction, equality
• Functions– ANSI Literal – ‘2009-09-16’– TO_DATE(‘09-SEP-16 16:00’, ‘YY-MON-DD HH24:MI’)– SYSDATE – System Date (current time)– TRUNC(date) – Truncates sets time portion to midnight– INTERVAL YEAR [precision] TO MONTH– INTERVAL DAY TO SECOND
10
RAW and LONG RAW Datatypes
• Intended for binary data or byte strings not interpreted by Oracle Database
• Intended to hold binary data such as graphics, documents, etc.
• Oracle recommends converting these types to LOBs
11
Large Objects
• About– LOBs are used to store binary files– Query results including LOBs returns LOB locator
• Datatypes– CLOB and NCLOB
• Store up to (4 gig -1) * (DMBS_LOB.GETCHUNCKSIZE) of char data
– BLOB – Binary Large Object• Store up to (4 gig -1) of data
– BFILE – Binary File• Store up to 4 gigabytes of data• Stored in a separate file on the server• Administrator responsible that the files exist and can be accessed
12
ROWID Datatype
• Row addresses in Oracle• Access row addresses by querying ROWID• Extended rowids– Supports partitioned tables and indexes without ambiguity
13
Specialized Datatypes
• Other types of data that can be represented– Geographic– Multimedia– Searchable Text– XML– Dynamically Typed Data– ANSI/ISO, DB2 and SQL/DS Data
14
Geographic Datatype
• MDSYS.SDO_GEOMETRY– Must have installed Oracle Spatial– Object created using
CREATE TYPE SDO_GEOMETRY AS OBJECT ( SDO_GTYPE NUMBER, SDO_SRID NUMBER, SDO_POINT SDO_POINT_TYPE, SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY, SDO_ORDINATES SDO_ORDINATE_ARRAY);
• SDO_GTYPE – reference to type of point (line, curve, polygon, etc)• SDO_SRID – reference for the spatial coordinate system• SDO_POINT – (x,y,z) coordinate of point• SDO_ELEM_INFO – • SDO_ORDINATES – lkj
15
Regular Expressions Overview
• Regular expressions are a language for pattern matching within text (string data)
• Useful when you want to find like strings or to extract information from strings
• Portable-ish – syntax can be used across applications, though some applications use more a more feature rich syntax than others
• Syntax is interpreted through a Regex Engine– DFA – Very fast, tends to use more memory, uses longest
leftmost matching– NFA – Uses backtracking, exhaustively searches all
permutations of the regex
16
Regex Syntax Basics
Syntax Name Example Matches. Any Character O.ama Osama, Obama, Omama
+ One or more characters Be+r Ber, Beer, Beeeeeeeeeeeeeer
? Zero or One Stuff? Stuf, Stuff
* Zero or More Foo* Fo, Foo, Fooooooooooooooooo
| Alternation cat|bat cat, bat
{m} Exact Count Clas{2} Class
{m,} At least SQ{1,}L SQL, SQQQQQQQQL
{m,n} In between Ap{1,3}le Aple, Apple, Appple
(…) Grouping, Sub-expression (fa|fi)t fat, fit
[ ...] Character set [bc]at bat, cat
[^ ...] Not in character set [^bc]at fat, hat,
^ Beginning of line ^The The quick brown fox, The lazy dog
$ End of line s$ Sleeps, sleeps, eats
\d Any digit \d\d 10, 20, 99
\w Any word character \w\w\w www, w_w, 222
\s Any space character \s tab, newline, space, carriage return
17
Regex Functions
• REGEXP_LIKE(columnName,pattern)– Used in a WHERE clause to search for a pattern
• REGEXP_REPLACE(string,pattern,repl,pos,occ,m_param)– Replaces a matched pattern with a specified string
• REGEXP_INSTR(string,pattern,pos,occ,ret,m_param)– Searches for an instance of a pattern and returns the position
in the string where that pattern is found• REGEXP_SUBSTR(string,pattern,pos,occ,m_param)– Returns a substring matching the regex pattern specified
18
References
• Oracle 10g Application Developer’s Guide• Oracle 10g Call Interface Programmer’s Guide• Oracle 10g SQL Reference• Oracle 10g Spatial User’s Guide and Reference• Mastering Regular Expressions by Jeffrey Friedl• Wikipedia– IEEE 754