Home Common Problem what is oracle function

what is oracle function

Jun 06, 2023 am 10:15 AM
oracle function

The oracle function is a PL/SQL subroutine. It is stored in the Oracle database as a database object. It will process the parameters passed in and return a processing result, that is, return a value. It is usually used to return a specific Data, oracle functions can be divided into two categories: system functions and user-defined functions.

what is oracle function

The operating environment of this tutorial: Windows 10 system, Oracle version 19c, Dell G3 computer.

Definition of Oracle function

Function is stored in the oracle database as a database object, and the function is also called a PL/SQL subroutine.

The function will process the parameters passed in and return a processing result, that is, return a value. Usually used to return specific data.

Oracle functions can be divided into two categories: system functions and user-defined functions.

ORACLE function single-line function

  • Does not change the real data, only further modifies or processes the data for display
  • Can be mixed with fields Use

    pseudo table: a real table that exists temporarily to facilitate data verification; table name: dual

1. Character function

##initcap(char) Capitalize the first letterinitcap('nice')Nicelower(char) Convert to lowercaselower('NICE')niceupper(char)Convert to uppercaseupper('nice')NICE##ltrim(char,set)rtrim(char,set)##concat(char1,char2)String concatenationconcat(' ni','ce')nicesubstr(char,pos,len)Get substringsubstr ('nice',2,2)icinstr(char,substr)Check substring position instr('nice','c')3Map translation by character##replace(char,old,new) String replacementreplace('nice','c','cc')nicce
Function name Function Example Result
left shear ltrim( 'nice','ni') ce
Right cut rtrim(' nice','e') nic
##translate(char,key,value)
translate('nice','ne','01') 0ic1
2. Numerical function

Function name

FunctionExampleResultGet the absolute valueabs(-3)##mod( m,n)Modulemod(3,2)1sign(n)Get the signsign(-3)-1ceil(n)Round upceil(3.2)4floor(n)Round downfloor( 3.2)33.24923.2301
##abs(n)
3
##round(m,n) Round to the specified number of decimal places round(3.236,2 )
power(m,n) m to the nth power power(3,2)
sqrt(n) square root sqrt(4)
trunc(m,n) Truncation trunc(3.233,2)
sin(n) sine sin(0)
cos(n) cosine cos(0)

3.Date function

Function name Function Example Result
months_between(date1,date2) Returns the months between two days (if date1 is earlier than date2 in the calendar, a negative number is returned, otherwise a Positive number) months_between('01-August-2020','01-August-2020') 0
add_months( date,m) Returns the new date with the number of months added to the date add_months('25-August-2020',-1) 25-7 Month-2020
next_day(date,week) Returns the new date corresponding to the week after the specified new date next_day('23-8 Month-2020', 'Monday') 24-August-2020
last_day(date) Returns the month of the specified date Last day last_day('25-August-2020') 31-August-2020
round(date,p) Round the date according to the specified format round(to_date('25-August-2020'),'YEAR') 1-January-2021
trunc(date,p) Truncate the date in the specified way trunc(to_date('25-8 month-2020'),'YEAR ') 01-January-2020

Note:

  • p is YEAR, round is from January to June and July-December, rounded to the nearest January of year yyyy; trunc is intercepted to the first day of this year.
  • p is MONTH, round is based on days 1-15 and 16-30, rounded to the 1st of the nearest mm month; trunc is intercepted to the first day of this month.
  • p is DAY, round is based on Monday to Wednesday and Thursday to Sunday, rounded to the nearest Sunday. trunc is intercepted to the first day of this week.

Oracle function multi-row function

  • Perform statistics on query data
  • Cannot be combined with ordinary fields and single rows Functions are mixed unless grouped

    ##max( Field name)Returns the maximum value of the fieldmin(Field name)Returns the minimum value of the fieldsum(field name)Returns the sum of the fieldavg(field name)Returns the average value of the fieldcount(*)Returns the number of table recordscount(field name)Returns non-null Number of valuescount(distinct field name)Returns the number of field values ​​after deduplication
    Function name Function

Oracle function conversion function

  • to_number (numeric type character): Convert characters to numerical values

  • to_char (numeric value or date): Convert a numerical value or date into a character

    Specify the display format:

    9 represents a placeholder, for example: 999,999,999 will separate the numbers in groups of three commas open.

    0 means occupancy. If the actual data digits are insufficient, 0 will be used to fill the digits.

    L represents the RMB symbol, $ represents the US dollar symbol.

    Note: Implicit conversion between numerical values ​​and characters is possible.

  • to_date (characters in date format): Convert characters to dates (generally added for new use, query with to_char)

    Common date format: yyyy-mm-dd

    yyyy/mm/dd

    'yyyy"year"mm"month"dd"day"'

    Note: The characters must conform to the date format; Oracle's default conversion format is Day, month and year, for example '25-August-2020'.

Other functions of oracle functions

  • nvl (field name, new value): If the field value is not If it is null, the field value is returned; if it is null, the new value is returned.

  • nvl2 (field name, process 1, process 2): If the field value is not null, process 1 is executed; if it is null, process 2 is executed.

  • decode (field name, value 1, processing 1, value 2, processing 2, value 3, processing 3, ..., public processing): If the field value and the condition in decode If the values ​​are the same, the corresponding processing will be performed. If there are none, public processing is performed.

The above is the detailed content of what is oracle function. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.