愿所有的美好和期待都能如约而至

SQL*Plus 如何从提示中接受文本变量?

发布时间:  来源:互联网  作者:匿名  标签:error SQL*Plus how to accept text variable from prompt? exception IT资讯 oracle pl  热度:37.5℃

本文介绍了SQL*Plus 如何从提示中接受文本变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 psql 的初学者,我有一个问题.

Im very beginner in psql and i have a question.

代码如下:

SET serveroutput ON
ACCEPT myVariable PROMPT "Input value: ";

BEGIN
  dbms_output.put_line('My input variable is: '||&myVariable);
 END;

问题很简单:如何将文本传递给我的变量?如果我输入一个数字,它可以正常工作并且我可以在日志中读取我的数字,但是如果我传递像mytext”这样的文本而不是数字,我会收到一个错误:

Question is very simple: How can i pass text to my variable? If i input a number it is works correctly and i can read in the log my number, but if i pass a text like “mytext” instead of a number, i got an error:

    old:BEGIN


     dbms_output.put_line('My input variable is: '||&myVariable);
     END;


    new:BEGIN

  dbms_output.put_line('My input variable is: '||mytext);
 END;

    Error starting at line 5 in command:
    BEGIN
      dbms_output.put_line('My input variable is: '||&myVariable);
     END;
    Error report:
    ORA-06550: 2 sor, 50 oszlop:
    PLS-00201: identifier 'MYTEXT' must be declared
    ORA-06550: 2 sor, 3 oszlop:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:
%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:

推荐答案

您必须指定数据类型作为 接受声明.如果没有给出,则假定一个数字.

You have to specify the data type as part of the ACCEPT statement. If none is given, it assumes a number.

尝试 ACCEPT myVariable CHAR PROMPT 'Input value: '; 代替.

这篇关于SQL*Plus 如何从提示中接受文本变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP