IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 insert statement


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
star_dhruv2000

New User


Joined: 03 Nov 2006
Posts: 87
Location: Plymouth, MN USA

PostPosted: Tue Nov 28, 2006 6:51 pm
Reply with quote

Hello people I need to enter more then one value in table but by using following command I can only enter one record viz

Code:
insert into table-name values()


I have also tried to use this but it dosent work for DB2

Code:
insert into table-name values(),(),().....



So plz tell me a suitable answer for this.

Thanks and regards
Back to top
View user's profile Send private message
rambabu
Currently Banned

New User


Joined: 18 Apr 2005
Posts: 67

PostPosted: Tue Nov 28, 2006 7:53 pm
Reply with quote

Using insert-select stmt it insert multiple rows

INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
Back to top
View user's profile Send private message
shrivatsa
Warnings : 1

Active User


Joined: 17 Mar 2006
Posts: 174
Location: Bangalore

PostPosted: Tue Nov 28, 2006 10:50 pm
Reply with quote

Yes Rambabu you are correct

The another way is like this

EXEC SQL
INSERT INTO <tablename>
(columnname1, columnname2, columnname3)
VALUES (:hostvariable1, :hostvariable2, :hostvariable3 :hostvariable4)
FOR :hostvariable ROWS
END-EXEC.

this insert the number of rows that are specified in the bolded host variable.

Thanks
Shri
Back to top
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Tue Nov 28, 2006 11:30 pm
Reply with quote

If you have large number of rows to be inserted, another option would be to consider LOAD, read more about it in manual:

publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNUGH11/2.12?SHELF=DSNSHHA1&DT=20010719144747
Back to top
View user's profile Send private message
star_dhruv2000

New User


Joined: 03 Nov 2006
Posts: 87
Location: Plymouth, MN USA

PostPosted: Wed Nov 29, 2006 11:48 am
Reply with quote

I want to directly put in values is there anything except LOAD command or can anyone provide me exact syntax for LOAD.

Thanks and regards[/code]
Back to top
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Wed Nov 29, 2006 8:59 pm
Reply with quote

This link i provided you has SYNTAX (infact job step) for table LOAD, review '2.12.5 Sample control statement'.

If you want to insert values interactively and you have access try these couple of ways:

Hopefully table is small and you were trying to do this in a test environment.


1. QMF:
On QMF command line enter

Code:


edit QUALIFIER.TABLENAME



And you will get a screen where you can interactively insert values.

2. PLATINUM:

From PLATINUM Main menu select option '3' (RC/UPDATE)

Code:


----  r11    ------- Unicenter DB2 Products Main Menu  ------ 11-29-2006 0
OPTION ===>                                                   SCROLL ===>
                                                                         
DB2 SSID ==> DB2S LOCATION ==> LOCAL                 DB2 VERSION : V
ACM      ==> OFF  ACMID    ==> XXXX     SQLID ==> XXXX                   
                                                                         
<-> Backup and Recovery                 <-> Report Facility               
    _ LA Log Analyzer                       _ R  Report Facility Menu     
    _ MM Merge/Modify                                                     
    _ Z  Recovery Analyzer              <-> Utilities                     
                                            _ U  DB2 Object Manager       
<-> Database Administration                                               
    _ PX Partition Expert               <-> Value Pack                   
    _ 1  RC/Query                           _ B  Batch Processor         
    _ 2  RC/Migrator                        _ C  DB2 Command Processor   
    X 3  RC/Update                          _ I  Interactive SQL         
    _ 4  RC/Secure                          _ M  Alt. Catalog Mapping     
    _ 5  RC/Extract                         _ TT Thread Term/Dynam DSNZPAR
                                            _ Y  Utility Manager         
<-> General Facilities                      _ 6  RI Manager               
    _ A  Product Authorizations                                           
    _ DF Dataset Facility                                                 
-------------  (C) 2004 Computer Associates International, Inc. ----------


Next screen will be RC/Update Main Menu, fill in

Option as 'E' (Edit) or 'FE' (Fast Edit), enter table name in 'Item Name' and Qualifier in 'Creator'

Code:

Option    ===> FE                 Object   ===> T        Mode  ===> O ONLINE
Item Name ===> TABLNAME           Creator  ===>   QUAL       Where ===> N       
----------------------------------------------------------------------- XXXX Location  ===> LOCAL              DB2 SSID ===> DB2S     DB2 Version: V7R1M0
                                                                             
    Object Options             Objects  (for use with Object Options)       
      A  - Alter                 SG - Storage Group     T - Table           
      C  - Create                DB - Data Base         I - Index           
      D  - Drop                  TS - Table Space       V - View             
      T  - Template              TG - Trigger           S - Synonym         
      R  - Drop Recovery         RI - Ref.Integrity     A - Alias           
                                                        J - Join/Edit       
                                                                             
    Operation Control          Table Data Options                           
      L  - Log Display           B  - Browse            FB - Fast Browse     
      P  - Profile               E  - Edit              FE - Fast Edit       
      BP - Batch Processor       CO - Copy              DC - Data Compare   
      IS - Interactive SQL       RB - RI Browse         RE - RI Edit         
      TU - Tutorial                                                         
-----------   (C) 2004 Computer Associates International, Inc.     ----------


This will display you all the existing rows in table, just repeat the line and change values to what you want.

3.And lastly if with good old INSERT statement you will have to just repeat the statement.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Identify Program Insert DB2 7
No new posts Insert trailer for non empty file only DFSORT/ICETOOL 6
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
Search our Forums:

Back to Top