当前位置:网站首页>Kingbasees SQL language reference manual of Jincang database (8. Function (I))

Kingbasees SQL language reference manual of Jincang database (8. Function (I))

2022-07-23 10:25:00 Thousands of sails passed by the side of the sunken boat_

8.  function

Functions are similar to operators , Because they manipulate data items and return results . Functions differ from operators in parameter format . This format enables them to zero 、 One 、 Operate with two or more parameters :

function ( Parameters , Parameters ,...) Functions without any parameters are similar to pseudo columns . however , Pseudo columns usually return different values for each row in the result set , Functions without any parameters usually return the same value for each row . This chapter contains the following sections :

8.1.  About SQL function

SQL The function is built into KingBase In the database , It can be used in various appropriate SQL sentence . Don't put SQL Functions and use PL/SQL User defined functions written are confused .

If the SQL The data type of the parameter of the function is the same as SQL The data type expected by the function is different , that KingBase Will be in execution SQL Function before trying to convert the parameter to the expected data type .

  • SQL Null value in function

    Most scalar functions are given null Parameter null. You can use the NVL Function is happening null Returns a value . for example , If it is empty , Expression NVL(commission_pct,0) return 0, If commission_pct Not empty , Then return to Value commission_pct.

    Information about how aggregate functions handle null values , See aggregate functions .

  • SQL Syntax of functions

    stay SQL In the syntax diagram of the function , Parameters are represented by their data types . When parameters function Appear in the SQL Grammatical middle tense , Replace it with one of the functions described in this section . Functions are grouped by the data types of their parameters and return values .

    take SQL Function applied to LOB Column time ,KingBase The database will be SQL and PL/SQL Create temporary during processing LOB. You should ensure that the temporary table space quota is sufficient to store these temporary for your application LOB.

    SQL Functions may be sensitive to collations , This means that the character value comparison or matching it performs is controlled by the collation . The specific collation used by the function is determined by the collation of the function parameters .

    If SQL The result of the function has a character data type , Then the collation derivation rule defines the collation to associate with the result .

The following is true of Kingbases The functions in the database are classified according to their purposes , Then the usage of each function 、 function 、 Use examples to illustrate .

8.2.  Mathematical functions

The following table shows the KingbaseES Available mathematical functions . In the table ,dp Express double precision. Many of these functions have many different forms , The difference is that the parameters are different . Unless otherwise specified , Any particular form of function returns the same data type as its arguments . Handle double precision Most functions of data are in the host system C Library ; therefore , The accuracy and behavior of boundary cases vary according to the host system .

ABS

BITAND

CBRT

CEIL

CEILING

DEGREES

DIV

EXP

FLOOR

LN

LOG

LOG10

MOD

PI

POWER

RADIANS

ROUND

SCALE

SIGN

SQRT

TRUNC

A function used to generate random numbers .

RANDOM

SETSEED

The following table shows the available trigonometric functions . All trigonometric functions have the type double precision Parameters and return types of . Every trigonometric function has two variants , An angle measured in radians , The other measures angle by angle .

ACOS

ASIN

ATAN

ATAN2

COS

COT

SIN

TAN

The following table shows the available hyperbolic functions . The types of parameters and return values of all these functions are double precision.

SINH

COSH

TANH

ASINH

ACOSH

ATANH

8.3.  String function

This section describes the functions used to check and manipulate string values . Strings in this environment include all types charactercharacter varying and text Value . Unless otherwise stated , All the functions listed below can handle these types , But be careful , In the use of character When it comes to type , It has the potential to automatically fill in blanks . Some functions can also handle bit string types .

SQL Defines some string functions , They use keywords , Instead of separating parameters with commas . Please refer to the table below for details ,KingbaseES Versions of these functions using normal function call syntax are also provided .

Be careful

Due to the existence from those data types to text Implicit enforcement of , stay KingbaseES V8.3 Before , These functions can also accept a variety of non string data types . These enforcement measures have been removed in the current version , Because they often lead to surprising behavior . however , String concatenation operator (||) Still accept non string input , As long as at least one input is a string type , As shown in the following table . In other cases , If you need to copy the previous behavior , It can be for text Insert an explicit enforcement . about || The operator , Support the input of several spaces or newline characters between two characters , The effect is the same as without spaces or line breaks .

BIT_LENGTH

BTRIM

CHAR_LENGTH

CHARACTER_LENGTH

CHARINDEX

CHR

CONCAT

CONCAT_WS

CONTAINS

CONVERT

CONVERT_FROM

CONVERT_TO

DECODING

ENCODE

FORMAT

FORMAT

INITCAP

INSTR

INSTRB

LOWER

OCTET_LENGTH

OVERLAY

POSITION

SUBSTRING

TRIM

UPPER

8.4.  Binary string function

This section describes the types of inspections and operations that are bytea A function of the value of .

SQL Defines some string functions that use keywords instead of commas to separate parameters . Please refer to the table below for details .KingbaseES Versions of these functions using regular function call syntax are also provided .

Be careful

The example results shown on this page assume server parameters bytea_output Set to escape( Tradition KingbaseES Format ).

BLOB_EXPORT

BLOB_IMPORT

BTRIM

DECODING

EMPTY_BLOB

ENCODE

GET_BIT

GET_BYTE

LENGTH

MD5

OCTET_LENGTH

OVERLAY

POSITION

SHA224

SHA256

SHA384

SHA512

SUBSTRING

TRIM

8.5.  Pattern matching function

This section describes KingbaseES Support POSIX Regular expression pattern matching function .

REGEXP_REPLACE

REGEXP_MATCH

REGEXP_SPLIT_TO_TABLE

REGEXP_SPLIT_TO_ARRAY

8.6.  Data type formatting function

KingbaseES Formatting functions provide a powerful set of tools for integrating various data types ( date / Time 、 Integers 、 floating-point 、 Numbers ) Convert to a formatted string and vice versa . The following table lists these functions . These functions follow a common call specification : The first parameter is the value to be formatted , The second is a template that defines the output or input format .

TO_CHAR

TO_DATE

TO_NUMBER

TO_TIMESTAMP

TO_TIMESTAMP_TZ

8.7.  Time date function

The following table shows the dates that can be used to process / Function of time value , The details are described in the following sections . And demonstrates the basic arithmetic operators (+* etc. ) act . Functions related to formatting , You can refer to   Data type formatting function  . You should be familiar with   Date time type   Date in / Background knowledge of time data types .

All acceptances described below time or timestamp There are actually two variants of input functions and operators : A reception time with time zone or timestamp with time zone, Another kind of acceptance time without time zone perhaps  timestamp without time zone. In order to simplify the , These variants have not been shown independently . Besides ,+ and * Operators are interchangeable operator pairs ( for example ,date + integer and integer + date); We only show one .

AGE

CLOCK_TIMESTAMP

CURRENT_DATE

CURRENT_TIME

CURRENT_TIMESTAMP

DATE_PART

DATE_TRUNC

DAYS_BETWEEN

EXTRACT

ISFINITE

JUSTIFY_DAYS

JUSTIFY_HOURS

JUSTIFY_INTERVAL

LOCALTIME

LOCALTIMESTAMP

MAKE_DATE

MAKE_INTERVAL

MAKE_TIME

MAKE_TIMESTAMP

MAKE_TIMESTAMPTZ

MONTH

MONTHS_BETWEEN

NOW

ROUND

SESSIONTIMEZONE

STATEMENT_TIMESTAMP

STR_VALID

SYSDATE

SYS_SLEEP

SYS_SLEEP_FOR

SYS_SLEEP_UNTIL

TIMEOFDAY

TIMESUB

TO_TIMESTAMP

YEAR

8.8.  Enumeration support functions

There are functions that allow cleaner coding for enumerated types , There is no need to write a specific value for an enumeration type . They are listed in the following table in .

enum_first

enum_last

enum_range

8.9.  Geometric functions

Geometric type pointbox、 lseglinepath、 polygon and circle There are a lot of local support functions , As shown in the following list .

BOUND_BOX

BOX

CENTER

CIRCLE

DIAMETER

HEIGHT

ISOPEN

LENGTH

LSEG

RADIUS

8.10.  Network address function

The following table shows all that can be used for cidr and inet Function of type . function abbrevhost It is mainly used to provide optional display formats .

ABBREV

FAMILY

HOST

HOSTMASK

INET_MERGE

INET_SAME_FAMILY

8.11. XML function

The functions described in this section and the expressions of class functions are in type xml Operation on the value of .

Used in values and type xml Expressions of class functions converted between xmlparse and  xmlserialize Don't repeat here .

APPENDCHILDXML

CURSOR_TO_XML

DELETEXML

EXISTSNODE

EXTRACT

EXTRACTVALUE

INSERTCHILDXML

INSERTCHILDXMLAFTER

INSERTCHILDXMLBEFORE

INSERTXMLAFTER

INSERTXMLBEFORE

QUERY_TO_XML

TABLE_TO_XML

UPDATEXML

XMLCOMMENT

XMLCONCAT

XMLELEMENT

XMLEXISTS

XMLFOREST

XMLPI

XMLROOT

XMLTABLE

XML_IS_WELL_FORMED

XML_IS_WELL_FORMED_CONTENT

XML_IS_WELL_FORMED_DOCUMENT

XPATH

XPATH_EXISTS

8.12. JSON function

This section describes how to process and create JSON Functions of data .

ARRAY_TO_JSON

JSONB_ARRAY_ELEMENTS

JSONB_ARRAY_ELEMENTS_TEXT

JSONB_ARRAY_LENGTH

JSONB_BUILD_ARRAY

JSONB_BUILD_OBJECT

JSONB_EACH

JSONB_EACH_TEXT

JSONB_EXTRACT_PATH

JSONB_EXTRACT_PATH_TEXT

JSONB_INSERT

JSONB_OBJECT

JSONB_OBJECT_KEYS

JSONB_PATH_EXISTS

JSONB_PATH_MATCH

JSONB_PATH_QUERY

JSONB_PATH_QUERY_ARRAY

JSONB_PATH_QUERY_FIRST

JSONB_POPULATE_RECORD

JSONB_POPULATE_RECORDSET

JSONB_PRETTY

JSONB_SET

JSONB_STRIP_NULLS

JSONB_TO_RECORD

JSONB_TO_RECORDSET

JSONB_TYPEOF

JSON_ARRAY_ELEMENTS

JSON_ARRAY_ELEMENTS_TEXT

JSON_ARRAY_LENGTH

JSON_BUILD_ARRAY

JSON_BUILD_OBJECT

JSON_EACH

JSON_EACH_TEXT

JSON_EXTRACT_PATH

JSON_EXTRACT_PATH_TEXT

JSON_OBJECT

JSON_OBJECT_KEYS

JSON_POPULATE_RECORD

JSON_STRIP_NULLS

JSON_TO_RECORD

JSON_TO_RECORDSET

JSON_TYPEOF

ROW_TO_JSON

TO_JSON

TO_JSONB

8.13.  Sequence operation function

This section describes the operation   Sequence object   Function of , Sequence objects are also called sequence generators or sequences . Sequence objects are usually used to generate unique identifiers for rows in a table . These sequence functions are listed in the following table , It can provide a simple way for us to obtain continuous sequence values from sequence objects 、 Methods of multi-user security .

CURRVAL

LASTVAL

NEXTVAL

SETVAL

8.14.  Array function

The following table shows the functions that can be used for array types .

ARRAY_APPEND

ARRAY_CAT

ARRAY_DIMS

ARRAY_FILL

ARRAY_LENGTH

ARRAY_LOWER

ARRAY_NDIMS

ARRAY_POSITION

ARRAY_POSITIONS

ARRAY_PREPEND

ARRAY_REMOVE

ARRAY_REPLACE

ARRAY_TO_STRING

ARRAY_UPPER

CARDINALITY

STRING_TO_ARRAY

UNNEST

8.15.  Range function

The following table shows the functions available for range types

ISEMPTY

LOWER

LOWER_INC

LOWER_INF

RANGE_MERGE

UPPER

8.16.  Aggregation function

Aggregation function   Calculate a single value from a set of input values . stay SELECT Nested calls of aggregate functions are supported in the statement ,SELECT Only one level of aggregate function nesting is supported in the list , The query statement must contain GROUP BY Clause .

ARRAY_AGG

AVG

BIT_AND

BIT_OR

BOOL_AND

BOOL_OR

CORR

COUNT

COVAR_POP

COVAR_SAMP

EVERY

JSON_AGG

JSON_OBJECT_AGG

JSONB_AGG

JSONB_OBJECT_AGG

LISTAGG

MAX

MIN

STDDEV

STDDEV_POP

STDDEV_SAMP

STRING_AGG

SUM

VAR_POP

VAR_SAMP

VARIANCE

WM_CONCAT

XMLAGG

8.17.  Window function

Window function Provides the ability to perform calculations on a set of rows related to the current query row .

The following table lists the built-in window functions . Note that these functions must be called using the syntax of window functions ; One OVER Clause is required .

Outside these functions , Any built-in or user-defined generic or statistical aggregation ( That is, unordered sets and hypothetical sets ) Can be used as a window function , See   Aggregation function  . Only if the aggregate function call is followed by a OVER When clause , The aggregate function will work like the window function , Otherwise, they will run in a non window aggregation manner and return a single row for the entire collection .

CUME_DIST

DENSE_RANK

FIRST_VALUE

LAG

LAST_VALUE

LEAD

NTH_VALUE

NTILE

PERCENT_RANK

RANK

RATIO_TO_REPORT

ROW_NUMBER

8.18.  Set return function

This section describes functions that may return more than one line . At present, the series generating function is the most widely used in this class . Other more specific set return functions are described elsewhere in this manual .

GENERATE_SERIES

GENERATE_SUBSCRIPTS

8.19.  System information function

The following table shows several functions that can extract session and system information .

In addition to the functions listed in this section , Some functions related to statistical system also provide system information .

COL_DESCRIPTION

CONNECTIONS

CONVERT

CURRENT_DATABASE

CURRENT_QUERY

CURRENT_SCHEMA

CURRENT_SCHEMAS

FORMAT_TYPE

GETUSERNAME

HAS_ANY_COLUMN_PRIVILEGE

HAS_COLUMN_PRIVILEGE

HAS_DATABASE_PRIVILEGE

HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE

HAS_FUNCTION_PRIVILEGE

HAS_LANGUAGE_PRIVILEGE

HAS_SCHEMA_PRIVILEGE

HAS_SEQUENCE_PRIVILEGE

HAS_SERVER_PRIVILEGE

HAS_TABLE_PRIVILEGE

HAS_TABLESPACE_PRIVILEGE

HAS_TYPE_PRIVILEGE

INET_CLIENT_ADDR

INET_CLIENT_PORT

INET_SERVER_ADDR

INET_SERVER_PORT

SESSION_ID

SESSION_USER

SYS_BACKEND_PID

SYS_FUNCTION_IS_VISIBLE

SYS_GET_CONSTRAINTDEF

SYS_GET_EXPR

SYS_GET_FUNCTION_ARGUMENTS

SYS_GET_FUNCTION_IDENTITY_ARGUMENTS

SYS_GET_FUNCTION_RESULT

SYS_GET_FUNCTIONDEF

SYS_GET_INDEXDEF

SYS_GET_KEYWORDS

SYS_GET_OBJECT_ADDRESS

SYS_GET_RULEDEF

SYS_GET_SERIAL_SEQUENCE

SYS_GET_STATISTICSOBJDEF

SYS_GET_TRIGGERDEF

SYS_GET_USERBYID

SYS_GET_VIEWDEF

SYS_HAS_ROLE

SYS_IDENTIFY_OBJECT

SYS_IDENTIFY_OBJECT_AS_ADDRESS

SYS_KINGBASE_START_TIME

SYS_TABLE_IS_VISIBLE

SYS_TABLESPACE_DATABASES

SYS_TABLESPACE_LOCATION

TRANSACTION_TIMESTAMP

USER

VERSION

8.20.  System management functions

The functions described in this section are used to control and monitor a KingbaseES install . Including configuration setting function 、 Server signal function 、 Backup control function 、 Restore the control function 、 Database object management function 、 Index maintenance function 、 General file access function, etc . See the table below :

CURRENT_SETTING

GET_DISK_INFO

SYS_CANCEL_BACKEND

SYS_COLUMN_SIZE

SYS_DATABASE_SIZE

SYS_INDEXES_SIZE

SYS_LS_DIR

SYS_LS_LOGDIR

SYS_LS_TMPDIR

SYS_LS_WALDIR

SYS_READ_BINARY_FILE

SYS_READ_FILE

SYS_RELATION_FILENODE

SYS_RELATION_FILEPATH

SYS_RELATION_SIZE

SYS_RELOAD_CONF

SYS_SIZE_BYTES

SYS_SIZE_PRETTY

SYS_STAT_FILE

SYS_TABLE_SIZE

SYS_TABLESPACE_SIZE

SYS_TERMINATE_BACKEND

SYS_TOTAL_RELATION_SIZE

原网站

版权声明
本文为[Thousands of sails passed by the side of the sunken boat_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230335356100.html