Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
914 views
in Technique[技术] by (71.8m points)

oracle - SQL*Plus how to accept text variable from prompt?

Im very beginner in psql and i have a question.

Here is the code:

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

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

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:
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Try ACCEPT myVariable CHAR PROMPT 'Input value: '; instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...