写一段oracle存储过程,实现一串字符的去重
时间: 2023-03-12 07:35:01 浏览: 93
将长于4000字符的字符串转化为CLOB类型存入数据库
4星 · 用户满意度95%
我可以提供一个参考:CREATE OR REPLACE PROCEDURE remove_duplicates(str_in IN VARCHAR2)
AS
-- define a variable to store the output string
result_str VARCHAR2(2000);
-- define a variable to store characters
c VARCHAR2(1);
-- define a variable to store the last character
last_c VARCHAR2(1);
BEGIN
-- initialise the output string
result_str := '';
-- initialise the last character
last_c := '';
-- loop through the input string
FOR i IN 1..length(str_in) LOOP
-- get the next character
c := substr(str_in, i, 1);
-- check if the current character is different to the last one
IF c != last_c THEN
-- add the character to the output string
result_str := result_str || c;
-- set the last character to be the current one
last_c := c;
END IF;
END LOOP;
-- output the resulting string
dbms_output.put_line(result_str);
END;
阅读全文