문제

Following from the below question, I have a query:

Declaring a variable and setting its value from a SELECT query in Oracle

Query:

Is it possible to write some equivalent oracle statement for the following SQL statement:

    declare @var_name nvarchar(5)='Vinay'
    select @var_name    

I know the question is far too basic, but i am just a beginner in Oracle, and would appreciate if you guys could also help me learning it. Thanks in advance.

도움이 되었습니까?

해결책

  1. Oracle variables are not prefixed with @ like in SQL Server.
  2. Oracle queries must have a FROM clause; there is a system-provided dummy table called DUAL for this
  3. In Oracle, the line between SQL code and procedural code is far harder than in SQL Server.

If all you want to do is print out the value of a variable, you will need to do something like this:

DECLARE
  var_name NVARCHAR2(5) := 'Vinay';
BEGIN
  -- Enable printing
  DBMS_OUTPUT.ENABLE();
  -- Print the value
  DBMS_OUTPUT.PUT_LINE(var_name);
END;
/

Note: If you are doing this in SQL*Plus, you must issue SET SERVEROUTPUT ON to see the result.

다른 팁

I hope this should work

DECLARE
   var_name varchar2(5) := 'Vinay' ;

BEGIN
   DBMS_OUTPUT.PUT_LINE(var_name);
END;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top