How to carry a consecutive saving in an Oracle BD

-2

I must carry a consecutive document that increases as a document is printed, before I had it in a text document like this:

string conse1 = "consecutivo";
        string tempurl = "C:\docequi\" + conse1 + ".txt";
        LNumDoc.Text = File.ReadAllText(tempurl);
        int consecutivo = int.Parse(LNumDoc.Text);
        consecutivo = int.Parse(LNumDoc.Text) + 1;
        if (File.Exists(tempurl))
        {
            File.WriteAllText(tempurl, consecutivo.ToString());
        }

but I have problems with user permissions to overwrite the consecutive one.

Then create a CCONSECUTIVE table and the "consecutive (type INT)" field in ORACLE to write and consult the consecutive one, as INSERT could do in this case and the procedure to increment by 1 each time you open or close the APP?

work in VS with C #.

    
asked by Saul Salazar 16.08.2018 в 21:34
source

1 answer

0

You can create sequences in Oracle. That way, you have the incremental in the table every time. (I do not think you need the table)

Create a sequence:

CREATE SEQUENCE MI_SECUENCIA MINVALUE 1 START WITH 1
INCREMENT BY 1 CACHE 20;

Use the sequence:

SELECT MI_SECUENCIA.NEXTVAL FROM DUAL;

With that, you can bring the value of the sequence MI_SECUENCIA

link

If you are using C #, I do not think you should do anything else in the code that connects to Oracle and consume a stored procedure. So, you let oracle do things.

Your procedure in oracle would look something like this:

CREATE PROCEDURE get_secuencia(consec OUT NUMBER)
AS
BEGIN
   consec:= MI_SECUENCIA.NEXTVAL;       
END;

You do not need to insert into the table because the sequence is already updated with the incremental value.

The code of c # for what you want is something like this:

oracommand.Parameters.Add("consec", OracleDbType.Int32).Direction =ParameterDirection.Output;

oracommand.ExecuteNonQuery();
var c = oracommand.Parameters["consec"].value;
    
answered by 16.08.2018 / 21:49
source