在循环中创建var plsql oracle 11g

发布于 2025-01-26 04:02:21 字数 593 浏览 3 评论 0原文

我的功能将数字放在var(var1)中。如果var1 = 3,则创建 3 新变量,并为以后在OUT类型中发送该值的值。我不知道该怎么做,我的代码是这样的,其中“ pos”的作用就像instr()我知道它的每个 13 < /strong> chars。和“ newvar || var1”是因为我希望我的var名称为newvar1newvar2newvar3等。

FOR n IN 1..var1
LOOP
  pos          NUMBER(4):= 0;
  newvar||var1 NUMBER(3);
  newvar||var1 := SUBSTR(TO_NUMBER(numberInsideString), 1, 1+pos);
  pos := pos+13;
END LOOP;

​谢谢。

i have a function that puts a number in a var (var1). if var1 = 3 then create 3 new variables and assign a value for later send that values in an out type. I don't know how can i do, my code is something like this where "pos" acts like an INSTR() that i know its each 13 chars. And "newvar||var1" is because i want my vars names be newvar1, newvar2, newvar3, etc.:

FOR n IN 1..var1
LOOP
  pos          NUMBER(4):= 0;
  newvar||var1 NUMBER(3);
  newvar||var1 := SUBSTR(TO_NUMBER(numberInsideString), 1, 1+pos);
  pos := pos+13;
END LOOP;

My question is, how a person who really know PLSQL would do that, im learning PLSQL please help. thank you.

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

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

发布评论

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

评论(1

行至春深 2025-02-02 04:02:21

您想尝试做的事情表明,您需要一个维数数组,以重复为循环中的每个迭代分配新值。 OWA 的类型之一,例如 vc_arr varchar2 组成代码>数据类型值)很方便地定义数组。

进入代码,您可以从将变量移动到声明部分开始,然后编写一个简单的代码,例如示例练习

SET serveroutput ON

DECLARE
  pos                INT := 0;
  numberInsideString VARCHAR2(100):='as12df34sdg345apl8976gkh4f11öjhöh678u7jgvj';
  newvar             OWA.vc_arr;
BEGIN
  FOR n IN 1..3
  LOOP    
    newvar(n) := SUBSTR(numberInsideString, 1, 1+pos);
    pos := pos+5;
    Dbms_Output.Put_Line(newvar(n));
  END LOOP;  
END;
/
a
as12df
as12df34sdg

What you want to try to do suggests that you need a one dimensional array in order repeatedly to assign new values for each iteration within the loop. One of the types in OWA package such as vc_arr(composed of VARCHAR2 data type values) is handy to define an array.

Coming to the code, you can start with moving the variables into the declaration section, and write such a simple code as a sample exercise

SET serveroutput ON

DECLARE
  pos                INT := 0;
  numberInsideString VARCHAR2(100):='as12df34sdg345apl8976gkh4f11öjhöh678u7jgvj';
  newvar             OWA.vc_arr;
BEGIN
  FOR n IN 1..3
  LOOP    
    newvar(n) := SUBSTR(numberInsideString, 1, 1+pos);
    pos := pos+5;
    Dbms_Output.Put_Line(newvar(n));
  END LOOP;  
END;
/
a
as12df
as12df34sdg
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文