I have a table that includes a column foo.
show create table shows `foo` bit(1) DEFAULT b'0', so the column should contain binary strings: the 0 and 1 bytes.
select ascii(foo),
ord(foo),
foo=char(1),
foo=char(0),
char(1)=char(0)
from table_name
group by 1,2,3,4,5
yields
ascii(foo) ord(foo) foo=char(1) foo=char(0) char(1)=char(0)
0 0 1 1 0
1 1 0 0 0
I'd expect it to yield
ascii(foo) ord(foo) foo=char(1) foo=char(0) char(1)=char(0)
0 0 0 1 0
1 1 1 0 0
Can someone please explain what's going on?
Nor is this restricted to the select clause. It happens in the where clause also: select distinct ascii(foo) from table_name where foo=char(0) and select distinct ascii(foo) from table_name where foo=char(1) both return only 0.
select ##version
5.7.21-20-57-log
Related
This is only sample case, my original table is more complex.
Table A
SchoolId
ClubId
ChildID
TeacherId
AttendanceDate
IsPresent
A
1
1
1
22-MAY-2022
1
A
1
2
1
22-MAY-2022
0
A
1
3
1
22-MAY-2022
1
B
2
11
2
22-MAY-2022
1
B
2
22
2
22-MAY-2022
0
B
2
33
2
22-MAY-2022
0
Table B
ChildID
TeacherId
CreateOn
IsPresent
ReasonId
2
1
22-MAY-2022
0
1
2
1
23-MAY-2022
0
2
22
2
22-MAY-2022
0
2
33
2
22-MAY-2022
0
3
Table C
ReasonId
ReasonMaster
1
Health
2
Social
3
Unknown
I want the left join result like this :
SchoolId
ClubId
ChildID
TeacherId
AttendanceDate
IsPresent
ReasonId
ReasonMaster
A
1
1
1
22-MAY-2022
1
A
1
2
1
22-MAY-2022
0
2
Social
A
1
3
1
22-MAY-2022
1
B
2
11
2
22-MAY-2022
1
B
2
22
2
22-MAY-2022
0
2
Social
B
2
33
2
22-MAY-2022
0
3
Unknown
Here are my cases:
I only want to retrieve the latest data from table B based on create on column on the table B to the table A. Because there is a duplicate input by users. for instance in the table B child Id= 2 & Teacher Id=1.
I only need to retrieve the the data if the status in the table A, column IsPresent=0
There is an additional data from table C which reason master.
I try this Query, but CTE function not working in Power BI.
;with MaxCreate as (Select ChildID,TeacherID,Max(CreateOn) as MaxCreateOn
from TableB
group by ChildID,TeacherID)
,LatestCreate as (select TableB.ChildID, TableB.TeacherId, TableB.CreateOn, TableB.IsPresent, TableB.ReasonId
from TableB
inner join MaxCreate
on TableB.ChildID = MaxCreate.ChildID
and TableB.TeacherId = MaxCreate.TeacherId
and TableB.CreateOn = MaxCreate.MaxCreateOn)
Select
TableA.SchoolId
,TableA.ClubId
,TableA.ChildID
,TableA.TeacherId
,TableA.AttendanceDate
,TableA.IsPresent
,LatestCreate.ReasonId
,TableC.ReasonMaster
From TableA
Left join LatestCreate
on TableA.ChildID = LatestCreate.ChildID
and TableA.TeacherID = LatestCreate.TeacherID
left join TableC
on LatestCreate.ReasonId = TableC.ReasonId
I have a spreadsheet and in one of the tabs I have a table with computed data from other tabs. This is small table with 11 columns. Row(1) is the Header row and Column A is the list of items, Column B to J is the types. Data consists of numbers only.
As the data is computed, time to time values in some of the columns thru B to J can be totally zero. I want to create a subset of this table with QUERY but constructing a dynamic range getting only the columns which has at least 1 value which is greater than zero.
I'm aware that a range can be created as an array like {A:A\B:B\D:D} but in my case I don't know which columns can have values of greater than zero and I don't want to take columns into the range which has completely zero values.
I have created an expression to concatenate this array value as a text in a cell, however I can't use it with the QUERY formula either with INDEX or TEXT functions. Table is like this:
Items TypeA TypeB TypeC TypeD
Bronze 0 0 0 0
Silver 0 0 1 0
Gold 0 0 1 0
Titanimum 1 0 0 0
For this snapshot of table, I want to QUERY range to be {A:A\B:B\D:D}. However, as the data is computed, the table can be like this after 2hrs or the next day:
Items TypeA TypeB TypeC TypeD
Bronze 1 0 0 1
Silver 0 0 1 0
Gold 0 1 1 0
Titanimum 1 0 0 0
And so, for this snapshot of table, I want to QUERY range to be {A:A\B:B\C:C\D:D\E:E}.
Is this doable? And how can I achieve or construct a dynamic QUERY range?
Thanks for everyone...
You can remove columns from a range based on a criteria using the FILTER command.
Unfiltered
Items TypeA TypeB TypeC TypeD TypeE TypeF TypeG
Bronze 1 0 0 1 0 0 1
Silver 1 1 0 1 0 0 1
Gold 1 0 0 1 0 0 1
Titan 1 0 0 1 1 0 1
1 4 1 0 4 1 0 4
Filtered to remove columns with total of 0
Items TypeA TypeB TypeD TypeE TypeG
Bronze 1 0 1 0 1
Silver 1 1 1 0 1
Gold 1 0 1 0 1
Titan 1 0 1 1 1
The 'trick' is to sum the sum the column data (for your example) and then test for >0
The filter expression is:
=FILTER(A1:H5,A6:H6 >0)
By way of explanation:
A1:H5 is the range to be filtered;
A6:H6 >0 selects all columns that have a value > 0 in row 6
I placed a 1 in A6 to make sure colA is included.
You can now do queries on the range returned by the above expression.
I am really sorry for this. I am new oracle and I have created following block which is resulting output and then error.
First cursor is generating output and then error and so second cursor is not generating output.
Please help for error free output .
thanks and regards
Error:
END;
Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 36
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause:
*Action:
Block:
DECLARE
c_dbuser SYS_REFCURSOR;
c_dbuser1 SYS_REFCURSOR;
temp_dbuser FIT_SCHEMA.fxf_inspt_insp_main%ROWTYPE;
year_date varchar2(20):='2014';
typeOfGraph varchar2(50):='InspectionByInspection';
division varchar2(20):='Division';
subDiv varchar2(20):='ALL';
emp varchar2(20):='';
TYPE t_name IS RECORD( --Error is at this line :(
inspectiondate varchar2(20),
totalcount number(38),
inspectionDesc varchar2(20)
);
r_name t_name; -- name record
TYPE t_monthwise is record (
month_number varchar2(20),
inspcount number(38),
inspectionDesc varchar2(20)
);
t_month t_monthwise;
BEGIN
fit_schema.My_manager(typeOfGraph,year_date,division,subDiv,emp,c_dbuser,c_dbuser1);
LOOP
FETCH c_dbuser INTO r_name ;
EXIT WHEN c_dbuser%NOTFOUND;
dbms_output.put_line( r_name.inspectiondate ||' '||r_name.totalcount||' '||r_name.inspectionDesc);
END LOOP;
LOOP
FETCH c_dbuser1 INTO t_month ;
EXIT WHEN c_dbuser1%NOTFOUND;
dbms_output.put_line( t_month.month_number ||' '||t_month.inspcount||' '||t_month.inspectionDesc);
END LOOP;
CLOSE c_dbuser;
CLOSE c_dbuser1;
END;
Output :
13-DEC-2014 1 3#CPLD Only
13-DEC-2014 4 0#Class Only
14-DEC-2014 1 0#Class Only
15-DEC-2014 2 0#Class Only
16-DEC-2014 1 0#Class Only
17-DEC-2014 1 7#Negative Class
17-DEC-2014 9 0#Class Only
19-DEC-2014 15 0#Class Only
22-DEC-2014 1 11#65% Rule
23-DEC-2014 1 8#XLGH & Class
30-DEC-2014 1 0#Class Only
31-DEC-2014 1 10#Mixed Articles
31-DEC-2014 3 0#Class Only
02-JAN-2015 2 0#Class Only
05-JAN-2015 2 0#Class Only
07-JAN-2015 2 9#XLGH Only
07-JAN-2015 3 1#Class & Reweigh
07-JAN-2015 1 10#Mixed Articles
07-JAN-2015 4 0#Class Only
07-JAN-2015 2 11#65% Rule
08-JAN-2015 5 0#Class Only
08-JAN-2015 1 9#XLGH Only
09-JAN-2015 1 3#CPLD Only
09-JAN-2015 1 11#65% Rule
09-JAN-2015 4 0#Class Only
09-JAN-2015 1 1#Class & Reweigh
12-JAN-2015 1 5#CCD Only
12-JAN-2015 1 3#CPLD Only
19-JAN-2015 1 11#65% Rule
20-JAN-2015 1 0#Class Only
21-JAN-2015 4 0#Class Only
23-JAN-2015 1 10#Mixed Articles
26-JAN-2015 1 7#Negative Class
26-JAN-2015 2 0#Class Only
27-JAN-2015 1 3#CPLD Only
27-JAN-2015 3 0#Class Only
27-JAN-2015 1 6#CCD & Class
28-JAN-2015 6 0#Class Only
29-JAN-2015 3 0#Class Only
29-JAN-2015 1 5#CCD Only
30-JAN-2015 1 3#CPLD Only
30-JAN-2015 1 1#Class & Reweigh
01-FEB-2015 3 0#Class Only
02-FEB-2015 1 4#CPLD & Class
02-FEB-2015 1 8#XLGH & Class
04-FEB-2015 1 0#Class Only
Queries from Procedure :-
SELECT TO_CHAR(MAINTABLE.INSP_CREATED_TMSTP,'dd-MON-yyyy') inspectiondate, --varchar2
COUNT(MAINTABLE.insp_id) AS totalinspection, --count is number
MAINTABLE.insp_type_id ||'#'||ISNPTYPETABLE.INSP_TYPE_DESC AS INSPECTIONDESCRIPTION-- varchar2
FROM FIT_SCHEMA.fxf_inspt_insp_main MAINTABLE
JOIN FIT_SCHEMA.fxf_inspt_emp_detail EMPTABLE
ON(MAINTABLE.inspector_emp_nbr=EMPTABLE.inspector_emp_nbr)
JOIN FIT_SCHEMA.fxf_inspt_drop_down DROPDOWNTABLE
ON (emptable.division_id = DROPDOWNTABLE.drop_down_id)
JOIN FIT_SCHEMA.fxf_inspt_insp_type ISNPTYPETABLE
ON(MAINTABLE.insp_type_id =isnptypetable.insp_type_id)
WHERE dropdowntable.is_active_flg = 1
AND MAINTABLE.STATUS_ID = 8
AND MAINTABLE.insp_type_id IN (0,1,3,4,5,6,7,8,9,10,11,12)
AND TRUNC(MAINTABLE.insp_created_tmstp) between TRUNC(EMPTABLE.EFFECTIVE_FROM_TMSTP)
And Nvl(Trunc(Emptable.Effective_To_Tmstp),Sysdate) AND UPPER(dropdowntable.drop_down_grp) =UPPER('division') AND TRUNC(MAINTABLE.insp_created_tmstp) between '01-JUN-14' AND '31-MAY-15' GROUP BY TO_CHAR(MAINTABLE.INSP_CREATED_TMSTP,'dd-MON-yyyy')
, TRUNC(MAINTABLE.INSP_CREATED_TMSTP), MAINTABLE.insp_type_id ||'#'|| ISNPTYPETABLE.INSP_TYPE_DESC ORDER BY TRUNC(MAINTABLE.INSP_CREATED_TMSTP)
SELECT TO_CHAR(MAINTABLE.insp_created_tmstp,'MM') AS MONTHNUMBER,
COUNT(MAINTABLE.INSP_ID) AS INSPCOUNT ,
MAINTABLE.insp_type_id ||'#'
||ISNPTYPETABLE.INSP_TYPE_DESC AS INSPECTIONDESCRIPTION
FROM FIT_SCHEMA.fxf_inspt_insp_main MAINTABLE
JOIN FIT_SCHEMA.fxf_inspt_emp_detail EMPTABLE
ON(MAINTABLE.inspector_emp_nbr=EMPTABLE.inspector_emp_nbr)
JOIN FIT_SCHEMA.fxf_inspt_drop_down DROPDOWNTABLE
ON (emptable.division_id = DROPDOWNTABLE.drop_down_id)
JOIN FIT_SCHEMA.fxf_inspt_insp_type ISNPTYPETABLE
ON(MAINTABLE.insp_type_id =isnptypetable.insp_type_id)
WHERE dropdowntable.is_active_flg = 1
AND MAINTABLE.insp_type_id IN (0,1,3,4,5,6,7,8,9,10,11,12)
AND dropdowntable.is_active_flg = 1
AND MAINTABLE.STATUS_ID = 8
AND TRUNC(MAINTABLE.insp_created_tmstp) between TRUNC(EMPTABLE.EFFECTIVE_FROM_TMSTP)
And Nvl(Trunc(Emptable.Effective_To_Tmstp),Sysdate) AND UPPER(dropdowntable.drop_down_grp) =UPPER('division')
AND TRUNC(MAINTABLE.insp_created_tmstp) between '01-JUN-14'
AND '31-MAY-15' GROUP BY TO_CHAR(MAINTABLE.insp_created_tmstp,'MM'), MAINTABLE.insp_type_id ||'#'||ISNPTYPETABLE.INSP_TYPE_DESC ORDER BY TO_CHAR(MAINTABLE.insp_created_tmstp,'MM')
Line 36 is:
FETCH c_dbuser INTO r_name ;
So one of the values being returned in your c_dbuser ref cursor is too big. Your date format mask will only generate string 11 characters long so inspectiondate is (more than) adequate, and the count seems unlikely to exceed number(38) so totalcount also seems fine. Which suggests that inspectionDesc is too small for some of the values in the data.
You're generating that from:
MAINTABLE.insp_type_id ||'#'||ISNPTYPETABLE.INSP_TYPE_DESC
If the total length of that concatenated string exceeds 20 characters then you'll get an error on fetch.
If INSP_TYPE_DESC is defined as varchar2(20) then you aren't allowing any room for the rest; you need one extra character for the fixed #, and at least two for the insp_type_id - more if the highest ID can be three digits or more. If it isn't constrained then you'll need to decide the highest number you expect to ever see and allow for that. So if you expect up to three digits for an ID, define inspectionDesc as varchar2(24), etc.
I need to join two tables (well, actually two views) so that for every selected row of the left view, there is a count of rows from the right view. That sounds to me like a LEFT JOIN, but in SQLite (this test database) and a LEFT JOIN query:
SELECT TARGET.session_id session_id, TARGET.labeltype_id labeltype_id, TARGET.label_id label_id, count(SECONDARY.label_id) NOlabels
FROM segment_extended TARGET LEFT JOIN segment_extended SECONDARY
WHERE TARGET.session_id = SECONDARY.session_id AND TARGET.lt_name= "Word" AND SECONDARY.lt_name ="Comments"
AND ((SECONDARY.start <= TARGET.start AND TARGET.END <= SECONDARY.END) OR (TARGET.start <= SECONDARY.start AND SECONDARY.END <= TARGET.END))
AND TARGET.label != '' AND SECONDARY.label != ''
GROUP BY TARGET.session_id,TARGET.labeltype_id, TARGET.label_id;
I get only a small subset of what I would expect:
2 3 3 1
2 3 9 1
A more extended query gives the correct result:
SELECT session_id, labeltype_id, label_id, max(NOlabels) NOlabels
FROM (SELECT TARGET.session_id session_id, TARGET.labeltype_id labeltype_id, TARGET.label_id label_id, count(SECONDARY.label_id) NOlabels
FROM segment_extended TARGET , segment_extended SECONDARY
WHERE TARGET.session_id = SECONDARY.session_id AND TARGET.lt_name= "Word" AND SECONDARY.lt_name ="Comments"
AND ((SECONDARY.start <= TARGET.start AND TARGET.END <= SECONDARY.END) OR (TARGET.start <= SECONDARY.start AND SECONDARY.END <= TARGET.END))
AND TARGET.label != '' AND SECONDARY.label != ''
GROUP BY TARGET.session_id,TARGET.labeltype_id, TARGET.label_id
UNION
SELECT TARGET.session_id session_id, TARGET.labeltype_id labeltype_id, TARGET.label_id label_id, 0 NOlabels
FROM segment_extended TARGET
WHERE TARGET.lt_name= "Word"
AND TARGET.label != ''
GROUP BY TARGET.session_id,TARGET.labeltype_id, TARGET.label_id)
GROUP BY session_id, labeltype_id, label_id
ORDER BY session_id,labeltype_id, label_id
session_id labeltype_id label_id NOlabels
2 3 2 0
2 3 3 1
2 3 4 0
2 3 5 0
2 3 7 0
2 3 8 0
2 3 9 1
2 3 10 0
but it seems unnecessarily complicated. What am I doing wrong with the left join?
When doing a left join you have to count the null values from the left join as 0 records but still include them. You can accomplish this with a CASE construct in the inner query, then using the SUM aggregate function in the outer group-by.
SELECT session_id, labeltype_id, label_id, sum(has_label) NOlabels
FROM (
SELECT TARGET.session_id session_id, TARGET.labeltype_id labeltype_id, TARGET.label_id label_id, CASE WHEN SECONDARY.label_id is NULL then 0 else 1 END has_label
FROM
segment_extended TARGET
LEFT JOIN
segment_extended SECONDARY on
TARGET.session_id = SECONDARY.session_id
AND SECONDARY.lt_name ="Comments"
AND ((
SECONDARY.start <= TARGET.start AND TARGET.END <= SECONDARY.END)
OR (TARGET.start <= SECONDARY.start AND SECONDARY.END <= TARGET.END))
AND SECONDARY.label != ''
WHERE TARGET.lt_name= "Word" AND TARGET.label != '')
GROUP BY session_id, labeltype_id, label_id
Your join is not a left join.
A left join adds NULL values for the right table if there are no rows that match the join condition.
However, you query does not have a join condition, and the WHERE condition is not affect by the LEFT JOIN clause.
Replace WHERE with ON.
I have tried to create the following trigger (DB2/LINUXX8664 9.7.2 running over Ubuntu 10.04.2 LTS) but I always get this:
Error report:
DB2 SQL error: SQLCODE: -1424, SQLSTATE: 54040, SQLERRMC: 2
According IBM DB2 documentation:
Too many references to transition variables and transition table columns or the row length for these references is too long. Reason code=rc.
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.5.0/com.ibm.db2.luw.messages.sql.doc/doc/msql01424n.html
I really do not understand that explanation. Here the stored procedure and trigger:
CREATE PROCEDURE SP_INSERT_UPDATE_REPNUM (
IN RECNUM INTEGER,
IN CUSTOMER_ID INTEGER,
IN Q_CODE VARCHAR(14),
IN S_CODE VARCHAR(14),
IN REP_STATUS INTEGER,
IN P_CODE INTEGER,
IN REPNUMRG_ID INTEGER,
IN VOLG_LET VARCHAR(1),
IN REP_DATUM DATE,
IN REP_INI VARCHAR(2),
IN INGEBOEKT_DATUM DATE,
IN INGEBOEKT_INI VARCHAR(2),
IN WIJZIGING_DATUM DATE,
IN WIJZIGING_INI VARCHAR(2),
IN OMSCR_STORING VARCHAR(5),
IN OMSCR_WERKZ VARCHAR(5),
IN OMSCR_OPMERKING VARCHAR(5),
IN OMSCR_GEBREK VARCHAR(5),
IN OMSCR_MAT VARCHAR(5),
IN REP_TIJD FLOAT,
IN REP_GEDAAN CHAR(1),
IN ACTION CHAR(1)
)
SPECIFIC SP_INSERT_UPDATE_REPNUM
DYNAMIC RESULT SETS 0
DETERMINISTIC
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO DBINFO
NOT FENCED
THREADSAFE
MODIFIES SQL DATA
PROGRAM TYPE SUB
EXTERNAL NAME 'RepairMigration!insertServiceReport'
and here the trigger:
CREATE TRIGGER INSERT_REPNUM
AFTER INSERT ON REPNUM
REFERENCING NEW ROW AS NROW
FOR EACH ROW MODE DB2SQL
BEGIN
CALL SP_INSERT_UPDATE_REPNUM(
NROW.RECNUM,
NROW.CUSTOMER_ID,
NROW.Q_CODE,
NROW.S_CODE,
NROW.REP_STATUS,
NROW.P_CODE,
NROW.REPNUMRG_ID,
NROW.VOLG_LET,
NROW.REP_DATUM,
NROW.REP_INI,
NROW.INGEBOEKT_DATUM,
NROW.INGEBOEKT_INI,
NROW.WIJZIGING_DATUM,
NROW.WIJZIGING_INI,
NROW.OMSCR_STORING,
NROW.OMSCR_WERKZ,
NROW.OMSCR_OPMERKING,
NROW.OMSCR_GEBREK,
NROW.OMSCR_MAT,
NROW.REP_TIJD,
NROW.REP_GEDAAN,
'I'
);
END
the table structure is thsi one:
RECNUM INTEGER 4 0 N
Q_CODE CHARACTER 14 0 N ''
U_Q_CODE CHARACTER 14 0 N
S_CODE CHARACTER 14 0 N ''
U_S_CODE CHARACTER 14 0 N
VOLG_LET CHARACTER 1 0 N ''
U_VOLG_LET CHARACTER 1 0 N
REP_DATUM DATE 4 0 N '0001-01-01'
REP_INI CHARACTER 2 0 N ''
P_CODE INTEGER 4 0 N 0
CUSTOMER_ID INTEGER 4 0 N 0
REPNUMHD_ID INTEGER 4 0 N 0
REPNUMRG_ID INTEGER 4 0 N 0
REP_STATUS SMALLINT 2 0 N 0
KONTAKT_PER CHARACTER 25 0 N ''
KONTAKT_TEL CHARACTER 20 0 N ''
OMSCR_STORING VARCHAR 512 0 N ''
OMSCR_WERKZ VARCHAR 2000 0 N ''
OMSCR_MAT VARCHAR 512 0 N ''
WIJZIGING_DATUM DATE 4 0 N '0001-01-01'
WIJZIGING_INI CHARACTER 2 0 N ''
INGEBOEKT_DATUM DATE 4 0 N '0001-01-01'
INGEBOEKT_INI CHARACTER 2 0 N ''
REP_GEDAAN CHARACTER 1 0 N ''
U_REP_GEDAAN CHARACTER 1 0 N
STATUS SMALLINT 2 0 N 0
UW_OPDRACHT CHARACTER 20 0 N ''
REP_UREN SMALLINT 2 0 N 0
REP_MINUTEN SMALLINT 2 0 N 0
OMSCR_OPMERKING VARCHAR 1008 0 N ''
OMSCR_GEBREK VARCHAR 512 0 N ''
SERVICE_NUMMER INTEGER 4 0 N 0
PRIJS_OPGAVE CHARACTER 1 0 N ''
CURRENCY SMALLINT 2 0 N 0
REP_TIJD INTEGER 4 0 N 0
After trying to execute the trigger, I get the error. How can I solve this?
UPDATE
It looks that I need to create a temporary tablespace. Listing all my tablespaces, I got some with more than 4k, for example this one:
Tablespace ID = 7
Name = TEMPSPACE1234
Type = Database managed space
Contents = All permanent data. Regular table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 1024
Useable pages = 1008
Used pages = 432
Free pages = 576
High water mark (pages) = 528
Page size (bytes) = 32768
Extent size (pages) = 16
Prefetch size (pages) = 16
Number of containers = 1
1) Create a 32K Buffer Pool
Example:
CREATE BUFFERPOOL "BUFFERPOOLLARGE" IMMEDIATE
ALL DBPARTITIONNUMS SIZE AUTOMATIC
NUMBLOCKPAGES 0
PAGESIZE 32 K;
2) Create a 32K SYSTEM TEMPORARY TABLESPACE
Example:
CREATE SYSTEM TEMPORARY TABLESPACE "TEMPSPACELARGE"
IN DATABASE PARTITION GROUP "IBMTEMPGROUP"
PAGESIZE 32 K
MANAGED BY AUTOMATIC STORAGE
EXTENTSIZE 32
BUFFERPOOL "BUFFERPOOLLARGE"
OVERHEAD INHERIT
TRANSFERRATE INHERIT
USING STOGROUP "IBMSTOGROUP"
FILE SYSTEM CACHING;
3) Run CREATE PROCEDURE Script Again.
OBS:In the examples I used DB2 automatic TABLESPACE.