If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Create type in db2 8.2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-12, 02:59
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Create type in db2 8.2

Hi,

I am new to db2. I have worked a bit upon db2 9 on WINORA server. And now shifted to db2 8.2 on AIX server.
I am facing problem while creating user defined type in db2 8.2, which was not the case in db2 9.
For e.g. in db2 9, I used -
CREATE TYPE strArray as VARCHAR(20) ARRAY[100];

While I come across a bit of change in command for creating type in db2 8.2, which I came to know from IBM's site itself, and here it is -
CREATE DISTINCT TYPE strArray as VARCHAR(20) ARRAY[100];

But it's not working out. I checked with Privileges (especially for CREATING TYPE) for my db2 user and db2 schema with this following information -

Authorization
The privilege set that is defined below must include at least one of the following:

The CREATEIN privilege on the schema
SYSADM or SYSCTRL authority
The authorization ID that matches the schema name implicitly has the CREATEIN privilege on the schema.

Privilege set: If the statement is embedded in an application program, the privilege set is the privileges that are held by the authorization ID of the owner of the plan or package.

If the statement is dynamically prepared, the privilege set is the privileges that are held by the SQL authorization ID of the process. The specified distinct type name can include a schema name (a qualifier). However, if the schema name is not the same as the SQL authorization ID, one of the following conditions must be met:

The privilege set includes SYSADM or SYSCTRL authority.
The SQL authorization ID of the process has the CREATEIN privilege on the schema.


After giving these required privileges.. Still I am stuck up with the same problem in db2 8.2 with the following error, which is perfectly working on db2 9..

ERROR: A character, token, or clause is invalid or missing.

DB2
SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=CREATE
or replace TYPE;BEGIN-OF-STATEMENT;<create_type>, DRIVER=3.57.82
Error
Code: -104


I would highly appreciate if someone helps me out for solving my problem.

Thanks,
Prodigy 201

Last edited by prodigy201; 01-19-12 at 03:04.
Reply With Quote
  #2 (permalink)  
Old 01-19-12, 03:02
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
maybe cut and paste error
CREATE DISTICNT TYPE --> CREATE DISTINCT TYPE
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 01-19-12, 03:06
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
It was typing mistake over here :-) but it was correct while executing the command on server.
Reply With Quote
  #4 (permalink)  
Old 01-19-12, 07:25
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Can anybody please help me to solve my problem?
Reply With Quote
  #5 (permalink)  
Old 01-19-12, 07:39
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Array datatype is not supported on DB2 8.2 for LUW.

CREATE TYPE (Array) was supported from DB2 9.5 for LUW, by referencing some PDF manuals.
Reply With Quote
  #6 (permalink)  
Old 01-20-12, 12:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
According to the error message, you are trying to use "OR REPLACE" option on the create statement, which is not evident from the "actual" statements you have shown. "OR REPLACE" was not available until DB2 9.7. You should read manuals for your specific version of DB2.
Reply With Quote
  #7 (permalink)  
Old 01-24-12, 09:20
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Apart from arrays, it is also impossible to create simple user defined type of type varchar, too.. like -

create distinct type person as varchar(100);

And array type was not introduced in db2 8.2, is there any other way to handle this problem?

Or, if I I take all values in varchar as comma separated and want to split it in stored procedure, is there any function to split varchar value into array. For e.g.

"name1, name2, name3, name4, name5" can be split into varchar array?
Reply With Quote
  #8 (permalink)  
Old 01-24-12, 09:33
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
Or, if I I take all values in varchar as comma separated and want to split it ...
Create another table to store variable number of "values".
So, handling(insert/update/delete/select) the values will be much easier than storing all values in a varchar.
Reply With Quote
  #9 (permalink)  
Old 01-25-12, 05:23
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Actually, I want to pass an array from java code to stored procedure as input parameter in stored procedure.

I want to check if each element in that array is already there in the desired table. If the elements are not in the table, I would like to insert these elements into the table.

If array was not introduced in db2 8.2, is there any way to handle array type in SP? Else, can we pass a string having all elements comma-separated as input parameter in stored procedure? And how to split then this string to get the all values as elements?
Reply With Quote
  #10 (permalink)  
Old 01-25-12, 07:17
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
I want to check if each element in that array is already there in the desired table. If the elements are not in the table, I would like to insert these elements into the table.
I thought that stored procedure is not necessary to do that requirements.
(If used a stored procedure, same complexity of code would be neccesary to construct a parameter for the procedure.)

Construct an INSERT statement into a string variable from the array in Java, then execute it dynamicaly.

The INSERT statement might look like...
Code:
INSERT INTO
 person_names(name)
SELECT new_name
 FROM  (VALUES
            'name_1'
          , 'name_2'
          ...
          , 'name_n'
       ) t(new_name)
 WHERE new_name NOT IN (
       SELECT name
        FROM  person_names
       )
;
Note: New lines and leading blanks in the sample code are for readability.
They are not necessary in an actual statement string(one blank to separate words is enough).

Last edited by tonkuma; 01-25-12 at 07:23. Reason: Add quoted statements(requirements) and some explanations.
Reply With Quote
  #11 (permalink)  
Old 01-25-12, 07:27
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Another issue is how you populated the values in the array.

Depending on the way to populate the array,
you might want to construct the INSERT statement directly without using intermediate array.
Reply With Quote
  #12 (permalink)  
Old 01-27-12, 08:59
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Hi, that query you provided has worked out. Thanks a lot! :-)
But if I want to take for more than one fields how can I right for multiple fields?
Reply With Quote
  #13 (permalink)  
Old 01-27-12, 09:01
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Quote:
INSERT INTO
person_names(name)
SELECT new_name
FROM (VALUES
'name_1'
, 'name_2'
...
, 'name_n'
) t(new_name)
WHERE new_name NOT IN (
SELECT name
FROM person_names
);
Hi, that query you provided has worked out. Thanks a lot! :-)
But if I want to take for more than one fields how can I write for multiple fields?
Reply With Quote
  #14 (permalink)  
Old 01-27-12, 09:05
prodigy201 prodigy201 is offline
Registered User
 
Join Date: Jan 2012
Posts: 11
Quote:
Originally Posted by tonkuma View Post
Another issue is how you populated the values in the array.

Depending on the way to populate the array,
you might want to construct the INSERT statement directly without using intermediate array.
I am taking comma separated values in String variable or Integer object to pass the values in query.
Like -
String str = new String('val1, 'val2', ........, 'val_n');
Reply With Quote
  #15 (permalink)  
Old 01-27-12, 15:33
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
I am taking comma separated values in String variable or Integer object to pass the values in query.
Like -
String str = new String('val1, 'val2', ........, 'val_n');
I don't know Java.
What value was in str, after the assignment?

And, to what query do you want to pass the values?


By the way,
from where came val1, val2, ..., val_n?
We might be better to go back more, to apply the following consideration.
Quote:
Originally Posted by tonkuma View Post
Another issue is how you populated the values in the array.

Depending on the way to populate the array,
you might want to construct the INSERT statement directly without using intermediate array.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On