Is there a way to automatically declare a varchar2 constant with the needed size?

时间:2015-06-30 13:55:37

标签: oracle plsql

Is there a way to declare a varchar2 constant with the needed size?

e.g. I would like to have the following definition without having to explicitly declare the size in parenthesis:

c_my_string constant varchar2(3) := 'abc';

Is there a way to do something like:

c_my_string constant varchar2(sizeof('abc')) := 'abc';

Other than that I could of course define the constant as a raw and then convert it to a varchar2 on the fly using UTL_RAW.CAST_TO_VARCHAR2(my_raw);

2 个答案:

答案 0 :(得分:0)

我认为你可以使用本地函数,然后像变量那样引用它:

declare
  function f_my_string return varchar2 is
  begin
    return 'abc';
  end;
begin
  dbms_output.put_line(f_my_string);
end;
/

不知道你为什么要这么复杂。

答案 1 :(得分:0)

如果使用char类型,则不需要指定最大长度,因此这应该有效:

enter the no. of nodes to be created
6
enter the value for the node
a
enter the value for the node
enter the value for the node
enter the value for the node
m
enter the value for the node
enter the value for the node
a
m