Oracle PL/SQL打印字符串的每个字母 [英] Oracle PL / SQL printing each letter of a string

查看:138
本文介绍了Oracle PL/SQL打印字符串的每个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要单独打印出"Hello"一词的字母,这是我写的:

I need to print out the letters of the word 'Hello' each on it's own , I wrote this :

Declare
c1 Number:=1;
c2 Varchar2(5);
begin
for c1 in 1..5
loop
select substr('Hello' , c1 , 1 ) into c2 from dual;
dbms_output.put_line(c2);
end loop;
end;

但它会跳过前两个字母,而输出是

but it skips the first two letter and the out is

l
l
o

任何想法可能是什么问题? 谢谢.

any ideas what might be the problem? Thank you.

推荐答案

最好具有循环结束限制For i in 1..v_length这样,您不必在每次运行时都更改Loop限制.

Better to have Loop end limit For i in 1..v_length This way you do not have to change the Loop limit each time you run.

 Create or replace procedure print_string( IN_string IN varchar2 )
AS
v_length number(10);
v_out varchar2(20);
Begin
v_length := length(IN_string);
for i in 1..v_length
Loop
v_out  := substr(IN_string,i,1) ;
DBMS_OUTPUT.PUT_LINE(v_out);
End loop;
DBMS_OUTPUT.PUT_LINE('Text printed: ' || IN_string);
End;
 -- Procedure created.

BEGIN
print_string('Hello');
END;


-- Output:

H
e
l
l
o
Text printed: Hello

Statement processed.

这篇关于Oracle PL/SQL打印字符串的每个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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