zoukankan      html  css  js  c++  java
  • 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);

    }

    }

    }

    }

     

     

  • 相关阅读:
    mysql-community-server-5.7.24 & 5.7.31 (5.6.35 升级到 5.7.24)
    企业 数据 能力 中台 大数据平台 CRM
    Tomcat日志切割配置
    你不知道的 Blob
    细说websocket快速重连机制
    DNS反向查询
    从安全的角度看待DNS
    LVS 负载均衡集群
    Linux服务器配置DNS解析
    react修改state的值
  • 原文地址:https://www.cnblogs.com/hlm750908/p/14415647.html
Copyright © 2011-2022 走看看