如何在PL / SQL过程中进行此INSERT?

时间:2015-08-04 07:27:03

标签: oracle stored-procedures plsql sql-insert

我是pl / sql编程的新手,我需要你的帮助。

我想制作一个程序。

更具体地说,我有像下面的TABLE1

这样的表
from Tkinter import *
from ttk import *
import time


class supervisorcalc:
    def __init__(self, master):

        #####notebook tabs#####
        self.notebook = Notebook(master)
        self.lines = {}
        for i in range(10, 20):
            self.lines[i] = Frame(self.notebook)
            self.notebook.add(self.lines[i], text="Line" +  str(i))
        self.notebook.grid(row=0,column=0)
        ###end notebook tabs###

        moldoptions = [1, 1, 2, 3, 4]

###widget dictionaries###
    ### cycle time ###

        ###cycle time labels###
        self.ctlabels = {}
        for i in range(10, 20):
            self.ctlabels[i] = Label(self.lines[i], text = "Cycle Time:")

        ###cycle time variables###
        self.cycletimes = {}
        for i in range(10,20):
            self.cycletimes[i] = StringVar()

        ###cycle time entries###
        self.cycle_time_entries = {}
        for i in range(10,20):
            self.cycle_time_entries[i] = Entry(self.lines[i], textvariable=self.cycletimes[i])
    ###molds###

        ###mold combo box variables###
        self.moldvars = {}
        for i in range(10,20):
            self.moldvars[i] = IntVar()

        ###molds labels###
        self.heads_labels = {}
        for i in range(10,20):
            self.heads_labels[i] = Label(self.lines[i], text = "# of Molds:")

        ###molds combo box###
        self.head_combo_boxes = {}
        for i in range(10,20):
            self.head_combo_boxes[i] = OptionMenu(self.lines[i], self.moldvars[i], *moldoptions)

    ###cycle count###

        ###cycle count labels###
        self.cycle_count_labels = {}
        for i in range(10,20):
            self.cycle_count_labels[i] = Label(self.lines[i], text = "Cycle Count:")

        ###cycle count variables###
        self.cycle_count_vars = {}
        for i in range(10,20):
            self.cycle_count_vars[i] = StringVar()

        ###cycle count entries###
        self.cycle_count_entries = {}
        for i in range(10,20):
            self.cycle_count_entries[i] = Entry(self.lines[i], textvariable=self.cycle_count_vars[i])

    ### units per case###

        ### units per case labels###
        self.units_per_case_labels = {}
        for i in range(10,20):
            self.units_per_case_labels[i] = Label(self.lines[i], text = "Units/Case:")

        ### units per case variables#
        self.units_per_case_vars = {}
        for i in range(10,20):
            self.units_per_case_vars[i] = StringVar()

        ### units per case entries###
        self.units_per_case_entries = {}
        for i in range(10,20):
            self.units_per_case_entries[i] = Entry(self.lines[i], textvariable=self.units_per_case_vars[i])

    ### current case ###

        ### current case labels ###
        self.current_case_labels = {}
        for i in range(10, 20):
            self.current_case_labels[i] = Label(self.lines[i], text = "Current Case #:")

        ### current case variables ###
        self.current_case_vars = {}
        for i in range(10,20):
            self.current_case_vars[i] = StringVar()

        ### current case entries ###
        self.current_case_entries = {}
        for i in range(10, 20):
            self.current_case_entries[i]  = Entry(self.lines[i], textvariable=self.current_case_vars [i])

    ### current time ###

        ### current time labels###
        self.current_time_labels = {}
        for i in range (10, 20):
            self.current_time_labels[i] = Label(self.lines[i], text = "Current Time:")

        ### clock labels ###
        self.clocks = {}
        for i in range (10, 20):
            self.clocks[i] = Label(self.lines[i])

    ### future time ###

        ### future time extra frame###
        self.future_frames = {}
        for i in range (10, 20):
            self.future_frames[i] =  Frame(self.lines[i])

        ### future labels ###
        self.future_labels = {}
        for i in range (10, 20):
            self.future_labels[i] =  Label(self.lines[i], text = "Future Projections time:")

        ### future hour variables ###
        self.future_hours_vars = {}
        for i in range (10, 20):
            self.future_hours_vars[i] = StringVar()

        ### future hour entries ###
        self.future_hour_entries = {}
        for i in range (10, 20):
            self.future_hour_entries[i] = Entry(self.future_frames[i], width=2, textvariable=self.future_hours_vars[i])

        ### future time colon###
        self.future_time_colon = {}
        for i in range(10, 20):
            self.future_time_colon[i] = Label(self.future_frames[i], text = ":")

        ### future minutes variables###
        self.future_minutes_vars = {}
        for i in range(10,20):
            self.future_minutes_vars[i] = StringVar()

        ### future minutes entries###
        self.future_minutes = {}
        for i in range(10,20):
            self.future_minutes[i] = Entry(self.future_frames[i], width=2, textvariable=self.future_minutes_vars[i])

    ### cycle total ###

        ### cycle total labels ###
        self.total_cycles_labels = {}
        for i in range(10, 20):
            self.total_cycles_labels[i] = Label(self.lines[i], text = 'Cycle Total:')

        ### total cycles variables ###
        self.total_cycles_vars = {}
        for i in range(10,20):
            self.total_cycles_vars[i] = StringVar()

        ### total cycles display###
        self.total_cycles_disp = {}
        for i in range(10, 20):
            self.total_cycles_disp[i] = Label(self.lines[i], foreground = 'green', background = 'black', text = "00000", textvariable = self.total_cycles_vars[i])

    ### current production ###

        ### current production labels ###
        self.current_production_labels = {}
        for i in range(10, 20):
            self.current_production_labels[i] = Label(self.lines[i], text = 'Current Production:')

        ### current production variables ###
        self.current_production_vars = {}
        for i in range(10, 20):
            self.current_production_vars[i] = StringVar()

        ### current production ###
        self.current_production_disp = {}
        for i in range(10, 20):
            self.current_production_disp[i] = Label(self.lines[i], foreground = 'green', background = 'black', textvariable=self.current_production_vars[i])

    ### projected production ###

        ### projected production labels###
        self.projected_production_labels = {}
        for i in range(10, 20):
            self.projected_production_labels[i] = Label(self.lines[i], text = 'Projected Production:')

        ### projected production variables ###
        self.projected_production_vars = {}
        for i in range(10, 20):
            self.projected_production_vars[i] = StringVar()

        ### projected production display ###
        self.projected_production_disp = {}
        for i in range(10,20):
            self.projected_production_disp[i] = Label(self.lines[i], foreground = 'green', background = 'black', textvariable=self.projected_production_vars[i])

    ### lost units ###

        ### lost units labels ###
        self.lost_units_labels = {}
        for i in range(10, 20):
            self.lost_units_labels[i] = Label(self.lines[i], text = 'Lost units:')

        ### lost units variables ###
        self.lost_units_vars = {}
        for i in range(10, 20):
            self.lost_units_vars[i] = StringVar()

        ### lost units display ###
        self.lost_units_displays = {}
        for i in range(10, 20):
            self.lost_units_displays[i] = Label(self.lines[i], foreground = 'green', background = 'black', textvariable=self.lost_units_vars[i])

    ### projected lost units ###

        ### projectd lost units labels ###
        self.projected_lost_units_labels = {}
        for i in range(10, 20 ):
            self.projected_lost_units_labels[i] = Label(self.lines[i], text = 'Projected Lost units:')

        ### projected lost unit variables ###
        self.projected_lost_units_vars = {}
        for i in range(10, 20):
            self.projected_lost_units_vars[i] = StringVar()

        ### projected lost ###
        self.projected_lost_units_displays = {}
        for i in range(10, 20):
            self.projected_lost_units_displays[i] = Label(self.lines[i], foreground = 'green', background = 'black', textvariable=self.projected_lost_units_vars[i])

    ### efficiency ###

        ### efficiency labels ###
        self.current_efficiency_labels = {}
        for i in range(10,20):
            self.current_efficiency_labels[i] = Label(self.lines[i], text = 'Current efficiency %:')

        ### efficiency variables ###
        self.current_efficiency_vars = {}
        for i in range(10, 20):
            self.current_efficiency_vars[i] = StringVar()

        ### efficiency displays ###
        self.current_efficiency_displays = {}
        for i in range(10, 20):
            self.current_efficiency_displays[i] = Label(self.lines[i], foreground = 'green', background = 'black', textvariable=self.current_efficiency_vars[i])

    ### future case ###

        ### future case labels ###
        self.future_case_projection_labels = {}
        for i in range(10, 20):
            self.future_case_projection_labels[i] = Label(self.lines[i], text = 'Future case # projection:')

        ### future case variables ###
        self.future_case_projection_vars = {}
        for i in range(10, 20):
            self.future_case_projection_vars[i] = StringVar()

        ### future case displays ###
        self.future_case_projection_disp = {}
        for i in range(10, 20):
            self.future_case_projection_disp[i] = Label(self.lines[i], foreground = 'green', background = 'black', textvariable=self.future_case_projection_vars[i])

    ### projected efficiency ###

        ### projected efficiency labels ###
        self.projected_efficiency_labels = {}
        for i in range(10, 20):
            self.projected_efficiency_labels[i] = Label(self.lines[i], text = "Efficiency Projection:")

        ### projected efficiency variables ###
        self.projected_efficiency_vars = {}
        for i in range(10, 20):
            self.projected_efficiency_vars[i] = StringVar()

        ### projected efficiency entries ###
        self.projected_efficiency_entries = {}
        for i in range(10, 20):
            self.projected_efficiency_entries[i] = Entry(self.lines[i], textvariable=self.projected_efficiency_vars[i])









        ###functions###

        def cyclecnt(tab, *args):
            cyclecount = int(self.cycle_count_vars[tab].get())
            molds = self.moldvars[tab].get()
            cyccount = cyclecount * molds
            self.total_cycles_vars[tab].set(cyccount)            
            return


        def currentproduction(tab, *args):
            item = int(self.units_per_case_vars[tab].get())
            case = int(self.current_case_vars [tab].get())
            currprod = item * case
            self.current_production_vars[tab].set(currprod)
            return

        def lostunits(tab, *args):
            cycle = int(self.total_cycles_vars[tab].get())
            prod = int(self.current_production_vars[tab].get())
            self.lost_units_vars[tab].set(cycle - prod)
            return

        def efficiency(tab, *args):
            lost = float(self.lost_units_vars[tab].get())
            prod = float(self.current_production_vars[tab].get())
            self.current_efficiency_vars[tab].set((lost/prod)*100)
            return

        def getSec(x):
            l = x.split(':')
            return int(l[0]) * 3600 + int(l[1]) * 60 + int(l[2])

        def future_time_seconds(tab, *args):
            hrs = self.future_hours_vars[tab].get()
            mins = self.future_minutes_vars[tab].get()
            return (int(hrs) * 3600) + (int(mins) * 60)

        def time_difference_seconds(tab, *args):
            fseconds = future_time_seconds(tab)
            s = time.strftime('%I:%M:%S')
            cursecs = getSec(s)
            return fseconds - cursecs

        def proj(tab, *args):
            ctime = float(self.cycletimes[tab].get())
            prod = float(self.current_production_vars[tab].get())
            loss = float(self.lost_units_vars[tab].get())
            case = float(self.current_case_vars[tab].get())
            molds = float(self.moldvars[tab].get())
            item = float(self.units_per_case_vars[tab].get())

            seconds = time_difference_seconds(tab)

            pcycle = ((molds / ctime) * seconds)
            projeff = float(self.projected_efficiency_vars[tab].get()) / float(100)

            pproduction = pcycle - (pcycle * projeff)

            self.projected_production_vars[tab].set(prod + pproduction)                     
            projloss = loss + pcycle * projeff
            self.projected_lost_units_vars[tab].set(projloss)

            fcase = case + (pproduction / float(item))
            self.future_case_projection_vars[tab].set(fcase)

### widget fuction ###

        def widg_on_panes(self, num):

            ### cycle time ###
            self.ctlabels[num].grid(row=2, column=0) 
            self.cycletimes[num].trace('w', lambda x,y,z: proj(num))
            self.cycle_time_entries[num].grid(row=2,column=1)

            ### molds ###
            self.moldvars[num].set(moldoptions[0])
            self.heads_labels[num].grid(row=3, column=0)
            self.head_combo_boxes[num].grid(row=3,column=1)
            self.moldvars[num].trace("w", lambda x, y, z: cyclecnt(num))

            ### cycle count ###
            self.cycle_count_labels[num].grid(row=4, column=0)
            self.cycle_count_vars[num].trace("w", lambda x, y, z: cyclecnt(num))
            self.cycle_count_entries[num].grid(row=4,column=1)

            ### units per case ###
            self.units_per_case_labels[num].grid(row=5, column=0)
            self.units_per_case_entries[num].grid(row=5,column=1)
            self.units_per_case_vars[num].trace("w", lambda x, y, z: currentproduction(num))

            ### current case ###      
            self.current_case_labels[num].grid(row=6, column=0)
            self.current_case_entries[num].grid(row=6,column=1)
            self.current_case_vars[num].trace("w", lambda x, y, z: currentproduction(num))

            ### clock ###
            self.current_time_labels[num].grid(row=7, column=0, sticky='W')
            self.clocks[num].grid(row=7,column=1, sticky='w')

            #### future time ###
            self.future_frames[num].grid(row=8, column=1)           
            self.future_labels[num].grid(row=8, column=0, sticky='w')
            self.future_hours_vars[num].trace('w', lambda x, y, z: proj(num))
            self.future_hour_entries[num].grid(row=0, column=0) 
            self.future_time_colon[num].grid(row=0, column=1)
            self.future_minutes_vars[num].trace('w', lambda x, y, z: proj(num))
            self.future_minutes[num].grid(row=0, column=2)


            ### total cycle display ### 
            self.total_cycles_labels[num].grid(row=2, column=2)
            self.total_cycles_vars[num].set("00000")
            self.total_cycles_vars[num].trace('w', lambda x, y, z: lostunits(num))
            self.total_cycles_disp[num].grid(row=2, column=3)

            ### current production ###
            self.current_production_labels[num].grid(row=3, column=2)
            self.current_production_vars[num].set('00000')           
            self.current_production_vars[num].trace('w', lambda x, y, z: lostunits(num))
            self.current_production_vars[num].trace('w', lambda x, y, z: efficiency(num))
            self.current_production_disp[num].grid(row=3, column=3)

            ### projected production ###    
            self.projected_production_labels[num].grid(row=4, column=2)
            self.projected_production_vars[num].set('00000')
            self.projected_production_disp[num].grid(row=4, column=3)

            ### lost units ###
            self.lost_units_labels[num].grid(row=5, column=2)
            self.lost_units_vars[num].set("0000")
            self.lost_units_vars[num].trace('w', lambda x, y, z: efficiency(num))
            self.lost_units_displays[num].grid(row=5, column=3)

            ### projected lost uniots ###c            
            self.projected_lost_units_labels[num].grid(row=6, column=2)
            self.projected_lost_units_vars[num].set("0000")
            self.projected_lost_units_displays[num].grid(row=6, column=3)

            ### current efficiency ###
            self.current_efficiency_labels[num].grid(row=7, column=2)
            self.current_efficiency_vars[num].set("00.00") 
            self.current_efficiency_displays[num].grid(row=7, column=3)

            ### future case ###
            self.future_case_projection_labels[num].grid(row=8, column=2)
            self.future_case_projection_vars[num].set("000.0")
            self.future_case_projection_disp[num].grid(row=8, column=3)

            ### projected efficiency ###
            self.projected_efficiency_labels[num].grid(row=9, column=2)
            self.projected_efficiency_vars[num].set(0.00)
            self.projected_efficiency_vars[num].trace('w', lambda x, y, z: proj(num))
            self.projected_efficiency_entries[num].grid(row=9,column=3)



        for num in range(10,20):
            widg_on_panes(self, num)


        def tick():
            s = time.strftime('%I:%M:%S')
            if s != self.clocks[10]:
                for i in range(10, 20):
                    self.clocks[i].configure(text=s)
            self.notebook.after(200, tick)

        tick()

root = Tk()
root.wm_title("Hillside Plastics Production Calculator")
calc = supervisorcalc(root)

mainloop()

对于相同的COL1和COL2 / COL3,请检查从COL4中选择不同的值 例如,对于COL1 = 600,COL2 = 140 / COL3 = 2并且COL2 = 150 / COL3 = 3 返回20和35

并在此表中插入TABLE1行

================================================
|COL1 | COL2 | COL3 | COL4 | COL5 | COL6 |COL7|
===============================================
|600 | 140 | 2 | 10 | 1300 | 500 | 1 |
|600 | 140 | 2 | 20 | 1400 | 340 | 4 |
|600 | 140 | 2 | 15 | 1400 | 230 | 3 |
|600 | 140 | 2 | 35 | 1700 | 120 | 2 |
|600 | 150 | 3 | 10 | 1300 | 166 | 6 |
|600 | 150 | 3 | 15 | 1400 | 435 | 5 |
----------------------------------------------

如果P_FLG1 =' Y',我在表1中进行插入。如果P_FLG2 =' Y'我也在TABLE3等中插入

我正在尝试制作如下的程序,但我无法完成它

600 , 150 , 3, 20 , 1400 , 340, 7 (seq number)
600 , 150 , 3, 35 , 1700 , 120, 8 (seq number)

如果你能帮助我,我将不胜感激。

非常感谢

1 个答案:

答案 0 :(得分:1)

CFL1.COL4无法正常工作,因为您需要引用结果集变量:REC.COL4。

指定要插入的表的列并不会有什么坏处。 例如:

INSERT INTO TABLE1 (col1, col2) values (rec.col1, rec.col2);

INSERT INTO TABLE1 (col1, col2) select rec.col1, rec.col2 from dual;

此外,您首先获取CFL1,期望只有1个记录值。 但是然后在循环中使用相同的游标。删除fetch并从REC获取col4值?无论如何,直接选择程序都不会有效。