Sql oracle reference manual


















Compound Statement Syntax. Variables in Stored Programs. Local Variable Scope and Resolution. Flow Control Statements. Restrictions on Server-Side Cursors. Restrictions on Condition Handling. Database Administration Statements. Account Management Statements.

Snowflake is available to accelerate your migration, structure and optimize your planning and implementation activities; and apply customer best practices to meet your technology and business needs. Get Access. First Name. Last Name. Oracle uses universal rowids urowids to store the addresses of index-organized and foreign tables. Index-organized tables have logical urowids and foreign tables have foreign urowids.

Both types of urowid are stored in the ROWID pseudocolumn as are the physical rowids of heap-organized tables. Oracle creates logical rowids based on the primary key of the table. The logical rowids do not change as long as the primary key does not change. ROWID statement. It converts the data type to the equivalent Oracle data type, records the Oracle data type as the name of the column data type, and stores the column data in the Oracle data type based on the conversions shown in the tables that follow.

Table 3—6 Cont. Notes: 1. For those data types, the scale s defaults to 0. The default precision for this data type is binary, or 38 decimal. The REAL data type is a floating-point number with a binary precision of 63, or 18 decimal. Table 3—7 Cont. For this data type, s defaults to 0. The default precision for this data type is binary or 38 decimal.

User-Defined Types User-defined data types use Oracle built-in data types and other user-defined data types as the building blocks of object types that model the structure and behavior of data in applications. The sections that follow describe the various categories of user-defined types.

Object Types Object types are abstractions of the real-world entities, such as purchase orders, that application programs deal with. Attributes model the structure of the real-world entity. Methods implement operations the application can perform on the real-world entity.

REF Data Types An object identifier represented by the keyword OID uniquely identifies an object and enables you to reference the object from other objects or from relational tables.

A data type category called REF represents such references. A REF data type is a container for an object identifier. REF values are pointers to objects. To determine whether a REF is dangling or. Varrays An array is an ordered set of data elements.

All elements of a given array are of the same data type. Each element has an index, which is a number corresponding to the position of the element in the array.

The number of elements in an array is the size of the array. Oracle arrays are of variable size, which is why they are called varrays. You must specify a maximum size when you declare the varray. When you declare a varray, it does not allocate space. However, if you specify separate storage characteristics for a varray, then Oracle stores it out of line, regardless of its size. Nested Tables A nested table type models an unordered set of elements.

The elements may be built-in types or user-defined types. You can view a nested table as a single-column table or, if the nested table is an object type, as a multicolumn table, with a column for each attribute of the object type. A nested table definition does not allocate space. Oracle Database automatically provides the low-level infrastructure services needed for input-output, heterogeneous client-side access for new data types, and optimizations for data transfers between the application and the database.

These interfaces can be used to build user-defined or object types and are also used by Oracle to create some commonly useful data types. Several such data types are supplied with the server, and they serve both broad horizontal application areas for example, the Any types and specific vertical ones for example, the spatial types. Any Types The Any types provide highly flexible modeling of procedure parameters and table columns where the actual type is not known. These data types let you dynamically encapsulate and access type descriptions, data instances, and sets of data instances of any other SQL type.

The values can be of SQL built-in types as well as user-defined types. The values of the data instances can be of SQL built-in types as well as user-defined types. It also provides a set of types to store and access both external and internal URIs from within the database. XMLType is a system-defined type, so you can use it as an argument of a function or as the data type of a table or view column. You can also create tables and views of XMLType.

The fragment is separated from the URL part by a pound sign. Storing DBURIRef values lets you reference data stored inside or outside the database and access the data consistently. If you imagine the database as an XML tree, then you would see the tables, rows, and columns as elements in the XML document. For example, URIFactory. Spatial Types Oracle Spatial is designed to make spatial data management easier and more natural to users of location-enabled applications, geographic information system GIS applications, and geoimaging applications.

After the spatial data is stored in an Oracle Database, you can easily manipulate, retrieve, and relate it to all the other data stored in the database. The following data types are available only if you have installed Oracle Spatial. Tables of this sort are sometimes called geometry tables. Tables of this sort are called GeoRaster tables. An instance of these object types consists of attributes, including metadata and the media data, and methods.

Public synonyms exist for all the data types, so you can access them without specifying the schema name. Use this type when you want all media to be stored in a single column. Supports the storage and management of image data. Existing occurrences of this object type will continue to function as in the past.

Expression Filter Type The Oracle Expression Filter allows application developers to manage and evaluate conditional expressions that describe users' interests in data. The Expression Filter includes the following data type:. Expression Expression Filter uses a virtual data type called Expression to manage and evaluate conditional expressions as data in database tables.

This assignment enables a data constraint that ensures the validity of expressions stored in the column. Numeric Values A larger value is considered greater than a smaller one. All negative numbers are less than zero and all positive numbers. Thus, -1 is less than ; is less than The floating-point value NaN not a number is greater than any other numeric value and is equal to itself. See Also: "Numeric Precedence" on page and "Floating-Point Numbers" on page for more information on comparison semantics.

Date Values A later date is considered greater than an earlier one. Binary and Linguistic Comparisons In binary comparison, which is the default, Oracle compares character strings according to the concatenated value of the numeric codes of the characters in the database character set. One character is greater than another if it has a greater numeric value than the other in the character set.

Oracle considers blanks to be less than any character, which is true in most character sets. Blank-Padded and Nonpadded Comparison Semantics With blank-padded semantics, if the two values have different lengths, then Oracle first adds blanks to the end of the shorter one so their lengths are equal. Oracle then compares the values character by character up to the first character that differs. The value with the greater character in the first differing position is considered greater.

If two values have no differing characters, then they are considered equal. This rule means that two values are equal if they differ only in the number of trailing blanks.

With nonpadded semantics, Oracle compares two values character by character up to the first character that differs. The value with the greater character in that position is considered greater. If two values of different length are identical up to the end of the shorter one, then the longer value is considered greater.

If two values of equal length have no differing characters, then the values are considered equal. The results of comparing two character values using different comparison semantics may vary. The table that follows shows the results of comparing five pairs of character values using each comparison semantic. Usually, the results of blank-padded and nonpadded comparisons are the same. The last comparison in the table illustrates the differences between the blank-padded and nonpadded comparison semantics.

Uppercase and lowercase letters are not equivalent. The numeric values for the characters of a character set may not match the linguistic sequence for a particular language. Table 3—8 Cont. Both functions compare object type instances, but they are quite different from one another. These functions must be specified as part of any object type that will be compared with other object types.

Varrays and Nested Tables Comparison of nested tables is described in "Comparison Conditions" on page Data Type Precedence Oracle uses data type precedence to determine implicit data type conversion, which is discussed in the section that follows.

Data Conversion Generally an expression cannot contain values of different data types. However, Oracle supports both implicit and explicit conversion of values from one data type to another. Behavior of explicit conversions is more predictable. This can have a negative impact on performance. Implicit Data Conversion Oracle Database automatically converts a value from one data type to another when such a conversion makes sense. Table 3—10 is a matrix of Oracle implicit conversions. The table shows all possible conversions, without regard to the direction of the conversion or the context in which it is made.

The rules governing these details follow the table. In such cases, the numeric data type resulting from such operations can differ from the numeric data type found in the underlying tables. This behavior differs from earlier releases of Oracle Database, when the fractional seconds portion of the timestamp value was rounded. The default direction of conversion in such cases is from the database character set to the national character set. Table 3—11 shows the direction of implicit conversions between different character types.

User-defined types such as collections cannot be implicitly converted, but must be explicitly converted using CAST Table 3—12 shows SQL functions that explicitly convert a value from one data type to another.

See Also: "Conversion Functions" on page for details on all of the explicit conversion functions. Security Considerations for Data Conversion When a datetime value is converted to text, either by implicit conversion or by explicit conversion that does not specify a format model, the format model is defined by one of the globalization session parameters.

The dependency of format models on session parameters can have a negative impact on database security when conversion without an explicit format model is applied to a datetime value that is being concatenated to text of a dynamic SQL statement. Dynamic SQL statements are those statements whose text is concatenated from fragments before being passed to a database for execution.

The result is concatenated into SQL text. A datetime format model can consist simply of literal text enclosed in double quotation marks.

Therefore, any user who can explicitly set globalization parameters for a session can decide what text is produced by the above conversion. If the procedure runs with definer's rights, with higher privileges than the session itself, the user can gain unauthorized access to sensitive data.

Note: This security risk also applies to middle-tier applications that construct SQL text from datetime values converted to text by the database or by OCI datetime functions.

Those applications are vulnerable if session globalization parameters are obtained from a user preference. This parameter defines the decimal and group separator characters. If the decimal separator is defined to be the quotation mark or the double quotation mark, some potential for SQL injection emerges. Literals The terms literal and constant value are synonymous and refer to a fixed data value. Character literals are enclosed in single quotation marks so that Oracle can distinguish them from schema object names.

You can also specify literals as part of expressions and conditions. You can specify character literals with the 'text' notation, national character literals with the N'text' notation, and numeric literals with the integer, or number notation, depending on the context of the literal. The syntactic forms of these notations appear in the sections that follow.

To specify a datetime or interval data type as a literal, you must take into account any optional precisions included in the data types. Examples of specifying datetime and interval data types as literals are provided in the relevant sections of "Data Types" on page Text Literals Use the text literal notation to specify values whenever 'string' appears in the syntax of expressions, conditions, SQL functions, and SQL statements in other parts of this reference.

This reference uses the terms text literal, character literal, and string interchangeably. Text, character, and string literals are always surrounded by single quotation marks. When char appears in the syntax, the single quotation marks are not used. The syntax of text literals or strings follows:. By default, text entered using this notation is translated into the national character set by way of the database character set when used by the server. Doing so transparently replaces the n' internally and preserves the text literal for SQL processing.

A single quotation mark ' within the literal must be preceded by an escape character. To represent one single quotation mark within a literal, enter two single quotation marks. In the bottom branch of the syntax:. This mechanism allows a wide range of delimiters for the text string.

You can include quotation marks " in the text literal made up of c characters. Here are some valid text literals using the alternative quoting mechanism: q'! Numeric Literals Use numeric literal notation to specify fixed and floating-point numbers.

Integer Literals You must use the integer notation to specify an integer whenever integer appears in expressions, conditions, SQL functions, and SQL statements described in other parts of this reference. The syntax of integer follows:. An integer can store a maximum of 38 digits of precision.

The syntax of number follows:. If you omit the sign, then a positive value is the default. The digits after the E specify the exponent. The exponent can range from to However, if Oracle encounters the string '9f', then conversion fails and an error is returned.

If you have established a decimal character other than a period. In these cases, Oracle automatically converts the text literal to a numeric value. You can also use the following supplied floating-point literals in situations where a value cannot be expressed as a numeric literal:. This example date format includes a two-digit number for the day of the month, an abbreviation of the month name, the last two digits of the year, and a hour time designation.

Oracle automatically converts character values that are in the default date format into date values when they are used in date expressions. If you specify a date value without a time component, then the default time is midnight or for hour and hour clock time, respectively. If you specify a date value without a date, then the default date is the first day of the current month. Oracle DATE columns always contain both the date and time fields.

Therefore, if you query a DATE column, then you must either specify the time field in your query or ensure that the time fields in the DATE column are set to midnight.

Otherwise, Oracle may not return the query results you expect. You can use the TRUNC date function to set the time field to midnight, or you can include a greater-than or less-than condition in the query instead of an equality or inequality condition.

However, if the DATE column contains values other than midnight, then you must filter out the time fields in the query to get the correct result. Oracle applies the TRUNC function to each row in the query, so performance is better if you ensure the midnight value of the time fields in your data.

Pacific Standard Time is the same as a. Eastern Standard Time. To eliminate the ambiguity of boundary cases when the daylight saving time switches, use both the TZR and a corresponding TZD format element.

See Also: "Datetime Expressions" on page for more information. If that parameter is set to FALSE, then Oracle interprets the ambiguous datetime as standard time in the specified region. The time zone offset is not stored as part of the column data. Rather, you represent values of this data type using any of the other valid datetime. Notice that if the value specified does not include a time component either explicitly or implicitly , then the value returned defaults to midnight.

Interval Literals An interval literal specifies a period of time. You can specify these differences in terms of years and months, or in terms of days, hours, minutes, and seconds. Each type contains a leading field and may contain a trailing field. The leading field defines the basic unit of date or time being measured. The trailing field defines the smallest increment of the basic unit being considered.

Interval literals are used primarily with analytic functions. The valid range of the leading field precision is 0 to 9 and its default value is 2. Restriction on the Leading Field If you specify a trailing field, then it must be less significant than the leading field. Examples of the other forms of the literal follow, including some abbreviated versions:. You must specify the leading field precision if it is greater than the default of 2 digits.

If this value contains more digits than the number specified by the leading precision, then Oracle returns an error. Accepted values are 1 to 9.

Restriction on the Leading Field: If you specify a trailing field, then it must be less significant than the leading field. The fractional second '' is rounded to '' because the precision is 4. For example. Format Models A format model is a character literal that describes the format of datetime or numeric data stored in a character string.

A format model does not change the internal representation of the value in the database. When you convert a character string into a date or number, a format model determines how Oracle Database interprets the string. For lists of number and datetime format model elements, see Table 3—13, " Number Format Elements" on page and Table 3—15, " Datetime Format Elements" on page The values of some formats are determined by the value of initialization parameters.

If a value has more significant digits to the left of the decimal place than are specified in the format, then pound signs replace the value. However, if you omit the format model, then Oracle returns either Inf or Nan as a string. Number Format Elements A number format model is composed of one or more number format elements.

The tables that follow list the elements of a number format model and provide some examples. Negative return values automatically contain a leading negative sign and positive values automatically contain a leading space unless the format model contains the MI, S, or PR format element. You can specify multiple commas in a number format model.

Restriction: You can specify only one period in a number format model. Leading zeros are blank, except for a zero value, which returns a zero for the integer part of the fixed-point number.

B B Returns blanks for the integer part of a fixed-point number when the integer part is zero regardless of zeros in the format model. The default is a period. Restriction: You can specify only one decimal character in a number format model. EEEE 9. You can specify multiple group separators in a number format model. Restriction: A group separator cannot appear to the right of a decimal character or period in a number format model.

MI MI Returns negative value with a trailing minus sign -. Returns positive value with a trailing blank. Restriction: The MI format element can appear only in the last position of a number format model.

Returns positive value with a leading and trailing blank. Restriction: The PR format element can appear only in the last position of a number format model. Value can be an integer between 1 and Table 3—13 Cont. Restriction: The S format element can appear only in the first or last position of a number format model. TM TM The text minimum number format model returns in decimal output the smallest number of characters possible.

This element is case insensitive. The default is TM9, which returns the number in fixed notation unless the output exceeds 64 characters. If the output exceeds 64 characters, then Oracle Database automatically returns the number in scientific notation.

V V99 Returns a value multiplied by 10n and if necessary, round it up , where n is the number of 9's after the V. If the specified number is not an integer, then Oracle Database rounds it to an integer. Negative values return an error.

Any other elements return an error. If you specify neither 0 nor FM with X, then the return always has one leading blank.

Table 3—14 Results of Number Conversions number 'fmt' Result S '' 0 Table 3—14 Cont. Datetime Format Elements A datetime format model is composed of one or more datetime format elements as listed in Table 3—15, " Datetime Format Elements" on page Refer to the format model modifier FM on page for more information.

Uppercase Letters in Date Format Elements Capitalization in a spelled-out word, abbreviation, or Roman numeral follows capitalization in the corresponding format element. Description - Yes Punctuation and quoted text is reproduced in the result. AM Yes Meridian indicator with or without periods. BC Yes BC indicator with or without periods.

CC Century. For example, returns 21; returns Table 3—15 Cont. Description D Yes Day of week This element depends on the NLS territory of the session. DAY Yes Name of day. DD Yes Day of month DDD Yes Day of year Month yyyy'. Restriction: You can specify this format only with the TS element, separated by white space. DS Yes Returns a value in the short date format. DY Yes Abbreviated name of day.

FF [ Use the X format element to add the radix character. Use the numbers 1 to 9 after FF to specify the number of digits in the fractional second portion of the datetime value returned.

If you do not specify a digit, then Oracle Database uses the precision specified for the datetime data type or the data type's default precision. Valid in timestamp and interval formats, but not in DATE formats. Number specified with J must be integers. MI Yes Minute MON Yes Abbreviated name of month. PM Yes Meridian indicator with or without periods. This section will list the common functions with their arguments expected. A short example will be provided when necessary.

You can use the NVL in the argument to a group function to substitute a value for a null. If a query with a group function returns no rows or only rows with nulls for the argument to the group function, the group function returns null. Note that a format model does not change the internal representation of the value in the database. All number format models cause the number to be rounded to the specified number of significant digits.

If a value has more significant digits to the left of the decimal place than are specified in the format, pound signs replace the value. A number format model is composed of one or more number format elements.

The table below lists the elements of a number format model. The MI and PR format elements can only appear in the last position of a number format model. The S format element can only appear in the first or last position.

If a number format model does not contain the MI, S, or PR format elements, negative sign and positive values automatically contain a leading space. A number format model can contain only a single decimal character D or period. A group separator or comma cannot appear to the right of a decimal character or period in a number format model.

The characters returned by some of these format elements are specified by initialization parameters. The table below lists these elements and parameters. A date format model is composed of one or more date format elements.

The table below lists the elements of a date format model. The RR date format element is similar to the YY date format element, but it provides additional flexibility for storing date values in other centuries. The RR date format element allows you to store twenty-first century dates in the twentieth century by specifying only the last two digits of the year. It will also allow you to store twentieth century dates in the twenty-first century in the same way if necessary.

If you use the RR date format element instead, the century of the return value varies according to the specified two-digit year and the last two digits of the current year.

Capitalization in a spelled-out word, abbreviation, or Roman numeral follows capitalization in the corresponding format element. These characters appear in the return value in the same location as they appear in the format model. Note that character literals must be enclosed in quotation marks double quotes. A modifier can appear in a format model more than once.

In such case, each subsequent occurrence toggles the effects of the modifier. Its effects are enabled for the portion of the model following its first occurrence, and then disabled for the portion following its second, and then re-enabled for the portion following its third, and so on. The table shows the results of the following query for different values of number and 'fmt' using FM:.

The table shows whether the following statement meets the matching conditions for different values of char and 'fmt' using FX:. Note: Not all of the DDL commands have been explained here, only the ones that you are most likely to use. This command allows the user to create multiple tables, multiple views and perform multiple grants in a single transaction.

This command allows the user to create a table, the basic structure to hold user data, by specifying the following information:. The number of columns in a table can range from 1 to Datatypes are defined previously in this manual. The datatype of the expression must match the datatype of the column. PCTFREE - specifies the percentage of space in each of the table's data blocks reserved for future updates to the table's rows.

These parameters need not be set as the default values will be sufficient for your purpose. AS subquery - inserts the rows returned by the subquery into the table upon its creation.

To modify an integrity constraint, you must drop the constraint and redefine it. This directive defines a view, a logical table based on one or more tables or views. The owner of the schema containing the view must have the privileges necessary to either select, insert, update or delete rows from all the tables or views on which the view is based.

You can use this option to change the definition of an existing view without dropping, recreating, and regranting object privileges previously granted to it. FORCE - creates the view regardless of whether the view's base tables exist or the owner of the schema containing the view has privileges on them. NOFORCE - creates the view only if the base tables exist and the owner of the schema containing the view has privileges on them. The number of aliases must match the number of expressions selected by the view.

AS subquery - identifies columns and rows of the table s that the view is based on. If the view query contains any of the following constructs, you cannot perform inserts, updates, or deletes on the view:.

Note: If a view contains pseudocolumns or expressions, you can only update the view with an UPDATE statement that does not refer to any of the pseudocolumns or expressions. This command permits the user to grant privileges for a particular object to users and roles.

If you do not list columns, the grantee has the specified privilege on all columns in the table or view. A privilege cannot appear more than once in the list of privileges to be granted. A user or role cannot appear more than once in the TO clause. This directive permits the user to create an index on one or more columns of a table or a cluster.

An index is a database object that contains an entry for each value that appears in the indexed column s of the table or cluster and provides direct, fast access to rows. An index can have as many as 16 columns. When you initially insert rows into a new table, it is generally faster to create the table, insert the rows, and then create the index.

You can create several indexes on different columns in the same table. Note that each index increases the processing time needed to maintain the table during updates to indexed data. A role is a set of privileges that can be granted to users or to other roles. You can add privileges to a role's privilege domain and then grant the role to a user.

The user can then enable the role and exercise the privileges in the role's privilege domain. A sequence is a database object from which multiple users may generate unique integers. You can use sequences to automatically generate primary key values. If this value is negative, then the sequence descends.



0コメント

  • 1000 / 1000