Results 1 to 6 of 6

Thread: PL/SQL Prompt

  1. #1
    Join Date
    May 2013
    Posts
    2

    Unanswered: PL/SQL Prompt

    Dear all

    I want to do a simple algorithm where the user enters a number and is returned the double of that number. I am beginner to PL/SQL and would like to know how to do. Thank you. I am trying the code below: which is not correct. Could you please help me? Thanks.

    set serveroutput on;
    set verify off;
    num integer;
    dobnum integer;
    accept num prompt 'Digite um número: ';
    BEGIN
    dobNum:=num+num;
    prompt dobNum;
    END;

    Carlos Junior
    Database Administrator and Data Architect
    -------------------------------------
    Blog do DBA - Responsabilidade em TI
    @carlosxbjunior (twitter)
    carlosxbjunior@gmail.com
    -------------------------------------

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    There is a difference between SQL & PL/SQL languages.
    What is valid is one language may not be valid in the other language.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    SQL*Plus does it directly:
    Code:
    SQL> select &give_me_a_number * 2 doubled from dual;
    Enter value for give_me_a_number: 2
    
       DOUBLED
    ----------
             4
    
    SQL>
    PL/SQL? That would be a function, I guess. Something like
    Code:
    SQL> create or replace function f_double (par_number in number)
      2    return number
      3  is
      4  begin
      5    return (par_number * 2);
      6  end;
      7  /
    
    Function created.
    
    SQL> select f_double(2) from dual;
    
    F_DOUBLE(2)
    -----------
              4
    
    SQL>

  4. #4
    Join Date
    May 2013
    Posts
    2

    PL/SQL Prompt

    Hi all

    Thanks.

    I've done this algorithm in Pascal, C++ and Java:

    PASCAL
    Program AlgoritmoP001;
    uses
    crt;
    var
    num, dob: real;
    Begin
    Clrscr;
    Gotoxy(01,01);
    write('Digite um número: ');
    readln(num);
    dob := num + num;
    Gotoxy(01,02);
    writeln('O dobro desse número é: ',dob:2:2);
    readln();
    End.
    C
    main() {
    float num, dob;
    printf("Digite um número: ");
    scanf("%f",&num);
    dob = num + num;
    printf("O dobro desse número é: %f",dob);
    getch();
    }
    JAVA
    import javax.swing.JOptionPane;
    class AlgoritmoJ001{
    public static void main(String args[]){
    float num, dobNum;
    num = Float.parseFloat(JOptionPane.showInputDialog("Digi te um número:"));
    dobNum = num + num;
    JOptionPane.showMessageDialog(null,"O dobro desse número é: " +dobNum);
    }
    }


    I just wanna do the same in PL/SQL. I am very beginner on it.

    I am very close with this one below:

    set serveroutput on;
    set verify off;
    num integer;
    dobnum integer;
    accept num prompt 'Digite um número: ';
    BEGIN
    dobNum:=num+num;
    prompt dobNum;
    END;

    Problem is that dobNum does not return the "num + num". Any chance to do something similar to the code above?

    Thanks.

    Carlos (jbxc)

  5. #5
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    ACCEPT & PROMPT commands only exist for sqlplus & do not exist for PL/SQL
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  6. #6
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Your main problem seems to be the fact that you know what you want, you heard of "SQL, PL/SQL and SQL*Plus" (but misuse and confuse these names), you don't know enough about any of these products and you'd like to produce a solution based on a very poor knowledge.

    Well, bad news for you: that's not the way it goes. First, choose a tool - will it be SQL or PL/SQL? Then get familiar with its capabilities and rules you should follow when using that tool. Pascal, C++ and Java? Fine, but these are not (PL/)SQL. Finally, write a program.

    I suggested two options (SQL and PL/SQL); how come none of these satisfy your needs?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •