SQL column name same as PL/SQL variable name - How can this be done in a select statement?

后端 未结 5 1390
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 20:10

Suppose I have a table:

create table foo (
  col_1     number;
  col_2     number;
);

Then I have the following code

declar         


        
5条回答
  •  情深已故
    2020-12-19 20:31

    Try this:

       declare
           col_1    number;
           col_2    number;
        begin
           col_1 := 1;
           select foo.col_2 into col_2 from foo where foo.col_1 = col_1;
    
           dbms_output.put_line(col_2);
    
        end;
    /
    

    Table name or synonym says that it entity linked to the table. Also you can use procedure name, if you do the procedure name.

    for example, if proc name is DO, you can do the following:

       select foo.col_2 into DO.col_2 from foo where foo.col_1 = DO.col_1;
    

提交回复
热议问题