


A relatively complex stored procedure for splitting strings multiple times
The special split function I wrote is as follows:
##create or replace function FN_SPLIT_STR_2(var_str in varchar2)return varchar2
/*
There is a table t1 with a field called c3, which stores the location information of all stores.
Now we need a stored procedure to reduce the coordinate values of the c3 field of all records by 3 times and write the content of the c field
For example, 220.25 257,220.25 269.75,229.25 269.75,229.25 257
Each comma separates the coordinate points, and each coordinate point uses a space to distinguish the x coordinate and y coordinate
Storage function name: FN_SPLIT_STR_2
Purpose: Reduce bis_store coordinates v_coords3 three times and update coords, such as
author:huangshan
*/
as var_tmp varchar2(4000); var_element varchar2(4000); var_result varchar2(4000); var_instr_first number; var_instr_second number; var_length number;
##begin var_tmp := var_str;
var_instr_first :=0;
var_instr_second :=0;
var_result :='';
var_length:=0;
## /* Replace the passed Special characters
chr (9) Tab character
chr (10) Carriage return
chr (13) Line feed
*/
##
var_tmp:= replace(var_tmp,chr(10),''); var_tmp:= replace(var_tmp,chr(13),''); var_tmp:= replace(var_tmp,chr(9),''); while instr(var_tmp, ' ') > 0 or instr(var_tmp, ',')>0 or(var_length>0) loop var_instr_first :=instr(var_tmp, ' '); var_instr_second :=instr(var_tmp, ','); -- dbms_output.put_line('var_instr_kg:'||var_instr_first||' '); -- dbms_output.put_line('var_instr_dh:'||var_instr_second||' '); var_length:=length(var_tmp); -- dbms_output.put_line('var_length :'||var_length||' ');
/* 1 If there is a space first, such as 12 32, 12 32, etc. **/
if var_instr_first<var_instr_second then var_element := round(to_number(substr(var_tmp, 1, var_instr_first-1))/3,2); var_result := var_result|| var_element|| ' '; var_tmp := substr(var_tmp,var_instr_first+1, length(var_tmp)); -- dbms_output.put_line('var_result kg:'||var_result); -- dbms_output.put_line('var_tmp kg:'||var_tmp||' '); -- dbms_output.put_line('var_element kg:'||var_element||' ');
/* 2 If the spaces have been intercepted, the comma is in front, such as 32,12 32**/
elsif var_instr_first>var_instr_second and var_instr_second>0 then var_element := round(to_number(substr(var_tmp, 1, var_instr_second-1))/3,2); var_result := var_result || var_element || ',' ; var_tmp := substr(var_tmp,var_instr_second+1, length(var_tmp)); -- dbms_output.put_line('var_result dh:'||var_result); -- dbms_output.put_line('var_tmp dh:'||var_tmp||' '); -- dbms_output.put_line('var_element dh:'||var_element||' ');
/* 3 如果是已经截取完逗号,已经只剩下最后一个坐标x y,比如12 32这类 **/
elsif var_instr_first>var_instr_second and var_instr_second=0 then var_element := round(to_number(substr(var_tmp, 1, var_instr_first-1))/3,2); var_result := var_result|| var_element|| ' '; var_tmp := substr(var_tmp,+1, length(var_tmp)); -- dbms_output.put_line('var_result kg:'||var_result); -- dbms_output.put_line('var_tmpvar_instr_first kg:'||var_tmp||' '); -- dbms_output.put_line('var_element kg:'||var_element||' ');
/* 4 如果是已经截取到最后一个坐标,比如32这类 **/
elsif var_instr_first=0 and var_instr_second=0 and var_length>0 then -- dbms_output.put_line('var_tmp the last one:'||var_tmp||' '); var_element := round(to_number(var_tmp)/3,2); var_result := var_result || var_element; var_tmp:=''; -- dbms_output.put_line('var_result 0:'||var_result); -- dbms_output.put_line('var_tmp 0:'||var_tmp||' '); -- dbms_output.put_line('var_element 0:'||var_element||' ');
/* 5 如果其他的东西,设置成''退出while循环为止 **/
else var_tmp:=''; end if; -- dbms_output.put_line(' '); end loop; return var_result; end FN_SPLIT_STR_2;
-- google其他人的拆分function如下:
-- 拆分函数
create or replace function split_str(var_str in varchar2, var_split in varchar2) /**************************************************** 注意 先执行下面语句 创建类型 create or replace type t_ret_table is table of varchar2(100) ** 函数名称:split_str ** 参 数:【名称】 【类型 】 【说明】 ** var_str varchar2 要拆分的字符串 ** var_split varchar2 字符串分隔符 ** 返 回 值:Result t_ret_table 拆分后数组集合 ** 摘 要:拆分字符串 调用 举例: select * from table(split_str('2008-10-21','-')) ****************************************************/ return t_ret_table is var_out t_ret_table; var_tmp varchar2(4000); var_element varchar2(4000);
begin
var_tmp := var_str; var_out := t_ret_table(); --如果存在匹配的分割符 while instr(var_tmp, var_split) > 0 loop var_element := substr(var_tmp, 1, instr(var_tmp, var_split) - 1); var_tmp := substr(var_tmp, instr(var_tmp, var_split) + length(var_split), length(var_tmp)); --var_out.extend(1); var_out.extend; var_out(var_out.count) := var_element; end loop; --var_out.extend(1); var_out.extend; var_out(var_out.count) := var_tmp; return var_out; end split_str;
以上就是一个比较复杂的多次拆分字符串的存储过程的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Title: Steps and Precautions for Implementing Batch Updates by Oracle Stored Procedures In Oracle database, stored procedures are a set of SQL statements designed to improve database performance, reuse code, and enhance security. Stored procedures can be used to update data in batches. This article will introduce how to use Oracle stored procedures to implement batch updates and provide specific code examples. Step 1: Create a stored procedure First, we need to create a stored procedure to implement batch update operations. The following is how to create a stored procedure

Title: How to determine whether a string ends with a specific character in Golang. In the Go language, sometimes we need to determine whether a string ends with a specific character. This is very common when processing strings. This article will introduce how to use the Go language to implement this function, and provide code examples for your reference. First, let's take a look at how to determine whether a string ends with a specified character in Golang. The characters in a string in Golang can be obtained through indexing, and the length of the string can be

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

How to check if a string starts with a specific character in Golang? When programming in Golang, you often encounter situations where you need to check whether a string begins with a specific character. To meet this requirement, we can use the functions provided by the strings package in Golang to achieve this. Next, we will introduce in detail how to use Golang to check whether a string starts with a specific character, with specific code examples. In Golang, we can use HasPrefix from the strings package

Go language is a powerful and flexible programming language that provides rich string processing functions, including string interception. In the Go language, we can use slices to intercept strings. Next, we will introduce in detail how to intercept strings in Go language, with specific code examples. 1. Use slicing to intercept a string. In the Go language, you can use slicing expressions to intercept a part of a string. The syntax of slice expression is as follows: slice:=str[start:end]where, s

Methods to solve Chinese garbled characters when converting hexadecimal strings in PHP. In PHP programming, sometimes we encounter situations where we need to convert strings represented by hexadecimal into normal Chinese characters. However, in the process of this conversion, sometimes you will encounter the problem of Chinese garbled characters. This article will provide you with a method to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP, and give specific code examples. Use the hex2bin() function for hexadecimal conversion. PHP’s built-in hex2bin() function can convert 1

Stored procedures in Oracle database are a specific type of stored procedures used to execute a series of SQL statements and data operations in the database. In actual database development work, sometimes we need to determine whether a certain table exists in the database, so that we can do some judgment and logical processing in the storage process. Below we will introduce how to implement the method of determining whether a table exists in Oracle database, and provide specific code examples. First, we can use the system table user_tables or all_t
