熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

PL/SQL的幾個概念區別

2022-06-13   來源: Oracle 

  char 和 varchar的區別

  varchar variablelength 變長

  char fixedlength 固定長度

  char定義的時候分配內存而varchar動態分配內存

  下面一個例子明確的說明了這兩個的區別

  SQL> DECLARE

   c CHAR() := ;

   v VARCHAR() := ;

   BEGIN

   dbms_outputput_line(c is [||LENGTH(c)||]);

   dbms_outputput_line(v is [||LENGTH(v)||]);

   v := v || ;

   dbms_outputput_line(v is [||LENGTH(v)||]); END;

   /

  c is []

  v is []

  v is []

  PL/SQL 過程已成功完成

  輸出的結果顯示CHAR類型變量在定義的時候分配內存分配的內存也可能超過變量定義的大小VARCHAR類型變量動態分配內存根據設置的變量的大小

  下面的例子也說明這一點

  SQL> DECLARE

   c CHAR() := ;

   v VARCHAR() := ;

   var CHAR := ; Implicitly sized at byte

   var CHAR() := ; Explicitly sized at byte

   var CHAR( BYTE) := ; Explicitly sized at byte

   var CHAR( CHAR) := ; Explicitly sized at character

   BEGIN

   dbms_outputput_line(c is [||LENGTH(c)||]);

   dbms_outputput_line(v is [||LENGTH(v)||]);

   dbms_outputput_line(var is [||LENGTH(var)||]);

   dbms_outputput_line(var is [||LENGTH(var)||]);

   dbms_outputput_line(var is [||LENGTH(var)||]);

   dbms_outputput_line(var is [||LENGTH(var)||]);

   v := v || ;

   dbms_outputput_line(v is [||LENGTH(v)||]); END;

   /

  c is []

  v is []

  var is []

  var is []

  var is []

  var is []

  v is []

  character 和 char的區別

  CHARACTER類型是CHAR的subtypeCHARACTER類型和它的基類優相同的大小在CHAR和CHARACTER數據類型之間隱式轉換以下是一個subtype的定義

  SUBTYPE subtype_name IS base_type[(maximum_size [BYTE | CHAR])] [NOT NULL];

  應用例子:

  SQL> DECLARE

   SUBTYPE code IS CHAR( CHAR);

   c CHAR( CHAR) := A;

   d CODE;

   BEGIN

   d := c;

   END;

   /

  PL/SQL 過程已成功完成


From:http://tw.wingwit.com/Article/program/Oracle/201311/19059.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.