Home » Developer & Programmer » Forms » autonumber field - not/not null [merged] (form 6i)
autonumber field - not/not null [merged] [message #482567] Fri, 12 November 2010 11:05 Go to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
declare
a number;
b number;
begin
if :class_name = 'DAE (ELECTRICAL)' then
select nvl(id,0) into b from stu_info;
if b is null then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
Elsif :class_name = 'DAE (ELECTRONICS)' then
select nvl(id,0) into b from stu_info;
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
Elsif :class_name = 'DAE (CIVIL TECHNOLOGY)' then
select nvl(id,0) into b from stu_info;
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
Elsif :class_name = 'DAE (MECHNICAL TECHNOLOGY)' then
select nvl(id,0) into b from stu_info;
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
end if;
end;
next_item;
/forum/fa/8441/0/
  • Attachment: 123.JPG
    (Size: 63.60KB, Downloaded 1220 times)
Re: autonumber field if it is not null or null [message #482572 is a reply to message #482567] Fri, 12 November 2010 13:00 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
SQL> !oerr ora 1403
01403, 00000, "no data found"
// *Cause:
// *Action:


QED.

No exception handlers at all in this code.

[Updated on: Fri, 12 November 2010 13:01]

Report message to a moderator

Re: autonumber field if it is not null or null [message #482579 is a reply to message #482572] Fri, 12 November 2010 20:09 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
please correct the above code. How i can handle exceptions.
Re: autonumber field if it is not null or null [message #482598 is a reply to message #482579] Sat, 13 November 2010 09:25 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Shortly:
begin
  select ...
  
exception
  when no_data_found then
    do something
end

More reading:Understanding PL/SQL Error Handling.
autonumber [message #483116 is a reply to message #482567] Thu, 18 November 2010 09:47 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
Structure:
If class = 'DAE' then start from 3100 first time. then every time pick from table.
If class = 'B-Tech' then start from 4100 first time. then every time from table.
...pls check the attached code and advised me where i am wrong.
-----------------------------------------------------
declare
a number;
b number;
begin
select COUNT(id) into b from stu_info where class_name=:stu_info.class_name;
if :stu_info.class_name = 'DAE (CIVIL TECHNOLOGY)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where :class_name = 'DAE (CIVIL TECHNOLOGY)';
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and :stu_info.class_name ='DAE (CIVIL TECHNOLOGY)';
end if;
if :class_name = 'DAE (ELECTRICAL)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where :class_name = 'DAE (ELECTRICAL)';
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and :class_name ='DAE (ELECTRICAL)';
end if;
if :class_name = 'DAE (ELECTRONICS)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where :class_name = 'DAE (ELECTRONICS)';
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and :class_name ='DAE (ELECTRONICS)';
end if;
if :class_name = 'DAE (MECHNICAL TECHNOLOGY)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where :class_name = 'DAE (MECHNICAL TECHNOLOGY)';
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and :class_name ='DAE (MECHNICAL TECHNOLOGY)';
end if;
exception
when no_data_found then
Message('Please Enter The Roll No List in Session...');
Message('Please Enter The Roll No List in Session...');
Raise form_trigger_failure;
end;
next_item;
----------------------------------------------
Re: autonumber [message #483117 is a reply to message #483116] Thu, 18 November 2010 09:56 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
shahzad-ul-hasan wrote on Thu, 18 November 2010 15:47
Structure:
If class = 'DAE' then start from 3100 first time.

Start what from 3100?
Quote:

then every time pick from table.

Pick what from what table?

Quote:

If class = 'B-Tech' then start from 4100 first time. then every time from table.

Same questions as above.

Quote:

...pls check the attached code and advised me where i am wrong.

We have no idea what that code is supposed to do or what it is actually doing. Plus the complete lack of identation and white space makes it really hard to read.

So explain in detail what the code is supposed to do and what it is actually doing.
Repost the code, formatted, in [code] tags - see the fourm guide if you're not sure how
Re: autonumber [message #483119 is a reply to message #483117] Thu, 18 November 2010 10:00 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
Dear
my mean is that if i select a class 'DAE' the id should be start from 3100. and if i select class 'Btech' then the id should start from 4100. My problem is that when i select class 'DAE' the id start autonumber from 1. but i want to start from 3100 when no data exist.and next time it should pick its maximum from the table.
please advised.
Re: autonumber [message #483121 is a reply to message #483119] Thu, 18 November 2010 10:21 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
So you check if you found no data and if so use the value of 3100. That's programming at it's most basic.
Why ask where you're going wrong when the code makes no reference to the values you want to use?

By the way, this:
if :stu_info.class_name = 'DAE (CIVIL TECHNOLOGY)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info 
where :class_name = 'DAE (CIVIL TECHNOLOGY)';
Does the same as this:
if :stu_info.class_name = 'DAE (CIVIL TECHNOLOGY)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info 
where 1=1;

I assume the where clause should be refering to a column in the table and not an item in the datablock (which is what : signifies).
Likewise all your where clauses appear to be wrong.
Re: autonumber [message #483128 is a reply to message #483121] Thu, 18 November 2010 10:57 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
please check the attached file/forum/fa/8450/0/
  • Attachment: 123.JPG
    (Size: 63.60KB, Downloaded 1181 times)
Re: autonumber [message #483137 is a reply to message #483128] Thu, 18 November 2010 11:10 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
Use a no_data_found exception handler to catch the error and apply the value you want to use.
Re: autonumber [message #483151 is a reply to message #483128] Thu, 18 November 2010 12:33 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
Looks like a lack of ability to learn on your part. This is the same exact problem you had in your previous question. Exactly!

http://www.orafaq.com/forum/m/482567/66800/#msg_482567
Re: autonumber [message #483155 is a reply to message #483151] Thu, 18 November 2010 13:31 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
I HAVE REMOVED THE ERROR. BUT IT GIVES ME AUTONUMBER 1 INSTEAD OF 3100,4100,2100.FIRST TIME IT WILL PICK 2100 FROM INITLIZED STAGE AND STORED IN DATABASE.THEN AFTER IT WILL PICK THE MAX VALUES PLUS 1 FROM DATABASE. BUT IT NOT WORKING.PLEASE ADVISED.
Re: autonumber [message #483156 is a reply to message #483155] Thu, 18 November 2010 13:52 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
Here's one piece of advise - don't post in all capital letters, it's considered shouting, is against the forum guidelines, and puts people off helping you.

Past that - the code you have posted here contains no reference to the numbers you say you want to use. So write some code that does use those numbers. We don't mind helping people but we are not going to write your code for you.
Re: autonumber [message #483167 is a reply to message #483156] Thu, 18 November 2010 19:59 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and :class_name ='DAE (MECHNICAL TECHNOLOGY)';
here is the reference values i can used in first time. then pick from the tABLE.
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where LTRIM(class_name) =RTRIM('DAE (MECHNICAL TECHNOLOGY)');
Re: autonumber [message #483197 is a reply to message #483167] Fri, 19 November 2010 02:10 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
1) Use [code] tags as already asked. It makes code a lot easier to read - see the forum guide if you're not sure how.
2) Where does the value 3100 come into this?

[EDITED by LF: fixed URL and [url] tags]

[Updated on: Fri, 19 November 2010 02:49] by Moderator

Report message to a moderator

Re: autonumber [message #483580 is a reply to message #483197] Tue, 23 November 2010 04:30 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
2) Where does the value 3100 come into this?
i have stored these values(1100,2100,3100) in another table. that why i am calling these values first time. and then from the other table.
Re: autonumber [message #483584 is a reply to message #483121] Tue, 23 November 2010 04:40 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
And you didn't think it'd be a good idea to tell us?

Before you go any further fix this:

cookiemonster wrote on Thu, 18 November 2010 16:21
By the way, this:
if :stu_info.class_name = 'DAE (CIVIL TECHNOLOGY)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info 
where :class_name = 'DAE (CIVIL TECHNOLOGY)';
Does the same as this:
if :stu_info.class_name = 'DAE (CIVIL TECHNOLOGY)' and b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info 
where 1=1;

I assume the where clause should be refering to a column in the table and not an item in the datablock (which is what : signifies).
Likewise all your where clauses appear to be wrong.

Re: autonumber [message #483828 is a reply to message #483584] Wed, 24 November 2010 20:44 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
Dear
i have solved the problem.there is a little problem every time i create a new record.Its work for two or three enteries and then It pick up the maximum after two or three enteries.pls advised me where i can put this code in a trigger.
declare
a number;
b number;
begin
if :class_name = 'DAE (ELECTRICAL)' then
select nvl(id,0) into b from stu_info;
if b is null then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
Elsif :class_name = 'DAE (ELECTRONICS)' then
select nvl(id,0) into b from stu_info;
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
Elsif :class_name = 'DAE (CIVIL TECHNOLOGY)' then
select nvl(id,0) into b from stu_info;
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
Elsif :class_name = 'DAE (MECHNICAL TECHNOLOGY)' then
select nvl(id,0) into b from stu_info;
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;
end if;
end;
next_item;
--------------------------------------------------------------
Re: autonumber [message #483850 is a reply to message #483828] Thu, 25 November 2010 01:26 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:

select nvl(id,0) into b from stu_info; 

if b is null or b = 0 then

"b" won't be NULL - NVL handles that. But SELECT might raise
  • NO-DATA-FOUND if STU_INFO is empty
  • TOO-MANY-ROWS if there's more than 1 record in STU_INFO table

As of the original question (where to put "this" code) - what code? Bold one? What's wrong with the current place? There's, though, ELSIF that follows END IF so ... maybe there IS something wrong with the current place.

I admit, I have difficulties following what you are saying and what "two or three entries" are, what actually "works" and what doesn't.


I think that you should really pay some more attention to formatting your code (and, once you do that, applying [code] tags to preserve formatting when posting code on forum). It is difficult to read such a mess.
Re: autonumber [message #483878 is a reply to message #483850] Thu, 25 November 2010 04:08 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
You do realise that you're using the same code for each class_name don't you?
And you're populating a variable called a which you then don't use.

As we're getting nowhere fast I'll suggest that this:
select nvl(id,0) into b from stu_info; 
if b is null or b = 0 then
select nvl(max(roll),0)+1 into a from ses_det,sesion
where ses_det.ses_id=sesion.ses_id;
else
select nvl(max(id),0)+1 into :stu_info.id from stu_info;
end if;


Has one select too many, and as Littlefoot suggests is missing some exception handlers (quite why I'm not sure since you've added them once already).
This is probably closer to what you want:
  BEGIN
  
    select max(id) + 1 into :stu_info.id 
    from stu_info
    WHERE <some where clause that actually restricts by class name
           unlike your original where clause that did not despite what you thought>;
    
  EXCEPTION WHEN no_data_found THEN

    select nvl(max(roll),0)+1 into :stu_info.id  from ses_det,sesion
    where ses_det.ses_id=sesion.ses_id;
    
  END;


Note how that's formatted - it's a lot more readable than your code. That's how you should always format your code.
Re: autonumber [message #483916 is a reply to message #483878] Thu, 25 November 2010 09:23 Go to previous messageGo to next message
shahzad-ul-hasan
Messages: 625
Registered: August 2002
Senior Member
eclare
a number;
b number;
c varchar2(300);
begin
select COUNT(id) into b from stu_info
where class_name IN ('DAE (CIVIL TECHNOLOGY)','DAE (ELECTRICAL)',
'DAE (ELECTRONICS)','DAE (MECHNICAL TECHNOLOGY)');
if LTRIM(:CLASS_NAME)='DAE (CIVIL TECHNOLOGY)' THEN
IF B > 0 THEN
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where LTRIM(class_name)=RTRIM('DAE (CIVIL TECHNOLOGY)') ;
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and LTRIM(:class_name)=RTRIM('DAE (CIVIL TECHNOLOGY)');
end if;
ELSIF LTRIM(:CLASS_NAME)='DAE (ELECTRICAL)' THEN
IF B > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where LTRIM(:class_name)=RTRIM('DAE (ELECTRICAL)');
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and LTRIM(:class_name)=RTRIM('DAE (ELECTRICAL)');
end if;
ELSif LTRIM(:CLASS_NAME)='DAE (ELECTRONICS)' THEN
IF b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where LTRIM(class_name)=RTRIM('DAE (ELECTRONICS)');
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and LTRIM(:class_name)=RTRIM('DAE (ELECTRONICS)');
end if;
ELSif LTRIM(:CLASS_NAME)='DAE (MECHNICAL TECHNOLOGY)' THEN
IF b > 0 then
select nvl(max(id),0)+1 into :stu_info.id from stu_info
where LTRIM(class_name)=RTRIM('DAE (MECHNICAL TECHNOLOGY)') ;
else
select nvl(max(roll),0)+1 into :stu_info.id from ses_det,sesion
where ses_det.ses_id=sesion.ses_id and LTRIM(:class_name)=RTRIM('DAE (MECHNICAL TECHNOLOGY)');
End if;
END IF;
exception
when no_data_found then
Message('Please Enter The Roll No List in Session...');
Message('Please Enter The Roll No List in Session...');
Raise form_trigger_failure;
end;
next_item;

pls send me your email address so i will send you its movie. how the form is run/execute and then may you will in position to notify me where i can be wrong?
Re: autonumber [message #483919 is a reply to message #483916] Thu, 25 November 2010 09:48 Go to previous message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
You're not getting my email address.
I'm also not prepared to help you further if you're too lazy to format your code.
Read the forum guide and follow the instructions on formatting - use [code] tags not bold.
Previous Topic: Background color
Next Topic: List Item Background Colour
Goto Forum:
  


Current Time: Thu Sep 19 18:16:05 CDT 2024