What is the simplest way to define a local variable in Oracle?

前端 未结 5 1004
我在风中等你
我在风中等你 2021-01-05 07:43

In the SQL Server, I can define local variables like this.

declare @id number := 1000

select * from tbl_A where id = @id;
select * from tbl_B where id = @id         


        
5条回答
  •  迷失自我
    2021-01-05 08:06

    (Just stumbled across this thread.) Beginning with SQL*Plus 12.2, you can declare and assign a value at the same time:

    SQL> var id number = 1000

    SQL> select * from tbl_A where id = :id;

    Oracle calls it input binding.

    If you must do it in PL/SQL, the answer was given by others.

提交回复
热议问题