Question : PLS_NUMBER vs NUMBER

what is the diff between the two and when will you use one over the other?

thanks

Answer : PLS_NUMBER vs NUMBER

simple example with 3 different types

PLS_INTEGER-  fails when the sequence goes above the data type limit  (2^31-1   or 2147483647)

INTEGER and NUMBER both succeed since both of these types have upper limits greater than that of a sequence

a sequence can only go to 9999999999999999999999999999   (28 digits)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
SQL> set serveroutput on
SQL> DROP SEQUENCE testseq1;

Sequence dropped.

SQL> CREATE SEQUENCE testseq1 MINVALUE 0 INCREMENT BY 100000000;

Sequence created.

SQL> DECLARE
  2      v_num PLS_INTEGER := 0;
  3  BEGIN
  4      FOR i IN 1 .. 100
  5      LOOP
  6          SELECT testseq1.NEXTVAL INTO v_num FROM DUAL;
  7
  8          DBMS_OUTPUT.put_line(v_num);
  9      END LOOP;
 10  END;
 11  /
0
100000000
200000000
300000000
400000000
500000000
600000000
700000000
800000000
900000000
1000000000
1100000000
1200000000
1300000000
1400000000
1500000000
1600000000
1700000000
1800000000
1900000000
2000000000
2100000000
DECLARE
*
ERROR at line 1:
ORA-01426: numeric overflow
ORA-06512: at line 6


SQL> DROP SEQUENCE testseq1;

Sequence dropped.

SQL> CREATE SEQUENCE testseq1 MINVALUE 0 INCREMENT BY 100000000;

Sequence created.

SQL> DECLARE
  2      v_num INTEGER := 0;
  3  BEGIN
  4      FOR i IN 1 .. 100
  5      LOOP
  6          SELECT testseq1.NEXTVAL INTO v_num FROM DUAL;
  7
  8          DBMS_OUTPUT.put_line(v_num);
  9      END LOOP;
 10  END;
 11  /
0
100000000
200000000
300000000
400000000
500000000
600000000
700000000
800000000
900000000
1000000000
1100000000
1200000000
1300000000
1400000000
1500000000
1600000000
1700000000
1800000000
1900000000
2000000000
2100000000
2200000000
2300000000
2400000000
2500000000
2600000000
2700000000
2800000000
2900000000
3000000000
3100000000
3200000000
3300000000
3400000000
3500000000
3600000000
3700000000
3800000000
3900000000
4000000000
4100000000
4200000000
4300000000
4400000000
4500000000
4600000000
4700000000
4800000000
4900000000
5000000000
5100000000
5200000000
5300000000
5400000000
5500000000
5600000000
5700000000
5800000000
5900000000
6000000000
6100000000
6200000000
6300000000
6400000000
6500000000
6600000000
6700000000
6800000000
6900000000
7000000000
7100000000
7200000000
7300000000
7400000000
7500000000
7600000000
7700000000
7800000000
7900000000
8000000000
8100000000
8200000000
8300000000
8400000000
8500000000
8600000000
8700000000
8800000000
8900000000
9000000000
9100000000
9200000000
9300000000
9400000000
9500000000
9600000000
9700000000
9800000000
9900000000

PL/SQL procedure successfully completed.

SQL> DROP SEQUENCE testseq1;

Sequence dropped.

SQL> CREATE SEQUENCE testseq1 MINVALUE 0 INCREMENT BY 100000000;

Sequence created.

SQL> DECLARE
  2      v_num NUMBER := 0;
  3  BEGIN
  4      FOR i IN 1 .. 100
  5      LOOP
  6          SELECT testseq1.NEXTVAL INTO v_num FROM DUAL;
  7
  8          DBMS_OUTPUT.put_line(v_num);
  9      END LOOP;
 10  END;
 11  /
0
100000000
200000000
300000000
400000000
500000000
600000000
700000000
800000000
900000000
1000000000
1100000000
1200000000
1300000000
1400000000
1500000000
1600000000
1700000000
1800000000
1900000000
2000000000
2100000000
2200000000
2300000000
2400000000
2500000000
2600000000
2700000000
2800000000
2900000000
3000000000
3100000000
3200000000
3300000000
3400000000
3500000000
3600000000
3700000000
3800000000
3900000000
4000000000
4100000000
4200000000
4300000000
4400000000
4500000000
4600000000
4700000000
4800000000
4900000000
5000000000
5100000000
5200000000
5300000000
5400000000
5500000000
5600000000
5700000000
5800000000
5900000000
6000000000
6100000000
6200000000
6300000000
6400000000
6500000000
6600000000
6700000000
6800000000
6900000000
7000000000
7100000000
7200000000
7300000000
7400000000
7500000000
7600000000
7700000000
7800000000
7900000000
8000000000
8100000000
8200000000
8300000000
8400000000
8500000000
8600000000
8700000000
8800000000
8900000000
9000000000
9100000000
9200000000
9300000000
9400000000
9500000000
9600000000
9700000000
9800000000
9900000000

PL/SQL procedure successfully completed.

SQL>
Random Solutions  
 
programming4us programming4us