{"id":418,"date":"2011-12-23T23:47:37","date_gmt":"2011-12-23T15:47:37","guid":{"rendered":"https:\/\/yangtingkun.net\/?p=418"},"modified":"2011-12-25T01:15:07","modified_gmt":"2011-12-24T17:15:07","slug":"%e6%8f%92%e5%85%a5lob%e5%af%b9%e8%b1%a1%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/yangtingkun.net\/?p=418","title":{"rendered":"\u63d2\u5165LOB\u5bf9\u8c61\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u5176\u5b9e\u4ee5\u524d\u5199\u8fc7\u7c7b\u4f3c\u7684\u6587\u7ae0\uff0c\u4f46\u662f\u90fd\u662f\u5728\u5176\u4ed6\u4f8b\u5b50\u4e2d\uff0c\u6ca1\u6709\u4e13\u95e8\u9488\u5bf9\u8fd9\u4e2a\u95ee\u9898\u8fdb\u884c\u8fc7\u63cf\u8ff0\uff0c\u6700\u8fd1\u53d1\u73b0\uff0c\u8fd8\u6709\u5f88\u591a\u4eba\u4e0d\u6e05\u695a\uff0c\u63d2\u5165\u4e00\u4e2a\u5305\u542bLOB\u5bf9\u8c61\u7684\u8bb0\u5f55\u9700\u8981\u51e0\u4e2a\u6b65\u9aa4\u3002<br \/>\n\u5728\u5ba2\u6237\u7684\u73af\u5883\u4e2d\uff0c\u53d1\u73b0\u63d2\u5165\u4e00\u6761\u5305\u542bLOB\u7684\u8bb0\u5f55\uff0c\u5c45\u7136\u7528\u4e86\u56db\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<pre lang='SQL'>SQL> CREATE TABLE T_LOB (ID NUMBER, NAME VARCHAR2(30), CONTENTS CLOB);\r\n\u8868\u5df2\u521b\u5efa\u3002\r\nSQL> DECLARE\r\n2 V_CLOB CLOB;\r\n3 V_STR VARCHAR2(32767) := LPAD('A', 4000, 'A');\r\n4 BEGIN\r\n5 INSERT INTO T_LOB \r\n6 VALUES (1, 'A', EMPTY_CLOB());\r\n7 SELECT CONTENTS \r\n8 INTO V_CLOB\r\n9 FROM T_LOB\r\n10 WHERE ID = 1\r\n11 FOR UPDATE;\r\n12 DBMS_LOB.WRITE(V_CLOB, 4000, 1, V_STR);\r\n13 UPDATE T_LOB \r\n14 SET CONTENTS = V_CLOB\r\n15 WHERE ID = 1;\r\n16 COMMIT;\r\n17 END;\r\n18 \/\r\nPL\/SQL \u8fc7\u7a0b\u5df2\u6210\u529f\u5b8c\u6210\u3002<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u4e3a\u4e86\u63d2\u5165\u4e00\u6761\u5305\u542bLOB\u7684\u8bb0\u5f55\uff0c\u5ba2\u6237\u9996\u5148\u63d2\u5165EMPTY_CLOB\uff0c\u7136\u540e\u901a\u8fc7SELECT\u9884\u8ba1\u83b7\u53d6LOB\u7684\u5b9a\u4f4d\u7b26\uff0c\u901a\u8fc7DBMS_LOB\u5305\u5199\u5165\u6570\u636e\uff0c\u6700\u540e\u901a\u8fc7UPDATE\u8bed\u53e5\uff0c\u5bf9LOB\u5217\u8fdb\u884c\u66f4\u65b0\u3002<br \/>\n\u5728\u4e0a\u9762\u7684\u6b65\u9aa4\u4e2d\uff0cUPDATE\u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u5373\u4f7f\u4e0d\u5bf9LOB\u5217\u6267\u884cUPDATE\u64cd\u4f5c\uff0c\u4e5f\u4f1a\u5bfc\u81f4\u8bb0\u5f55\u7684\u63d2\u5165\uff1a<\/p>\n<pre lang='SQL'>SQL> DECLARE\r\n2 V_CLOB CLOB;\r\n3 V_STR VARCHAR2(32767) := LPAD('B', 4000, 'B');\r\n4 BEGIN\r\n5 INSERT INTO T_LOB \r\n6 VALUES (2, 'B', EMPTY_CLOB());\r\n7 SELECT CONTENTS \r\n8 INTO V_CLOB\r\n9 FROM T_LOB\r\n10 WHERE ID = 2\r\n11 FOR UPDATE;\r\n12 DBMS_LOB.WRITE(V_CLOB, 4000, 1, V_STR);\r\n13 COMMIT;\r\n14 END;\r\n15 \/\r\nPL\/SQL \u8fc7\u7a0b\u5df2\u6210\u529f\u5b8c\u6210\u3002<\/pre>\n<p>\u800c\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u91cc\u7684SELECT FOR UPDATE\u8bed\u53e5\u540c\u6837\u662f\u4e0d\u5fc5\u8981\u7684\uff0c\u8fd9\u4e2a\u8bed\u53e5\u53ef\u4ee5\u7531INSERT\u7684RETURN\u8bed\u53e5\u6765\u4ee3\u66ff\uff1a<\/p>\n<pre lang='SQL'>SQL> DECLARE\r\n  2  V_CLOB CLOB;\r\n  3  V_STR VARCHAR2(32767) := LPAD('C', 4000, 'C');\r\n  4  BEGIN\r\n  5  INSERT INTO T_LOB \r\n  6  VALUES (3, 'C', EMPTY_CLOB())\r\n  7  RETURN CONTENTS INTO V_CLOB;\r\n  8  DBMS_LOB.WRITE(V_CLOB, 4000, 1, V_STR);\r\n  9  COMMIT;\r\n 10  END;\r\n 11  \/\r\nPL\/SQL \u8fc7\u7a0b\u5df2\u6210\u529f\u5b8c\u6210\u3002\r\nSQL> SET LONG 40\r\nSQL> SELECT * FROM T_LOB;\r\n        ID NAME                           CONTENTS\r\n---------- ------------------------------ ----------------------------------------\r\n         3 C                              CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\r\n         1 A                              AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n         2 B                              BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB<\/pre>\n<p>\u63d2\u5165\u5305\u542bLOB\u7684\u8bb0\u5f55\uff0c\u9664\u4e86DBMS_LOB\u90e8\u5206\u4e00\u822c\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\uff0c\u6b64\u5916\u53ea\u9700\u8981INSERT\u8bed\u53e5\u672c\u8eab\uff0c\u5176\u4ed6\u7684SELECT\u548cUPDATE\u8bed\u53e5\u90fd\u4e0d\u662f\u5fc5\u987b\u7684\u3002\u53bb\u6389\u8fd9\u4e9b\u4e0d\u5fc5\u8981\u7684\u6b65\u9aa4\uff0c\u53ef\u4ee5\u6709\u6548\u7684\u964d\u4f4e\u7a0b\u5e8f\u548c\u6570\u636e\u5e93\u4ea4\u4e92\u6b21\u6570\uff0c\u51cf\u5c11\u5355\u4e2a\u64cd\u4f5c\u8c03\u7528\u7684\u8bed\u53e5\u6570\u91cf\uff0c\u4ece\u800c\u63d0\u9ad8\u64cd\u4f5c\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5b9e\u4ee5\u524d\u5199\u8fc7\u7c7b\u4f3c\u7684\u6587\u7ae0\uff0c\u4f46\u662f\u90fd\u662f\u5728\u5176\u4ed6\u4f8b\u5b50\u4e2d\uff0c\u6ca1\u6709\u4e13\u95e8\u9488\u5bf9\u8fd9\u4e2a\u95ee\u9898\u8fdb\u884c\u8fc7\u63cf\u8ff0\uff0c\u6700\u8fd1\u53d1\u73b0\uff0c\u8fd8\u6709\u5f88\u591a\u4eba\u4e0d\u6e05\u695a\uff0c\u63d2\u5165\u4e00\u4e2a\u5305\u542bLOB\u5bf9\u8c61\u7684\u8bb0\u5f55\u9700\u8981\u51e0\u4e2a\u6b65\u9aa4\u3002 \u5728\u5ba2\u6237\u7684\u73af\u5883\u4e2d\uff0c\u53d1\u73b0\u63d2\u5165\u4e00\u6761\u5305\u542bLOB\u7684\u8bb0\u5f55\uff0c\u5c45\u7136\u7528\u4e86\u56db\u4e2a\u6b65\u9aa4\uff1a SQL> CREATE TABLE T_LOB (ID NUMBER, NAME VARCHAR2(30), CONTENTS CLOB); \u8868\u5df2\u521b\u5efa\u3002 SQL> DECLARE 2 V_CLOB CLOB; 3 V_STR VARCHAR2(32767) := LPAD(&#8216;A&#8217;, 4000, &#8216;A&#8217;); 4 BEGIN 5 INSERT INTO T_LOB 6 VALUES (1, &#8216;A&#8217;, EMPTY_CLOB()); 7 SELECT CONTENTS 8 &hellip; <a href=\"https:\/\/yangtingkun.net\/?p=418\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[312,313,91,314,315],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2yiY3-6K","_links":{"self":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/418"}],"collection":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=418"}],"version-history":[{"count":1,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangtingkun.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}