How to create a temporary DB2 table

Source: Internet
Author: User

The problem that DB2 temporary tables cannot be created is indeed a headache. The following describes how to solve the problem that DB2 temporary tables cannot be created. We hope this will help you learn about DB2 temporary tables.

 
 
  1. Procedure TXXXForm. lc_procHandleStandard (strpo: string; xPOSEQ: Integer); // HXYADD----24/09/2010 ----
  2. Var
  3. StrFieldList: string; // A-JW-02-351101-01
  4. Begin
  5. StrFieldList: = 'xname VARCHAR (80), '#13 #10
  6. + 'Xkind VARCHAR (20), '#13 #10
  7. + 'Ename VARCHAR (20), '#13 #10
  8. + 'Cname VARCHAR (20), '#13 #10
  9. + 'Xbiao VARCHAR (80), '#13 #10
  10. + 'Xcode INTEGER, '#13 #10
  11. + 'Xgrade INTEGER ';
  12. StrTmpTableName: = lc_CreatTmpTable (strFieldList );
  13. If strTmpTableName = ''then
  14. Begin
  15. Messagebox (handle, 'unable to create a [Execute standard materials] temporary table! ', 'prompt information', mb_ OK );
  16. Exit;
  17. End ;//*)
  18. Qry6.Close;
  19. Qry6. SQL. Clear;
  20. Qry6. SQL. Add ('delete from' + strTmpTableName );
  21. Qry6.ExecSQL;
  22.  
  23. Qry6.Close;
  24. Qry6. SQL. Clear;
  25. Qry6. SQL. Add ('insert' + strTmpTableName );
  26. Qry6. SQL. Add ('(XNAME, XKIND, ENAME, CNAME, XBIAO, XCODE, XGRADE )');
  27. Qry6. SQL. Add ('select VALUE (K. PROD_NAME ,''''),');
  28. Qry6. SQL. Add ('case K. PROD_KIND WHEN 0 then'' '0 primary color production ''');
  29. Qry6. SQL. Add ('when 1 then' '1 washing product ''');
  30. Qry6. SQL. Add ('else' X does not classify ''end PROD_KIND ,');
  31. Qry6. SQL. Add ('value (A. COLOR_ENG_NAME ,''''),');
  32. Qry6. SQL. Add ('value (A. COLOR_CHN_NAME ,''''),');
  33. Qry6. SQL. Add ('value (K. ZHIXIN_BIAO ,''''),');
  34. Qry6. SQL. Add ('k.s _ CODE ,');
  35. Qry6. SQL. Add ('A. COLOR_GRADE ');
  36. Qry6. SQL. Add ('from GSSAL. SAL_PO_DTLA ');
  37. Qry6. SQL. Add ('left JOIN GSSAL. SAL_PO X ON (X. PO_NO = A. PO_NO AND X. GEN_POSEQ = A. GEN_POSEQ )');
  38. Qry6. SQL. Add ('left JOIN GSSAL. SAL_KIND K ON (K.S _ CODE = VALUE (A. PROD_CODE, X. PROD_CODE ))');
  39. Qry6. SQL. Add ('where A. PO_NO =: PO_NO AND A. GEN_POSEQ =: GEN_POSEQ ');
  40. Qry6. SQL. Add ('AND VALUE (K. ISVALID, ''n'') = ''y ''');
  41. Qry6. SQL. Add ('order BY K. PROD_NAME, A. COLOR_ENG_NAME ');
  42. Qry6.ParamByName ('po _ no'). AsString: = strpo;
  43. Qry6.ParamByName ('gen _ POSEQ '). AsInteger: = xPOSEQ;
  44. Qry6.ExecSQL;
  45. Qry6.Close;
  46. Qry6. SQL. Clear;
  47. Qry6. SQL. Add ('select *');
  48. Qry6. SQL. Add ('from' + strTmpTableName );
  49. Qry6.Open;
  50. End;
  51. Certificate -----------------------------------------------------------------------------------------------------------------------------------
  52. Function TXXXForm. lc_CreatTmpTable (strFieldList: string): string;
  53. Var
  54. StrTableName: string;
  55. BlnSuccess: boolean;
  56. I: integer;
  57. Function lc_funcCreatTable (strFieldList, strTableName: string): Boolean;
  58. Var
  59. QryCreatTemp: TQuery;
  60. Begin
  61. Result: = False;
  62. QryCreatTemp: = TQuery. Create (self );
  63. With qryCreatTemp do
  64. Begin
  65. DatabaseName: = 'gscomdb ';
  66. SQL. Clear;
  67. SQL. Add ('create table' + strTableName + '(' + strFieldList + ') IN USERSPACE1 ');
  68. Try
  69. ExecSQL;
  70. Result: = True;
  71. Except
  72. End;
  73. End;
  74. QryCreatTemp. Free;
  75. End;
  76. Begin
  77. Result: = ''; // If creation fails, an empty string is returned.
  78. StrTableName: = 'maid. TMP _ '+ FormatFloat ('0', now * 10000000) + '';
  79. For I: = 1 to 50 do // loop for 50 times, and then exit if it cannot be created.
  80. Begin
  81. BlnSuccess: = lc_funcCreatTable (strFieldList, strTableName );
  82. If blnSuccess then // if the table is successfully created, the table name is returned and the table exits.
  83. Begin
  84. Result: = strTableName;
  85. Exit;
  86. End;
  87. End;
  88. End;
  89. Certificate -----------------------------------------------------------------------------------------------------------------------------------
  90. Procedure TXXXForm. FormCloseQuery (Sender: TObject; var CanClose: Boolean );
  91. Begin
  92. LstUser. Free;
  93. If strTmpTableName <> ''then
  94. Begin
  95. Lc_DeleteTable (strTmpTableName );
  96. StrTmpTableName: = '';
  97. End;
  98. End;
  99. Certificate -----------------------------------------------------------------------------------------------------------------------------------
  100. Function TXXXForm. lc_DeleteTable (strTableName: string): Boolean;
  101. Var
  102. QryDeleteTemp: TQuery;
  103. Begin
  104. Result: = False;
  105. QryDeleteTemp: = TQuery. Create (Self );
  106. With qryDeleteTemp do
  107. Begin
  108. DatabaseName: = 'gscomdb ';
  109. SQL. Clear;
  110. SQL. Add ('drop table' + strTableName );
  111. Try
  112. ExecSQL;
  113. Result: = True;
  114. Except
  115. End;
  116. End;
  117. QryDeleteTemp. Free;
  118. End;
  119. Certificate -----------------------------------------------------------------------------------------------------------------------------------

Learn about the DB2 lock types

Solution to db2 tablespace lock

Implementation of adding verification constraints to DB2

How to Create a tablespace in DB2

Introduction to the DB2 user group in Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.