Declaring variable type based on a column type

后端 未结 2 1887
忘掉有多难
忘掉有多难 2020-12-18 18:26

In Oracle\'s PL-SQL, you can declare a variable and define its type based on a table column:

declare var1 table.column%TYPE;

Is it possible

2条回答
  •  有刺的猬
    2020-12-18 19:03

    It may skirt the real issue, but you can "cheat" a little bit by

    Select *
    INTO #tmp
    From MyTable
    Where 1 = 0
    

    Will automatically create a temp table with all columns with correct data types.

提交回复
热议问题