Two issues I can see.
1). You are trying to assign a value to an 'in' parameter. It's possible that is failing.
2). When the table is empty, the very first select is going to return a NULL value. You are not handling this situation at all. Suggest you change your select to
select max(nvl(branchid,0))+1 into ....
:)