如何在PL/SQL中查找字符串中不同字符的计数和名称 [英] How to find count and names of distinct characters in string in PL/SQL

查看:110
本文介绍了如何在PL/SQL中查找字符串中不同字符的计数和名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PL/SQL的新手,我需要获取字符串中不同字符的名称和计数.例如.如果我有字符串str="helloexample",则需要获取str中不同字符的输出,即heloxamp.

I'm quite new to PL/SQL and I need to get the names and count of the distinct characters in a string. E.g. if I have a string str="helloexample", I need to get output of distinct characters in str, i.e. heloxamp.

我该怎么做?

推荐答案

您可以使用正则表达式,如下所示:

You can use regular expression as follows:

SET serveroutput ON
DECLARE
     str        VARCHAR2(20):='helloexample';
     str_length NUMBER;
     c          VARCHAR2(20):=NULL;
     d          NUMBER;
BEGIN
     str_length:=LENGTH(str);
     FOR i IN 1..str_length
     LOOP
          IF regexp_instr(c,SUBSTR(str,i,1))>0 THEN
               NULL;
          ELSE
               c:=c||SUBSTR(str,i,1);
          END IF;
     END LOOP;
     dbms_output.put_line(c);
END;

答案将是:

heloxamp

这篇关于如何在PL/SQL中查找字符串中不同字符的计数和名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆