SQL * Plus如何从提示中接受文本变量? [英] SQL*Plus how to accept text variable from prompt?

查看:78
本文介绍了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:\n%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如何从提示中接受文本变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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