Skip to content

Instantly share code, notes, and snippets.

@hackvan
Created May 18, 2016 13:28
Show Gist options
  • Save hackvan/3bd1f9287ae3f72feffa4e9fe465628c to your computer and use it in GitHub Desktop.
Save hackvan/3bd1f9287ae3f72feffa4e9fe465628c to your computer and use it in GitHub Desktop.
PL/SQL Oracle: Ejemplo del uso del "For Update Of" y "Current Of"
Create Or Replace Function getCodSeq(xcodseque In Varchar2,xtam In Number Default Null) Return Varchar2 Is
xvalseque sfad012t.valseque%Type;
xcodprefi sfad012t.codprefi%Type;
xseque Varchar2(50);
Cursor c1 Is
Select nvl(valseque, 0) + nvl(incseque, 1), codprefi
Into xvalseque, xcodprefi
From sfad012t
Where codseque = xcodseque
For Update Of valseque;
Begin
Open c1;
Fetch c1 Into xvalseque, xcodprefi;
If c1%found Then
Update sfad012t
Set valseque = xvalseque
Where Current Of c1;
End If;
Close c1;
xseque := ltrim(rtrim(xcodprefi || lpad(xvalseque, nvl(xtam, length(xvalseque)), '0')));
Return xseque;
End getCodSeq;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment