2011年9月6日

ORACLE(PLSQL) insert into 和 Select into

底下是示範PLSQL insert into 和select into的語法:

  • PL SQL 等同TSQL的Select into
    CREATE TABLE [New Table Name] AS SELECT * FROM [Table Name]
  • PL SQL 等同TSQL的 insert into select
    INSERT ALL INTO [Table Name 1] SELECT * FROM [Table Name 2]
    OR
    INSERT INTO [Table Name 1] ([Column Name]+)
    SELECT [Column Name]+ FROM [Table Name 2]
  • PL SQL 的slect into是將欄位放到一個變數裡

    v_column my_table.column%TYPE; BEGIN BEGIN select column into v_column from my_table where ...;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    v_column
    := NULL; END; ... use v_column here END;

沒有留言:

張貼留言