• mes 入库单号 锁表方案


     

    1. 提取单别

    create table z_doctype as

    select distinct substr(INSTRUCTION_NUM, 0, 3) doctype from Z_INSTRUCTION_DOC where INSTRUCTION_NUM not like 'PP%'

     

    单别表结构

     

    程序优化方案如下:

    me 入库单 优化-防止多人入库取到同一个单号方案

    1. 原本取下一个单号的逻辑不变
    2. 在取原本取下一个单号前加一个 锁表逻辑  执行语句

                      select * from Z_DOCTYPE where DOCTYPE='单据前缀' for update nowait

    1. 上面的行锁 会随着  事物的  提交而自动解锁,无需其他代码

     

    取最大单号表sql

    select nvl2(max(INSTRUCTION_NUM),

    'AGK' || to_char(sysdate, 'yyyymmdd') || substr( '0000'|| to_char(to_number(substr(max(INSTRUCTION_NUM), -4)) + 1),-4),

    'AGK' || to_char(sysdate, 'yyyymmdd') || '0001'

    )

    from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like 'AGK' || to_char(sysdate, 'yyyymmdd') || '%';

     

    select max(INSTRUCTION_NUM) from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like 'AGK' || to_char(sysdate, 'yyyymmdd') || '%'

     

     

    c# 技术验证代码

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows.Forms;

     

    namespace 取单号锁表测试

    {

    public partial class Form1 : Form

    {

    string constring = @"Data Source=10.8.1.132:1521/MP1;User Id=wipdba;Password=Init1234";

    FluentData.IDbContext db = null;

     

    public Form1()

    {

    InitializeComponent();

    }

     

    private void Form1_Load(object sender, EventArgs e)

    {

    db = new FluentData.DbContext().ConnectionString(constring, new FluentData.OracleProvider(), "Oracle.ManagedDataAccess.Client");

     

    string sqlString = "select DOCTYPE from Z_DOCTYPE t";

    List<string> doctype = db.Sql(sqlString).QueryMany<string>();

    comboBox1.DataSource = doctype;

     

     

    }

     

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

     

    string sqlString = "select max(INSTRUCTION_NUM) from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || '%'";

    string x = db.Sql(sqlString).QuerySingle<string>();

     

    textBox2.Text = x;

    }

     

    private void button1_Click(object sender, EventArgs e)

    {

    try

    {

    textBox1.Text = "";

    db.UseTransaction(true);

    string sqlString = "select * from Z_DOCTYPE where DOCTYPE='" + comboBox1.Text + "' for update nowait ";

    db.Sql(sqlString).Execute();

     

     

     

    sqlString = "select nvl2(max(INSTRUCTION_NUM), " +

    " '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || substr( '0000'|| to_char(to_number(substr(max(INSTRUCTION_NUM), -4)) + 1),-4), " +

    " '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || '0001' " +

    " ) " +

    "from Z_INSTRUCTION_DOC t where INSTRUCTION_NUM like '" + comboBox1.Text + "' || to_char(sysdate, 'yyyymmdd') || '%'";

     

    textBox1.Text = db.Sql(sqlString).QuerySingle<string>();

     

     

    }

    catch (Exception ex)

    {

    db.Rollback();

    MessageBox.Show(ex.Message);

    }

     

    }

     

    private void button2_Click(object sender, EventArgs e)

    {

    try

    {

    db.Commit();

    MessageBox.Show("ok");

    }

    catch (Exception ex)

    {

     

    MessageBox.Show(ex.Message);

    }

    }

    }

    }

     

     

  • 相关阅读:
    时间操作、时间戳
    滚动条大于120px时,判断pc端的情况下,导航条固定定位
    通过js中的useragrent来判断设备是pc端还是移动端,跳转不同的地址
    js构建函数,点击按钮显示div,再点击按钮或其他区域,隐藏div
    localStorage用法总结
    轮播插件、原生js编写,弄懂这个,基本上各种轮播都可以自己写了
    (原)选择远比努力重要
    Java线程之间通信
    迪杰斯特拉(Java)
    FFTW中文参考
  • 原文地址:https://www.cnblogs.com/hlm750908/p/14415647.html
Copyright © 2020-2023  润新知