插入字符串&在PLSQL中显示该字符串的字符

发布于 2025-02-12 07:26:18 字数 134 浏览 1 评论 0原文

编写一个函数以将字符串插入表中,该表将显示字符串的字符,就像我们通过的情况一样(奎师那将显示

k

r

i

s

h

n

a
)在桌子内。

Write a function to insert the string in a table which will display the character of string like if we pass (KRISHNA it will display

K

R

I

S

H

N

A
) Inside the table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-02-19 07:26:18

这是一个选项:

示例表:

SQL> create table test (source_string varchar2(20), target_string varchar2(20));

Table created.

过程:

SQL> create or replace procedure p_test (par_string in varchar2) is
  2  begin
  3    insert into test (source_string, target_string)
  4    select par_string,
  5           regexp_replace(par_string, '(.)', '\1' ||chr(10))
  6    from dual;
  7  end;
  8  /

Procedure created.

测试:

SQL> exec p_test ('KRISHNA');

PL/SQL procedure successfully completed.

SQL> select * from test;

SOURCE_STRING        TARGET_STRING
-------------------- --------------------
KRISHNA              K
                     R
                     I
                     S
                     H
                     N
                     A


SQL>

如果必须是一个函数,那么 - 如您所见 的做法 - 您可以自己切换到(功能),而不是坚持别人做你的作业。

无论如何:

SQL> create or replace function f_test (par_string in varchar2)
  2    return varchar2
  3  is
  4  begin
  5    return regexp_replace(par_string, '(.)', '\1' ||chr(10));
  6  end;
  7  /

Function created.

SQL> insert into test (source_string, target_string)
  2  values ('IHCASAYBAS', f_test ('IHCASAYBAS'));

1 row created.

结果:

SQL> select * from test;

SOURCE_STRING        TARGET_STRING
-------------------- --------------------
KRISHNA              K
                     R
                     I
                     S
                     H
                     N
                     A

IHCASAYBAS           I
                     H
                     C
                     A
                     S
                     A
                     Y
                     B
                     A
                     S


SQL>

Here's one option:

Sample table:

SQL> create table test (source_string varchar2(20), target_string varchar2(20));

Table created.

Procedure:

SQL> create or replace procedure p_test (par_string in varchar2) is
  2  begin
  3    insert into test (source_string, target_string)
  4    select par_string,
  5           regexp_replace(par_string, '(.)', '\1' ||chr(10))
  6    from dual;
  7  end;
  8  /

Procedure created.

Testing:

SQL> exec p_test ('KRISHNA');

PL/SQL procedure successfully completed.

SQL> select * from test;

SOURCE_STRING        TARGET_STRING
-------------------- --------------------
KRISHNA              K
                     R
                     I
                     S
                     H
                     N
                     A


SQL>

If it has to be a function, then - as you see how to do it - you could have switched to it (the function) yourself, instead of insisting on someone else doing your homework.

Anyway:

SQL> create or replace function f_test (par_string in varchar2)
  2    return varchar2
  3  is
  4  begin
  5    return regexp_replace(par_string, '(.)', '\1' ||chr(10));
  6  end;
  7  /

Function created.

SQL> insert into test (source_string, target_string)
  2  values ('IHCASAYBAS', f_test ('IHCASAYBAS'));

1 row created.

Result:

SQL> select * from test;

SOURCE_STRING        TARGET_STRING
-------------------- --------------------
KRISHNA              K
                     R
                     I
                     S
                     H
                     N
                     A

IHCASAYBAS           I
                     H
                     C
                     A
                     S
                     A
                     Y
                     B
                     A
                     S


SQL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文