Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2013
    Posts
    4

    Unanswered: Random Insert - Table Populate

    Hello to all ,

    I'm having trouble generating data in some tables in a database for studies basically need to generate a random code to concatenate strings for insertion into tables , something similar to what I do in the same database in Postgres SQL code using the following function:

    "CREATE OR REPLACE FUNCTION Inspess ( cliini integer , integer climax , pcodcid integer , textoend varchar ( 15 ) , ptipo VARCHAR ( 10 ) )
    RETURNS INTEGER
    AS $ $
    DECLARE
    Vcont integer;
    vcodcli integer;
    BEGIN
    Vcont : = cliini ;

    WHILE Vcont < = climax LOOP
    vcodcli : = cast ( random () * 10000 AS integer) ;
    INSERT INTO person VALUES ( Vcont , ' Person ' | | Vcont , textoend | | Vcont , ptipo , vcodcli , null , pcodcid ) ;
    Vcont : Vcont = +1 ;
    END LOOP ;
    RETURN 0 ;
    END;
    $ $ LANGUAGE plpgsql ;
    "

    select inspess ( 10001 , 20000 , 10 , ' Street XY ' , 'E' ) -- in parameters
    --delete from person

    With this you can insert 20k rows in the table " person" quickly.

    Anyone can help to make this in DB2 ? ( I'm testing the version 9.7 )
    What can I change in the code so that it works in DB2?

    If possible send a sample small but complete with imaginary tables of a database using commands yield equivalent to DB2.

    I read the book DB2 LUW V9.7 - Cookbook - but could not make it right .

    Grateful for any help!
    Last edited by Rodrigo VR; 10-28-13 at 19:17. Reason: add information

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    as vcont is integer you can not use
    ' Person ' | | Vcont , textoend | | Vcont
    ' Person ' | | char(Vcont) should be used
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •