1
ACCEPT scale PROMPT 'Enter your input scale (C or F) for temperature: ';
ACCEPT temp PROMPT 'Enter your temperature value to be converted: ';
DECLARE
v_scale CHAR(1) := UPPER('&scale');
v_temp NUMBER := '&input';

BEGIN

IF (v_scale) = ('F') THEN
   v_temp := (v_temp - 32) * 5/9;
   DBMS_OUTPUT.PUT_LINE ('You converted temperature in C is exactly ' || TO_CHAR(v_temp));

ELSIF (v_scale) = ('C') THEN
   v_temp := (v_temp * 9/5) + 32;
   DBMS_OUTPUT.PUT_LINE ('You converted temperature in F is exactly ' || TO_CHAR(v_temp));

ELSE
   DBMS_OUTPUT.PUT_LINE ('This is NOT a valid scale. Must be C or F.');

END IF;

END;

/

When I run the code it ask me for the 2 inputs which I enter like F and 100. Then it only displays "PL/SQL procedure successfully completed".

It looks like it never runs the DBMS_OUTPUT.PUT_LINE ?? How come?? I am new to pl sql so sorry for any newvie mistakes above

Thanks

SVL
  • 33
  • 4
  • 1
    `DBMS_OUTPUT` only puts output in the output buffer, not on screen. To see stuff on screen, you must also issue the command `SET SERVEROUTPUT ON`. Do that before the `ACCEPT` statements. –  Oct 03 '18 at 23:17

1 Answers1

1

Try to add SET SERVEROUTPUT ON at the beginning of your script.

sticky bit
  • 36,626
  • 12
  • 31
  • 42
  • The semicolon is not necessary; `SET` is a UI command (SQL\*Plus), which does not need a semicolon to show where it ends. –  Oct 03 '18 at 23:18
  • @mathguy: I did wonder about that indeed. But then went to put it in the believe it doesn't harm either. Or does it? Anyway, I'll remove it. – sticky bit Oct 03 '18 at 23:25
  • It does no harm - SQL\*Plus ignores it, and so does the emulator in SQL Developer. I don't know about other apps that either use or emulate SQL\*Plus though. And for a beginner (like our OP), it is good to draw as many distinctions as possible between SQL (the database server's language), PL/SQL (a procedural programming language), and the scripting language used by the interface. The latter needs neither semicolons nor slashes, and the fact that they execute without either shows that the UI commands are neither SQL nor PL/SQL. –  Oct 03 '18 at 23:27
  • @Kurai - that is a different question, for which you should start a new thread. In any case - the mistake is in your code, not in the math. You are prompting for a variable `temp`, but then in the block you use `&input`. Change that to `&temp`, and it should work. Also, you shouldn't need single quotes around it, since it's a number, not a string. –  Oct 03 '18 at 23:45