Missing " assign " operation in Yosys topological order command - yosys
I am working on privacy preserving verification tool, where I used yosys to get the topological order of the netlist as in question ( gate level parsing using yosys). It is working perfectly and gave me the correct order in most of the cases. However, when I have the assign operation as in iscas89 s386, I added the and to get this output from a cell, but I got the wrong output order cells ( O1 O2 O3 O4 O5 O6). In what follow I'll give an example.
For the input 01110110010 (in certain clock cycle)
The expected output for s386 is : 11000000 , but I am getting : 0011000
After debugging the code manually, I figured out the wrong was in the topological order of the assign operation, yosys didnt take assign operation into consideration and kept it as is. Below is the netlist and yosys output
S386 netlist :
module s386 ( GND, VDD, CK, R, v0, v1, v13_D_10, v13_D_11, v13_D_12, v13_D_6,v13_D_7, v13_D_8, v13_D_9, v2, v3, v4, v5, v6 );
input GND, VDD, CK, R, v0, v1, v2, v3, v4, v5, v6;
output v13_D_10, v13_D_11, v13_D_12, v13_D_6, v13_D_7, v13_D_8, v13_D_9;
wire v12, v11, v10, v9, v8, v7, Lv13_D_12, Lv13_D_11, Lv13_D_10,Lv13_D_9,
Lv13_D_8, Lv13_D_7, Lv13_D_6, Lv13_D_5, Lv13_D_4, Lv13_D_3, Lv13_D_2,
Lv13_D_1, Lv13_D_0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n12, n15, n16,
n17, n18, n19, n20, n21, n22, n23, n24, n25, n26, n27, n28, n29, n30,
n31, n32, n33, n34, n35, n36, n37, n38, n39, n40, n41, n42, n43, n44,
n45, n46, n47, n48, n49, n50, n51, n52, n53, n54, n55, n56, n57, n58,
n59, n60, n61, n62, n63, n64, n65, n66, n67, n68, n69, n70, n71, n72,
n73, n74, n75, n76, n77, n78, n79, n80, n81, n82, n83, n84, n85, n86,
n87, n88, n89, n90, n91, n92, n93, n94, n95, n96, n97, n98, n99, n100,
n101, n102, n103, n104, n105, n106, n107, n108, n109, n110, n111,
n112, n113, n114;
assign v13_D_12 = Lv13_D_12;
assign v13_D_11 = Lv13_D_11;
assign v13_D_10 = Lv13_D_10;
assign v13_D_9 = Lv13_D_9;
assign v13_D_8 = Lv13_D_8;
assign v13_D_7 = Lv13_D_7;
assign v13_D_6 = Lv13_D_6;
AND2X1 O1 ( .A(Lv13_D_12), .B(Lv13_D_12), .Y(v13_D_12) );
AND2X1 O2 ( .A(Lv13_D_11), .B(Lv13_D_11), .Y(v13_D_11) );
AND2X1 O3 ( .A(Lv13_D_10), .B(Lv13_D_10), .Y(v13_D_10) );
AND2X1 O4 ( .A(Lv13_D_9), .B(Lv13_D_9), .Y(v13_D_9) );
AND2X1 O5 ( .A(Lv13_D_8), .B(Lv13_D_8), .Y(v13_D_8) );
AND2X1 O6 ( .A(Lv13_D_7), .B(Lv13_D_7), .Y(v13_D_7) );
AND2X1 O7 ( .A(Lv13_D_6), .B(Lv13_D_6), .Y(v13_D_6) );
DFFSR \DFF_5/Q_reg ( .D(Lv13_D_0), .CLK(CK), .R(R), .Q(v7) );
DFFSR \DFF_4/Q_reg ( .D(Lv13_D_1), .CLK(CK), .R(R), .Q(v8) );
DFFSR \DFF_1/Q_reg ( .D(Lv13_D_4), .CLK(CK), .R(R), .Q(v11) );
DFFSR \DFF_0/Q_reg ( .D(Lv13_D_5), .CLK(CK), .R(R), .Q(v12) );
DFFSR \DFF_3/Q_reg ( .D(Lv13_D_2), .CLK(CK), .R(R), .Q(v9) );
DFFSR \DFF_2/Q_reg ( .D(Lv13_D_3), .CLK(CK), .R(R), .Q(v10) );
INVX1 U1 ( .A(n75), .Y(n1) );
INVX1 U2 ( .A(v0), .Y(n2) );
INVX1 U3 ( .A(v1), .Y(n3) );
INVX1 U4 ( .A(n41), .Y(n4) );
INVX1 U5 ( .A(n101), .Y(n5) );
INVX1 U6 ( .A(v4), .Y(n6) );
INVX1 U7 ( .A(v5), .Y(n7) );
INVX1 U8 ( .A(v6), .Y(n8) );
INVX1 U9 ( .A(v12), .Y(n9) );
INVX1 U12 ( .A(v9), .Y(n12) );
OR2X1 U15 ( .A(n15), .B(n16), .Y(Lv13_D_9) );
AND2X1 U16 ( .A(n17), .B(n18), .Y(n15) );
AND2X1 U17 ( .A(n19), .B(n3), .Y(n18) );
AND2X1 U18 ( .A(n109), .B(n113), .Y(n19) );
AND2X1 U19 ( .A(n20), .B(v4), .Y(n17) );
AND2X1 U20 ( .A(n21), .B(n5), .Y(n20) );
AND2X1 U21 ( .A(n8), .B(n16), .Y(Lv13_D_8) );
AND2X1 U22 ( .A(n22), .B(n23), .Y(Lv13_D_7) );
OR2X1 U23 ( .A(n24), .B(n25), .Y(n23) );
AND2X1 U24 ( .A(n26), .B(n111), .Y(n24) );
OR2X1 U25 ( .A(n27), .B(n28), .Y(Lv13_D_6) );
AND2X1 U26 ( .A(v5), .B(n29), .Y(n28) );
AND2X1 U27 ( .A(n30), .B(n22), .Y(n27) );
AND2X1 U28 ( .A(n31), .B(n106), .Y(n30) );
OR2X1 U29 ( .A(n32), .B(n33), .Y(n31) );
AND2X1 U30 ( .A(n114), .B(v4), .Y(n33) );
AND2X1 U31 ( .A(n34), .B(n35), .Y(n32) );
OR2X1 U32 ( .A(v2), .B(n114), .Y(n35) );
OR2X1 U33 ( .A(v3), .B(n111), .Y(n34) );
OR2X1 U34 ( .A(n36), .B(n29), .Y(Lv13_D_5) );
AND2X1 U35 ( .A(n37), .B(n22), .Y(n36) );
AND2X1 U36 ( .A(n112), .B(n38), .Y(n37) );
OR2X1 U37 ( .A(n39), .B(n26), .Y(n38) );
AND2X1 U38 ( .A(n40), .B(v3), .Y(n39) );
AND2X1 U39 ( .A(n41), .B(n106), .Y(n40) );
OR2X1 U40 ( .A(n42), .B(n43), .Y(Lv13_D_4) );
AND2X1 U41 ( .A(n22), .B(n44), .Y(n43) );
OR2X1 U42 ( .A(n45), .B(n46), .Y(n44) );
OR2X1 U43 ( .A(n114), .B(n25), .Y(n46) );
AND2X1 U44 ( .A(n47), .B(v2), .Y(n45) );
AND2X1 U45 ( .A(n106), .B(n111), .Y(n47) );
AND2X1 U46 ( .A(n29), .B(n7), .Y(n42) );
AND2X1 U47 ( .A(n48), .B(n49), .Y(n29) );
AND2X1 U48 ( .A(n50), .B(n107), .Y(n49) );
OR2X1 U49 ( .A(n51), .B(n52), .Y(Lv13_D_3) );
AND2X1 U50 ( .A(n53), .B(n54), .Y(n51) );
OR2X1 U51 ( .A(n55), .B(n56), .Y(n54) );
AND2X1 U52 ( .A(n57), .B(v1), .Y(n55) );
AND2X1 U53 ( .A(n110), .B(n7), .Y(n57) );
OR2X1 U54 ( .A(n58), .B(n59), .Y(Lv13_D_2) );
OR2X1 U55 ( .A(n52), .B(n60), .Y(n59) );
AND2X1 U56 ( .A(n61), .B(n62), .Y(n60) );
AND2X1 U57 ( .A(n2), .B(n7), .Y(n61) );
AND2X1 U58 ( .A(n63), .B(v1), .Y(n58) );
AND2X1 U59 ( .A(v0), .B(n53), .Y(n63) );
AND2X1 U60 ( .A(n64), .B(n65), .Y(Lv13_D_12) );
AND2X1 U61 ( .A(n110), .B(n2), .Y(n65) );
AND2X1 U62 ( .A(n62), .B(v5), .Y(n64) );
OR2X1 U63 ( .A(n66), .B(n67), .Y(Lv13_D_11) );
OR2X1 U64 ( .A(n52), .B(n16), .Y(n67) );
AND2X1 U65 ( .A(n68), .B(n69), .Y(n16) );
AND2X1 U66 ( .A(v0), .B(n110), .Y(n69) );
AND2X1 U67 ( .A(n12), .B(n53), .Y(n68) );
AND2X1 U68 ( .A(n109), .B(n70), .Y(n52) );
OR2X1 U69 ( .A(n71), .B(n72), .Y(n70) );
AND2X1 U70 ( .A(n56), .B(n73), .Y(n72) );
OR2X1 U71 ( .A(n74), .B(n2), .Y(n56) );
AND2X1 U72 ( .A(v1), .B(n12), .Y(n74) );
AND2X1 U73 ( .A(n75), .B(n21), .Y(n71) );
AND2X1 U74 ( .A(n76), .B(n21), .Y(n66) );
AND2X1 U75 ( .A(n12), .B(n9), .Y(n21) );
AND2X1 U76 ( .A(n77), .B(n109), .Y(n76) );
OR2X1 U77 ( .A(n78), .B(n25), .Y(n77) );
AND2X1 U78 ( .A(n26), .B(n112), .Y(n78) );
AND2X1 U79 ( .A(n107), .B(n114), .Y(n26) );
AND2X1 U80 ( .A(n79), .B(n62), .Y(Lv13_D_10) );
AND2X1 U81 ( .A(n53), .B(n108), .Y(n62) );
AND2X1 U82 ( .A(n73), .B(n80), .Y(n53) );
AND2X1 U83 ( .A(n9), .B(n106), .Y(n80) );
AND2X1 U84 ( .A(v1), .B(n81), .Y(n79) );
OR2X1 U85 ( .A(n82), .B(n109), .Y(n81) );
AND2X1 U86 ( .A(v5), .B(v0), .Y(n82) );
AND2X1 U87 ( .A(n50), .B(n83), .Y(Lv13_D_1) );
OR2X1 U88 ( .A(n84), .B(n85), .Y(n83) );
AND2X1 U89 ( .A(n48), .B(n106), .Y(n85) );
AND2X1 U90 ( .A(n73), .B(n105), .Y(n48) );
AND2X1 U91 ( .A(n111), .B(n113), .Y(n73) );
AND2X1 U92 ( .A(n86), .B(n9), .Y(n84) );
OR2X1 U93 ( .A(n87), .B(n88), .Y(n86) );
AND2X1 U94 ( .A(n89), .B(n106), .Y(n88) );
OR2X1 U95 ( .A(n90), .B(n91), .Y(n89) );
AND2X1 U96 ( .A(v4), .B(n92), .Y(n91) );
OR2X1 U97 ( .A(n93), .B(n114), .Y(n92) );
AND2X1 U98 ( .A(v2), .B(n111), .Y(n93) );
AND2X1 U99 ( .A(n94), .B(v3), .Y(n90) );
AND2X1 U100 ( .A(n112), .B(n4), .Y(n94) );
AND2X1 U101 ( .A(n113), .B(v2), .Y(n41) );
AND2X1 U102 ( .A(n107), .B(n95), .Y(n87) );
OR2X1 U103 ( .A(n96), .B(n97), .Y(n95) );
AND2X1 U104 ( .A(n112), .B(n113), .Y(n97) );
AND2X1 U105 ( .A(n98), .B(v5), .Y(n96) );
AND2X1 U106 ( .A(n114), .B(n111), .Y(n98) );
AND2X1 U107 ( .A(n22), .B(n99), .Y(Lv13_D_0) );
OR2X1 U108 ( .A(n100), .B(n25), .Y(n99) );
AND2X1 U109 ( .A(n6), .B(n5), .Y(n25) );
OR2X1 U110 ( .A(n111), .B(n102), .Y(n101) );
OR2X1 U111 ( .A(v3), .B(n107), .Y(n102) );
AND2X1 U112 ( .A(n107), .B(n103), .Y(n100) );
OR2X1 U113 ( .A(n111), .B(n113), .Y(n103) );
AND2X1 U114 ( .A(n9), .B(n50), .Y(n22) );
AND2X1 U115 ( .A(n1), .B(n104), .Y(n50) );
AND2X1 U116 ( .A(n12), .B(n109), .Y(n104) );
OR2X1 U117 ( .A(v1), .B(n2), .Y(n75) );
INVX1 U118 ( .A(n9), .Y(n105) );
INVX1 U119 ( .A(v11), .Y(n106) );
INVX1 U120 ( .A(n106), .Y(n107) );
INVX1 U121 ( .A(n12), .Y(n108) );
INVX1 U122 ( .A(v10), .Y(n109) );
INVX1 U123 ( .A(n109), .Y(n110) );
INVX1 U124 ( .A(v8), .Y(n111) );
INVX1 U125 ( .A(n111), .Y(n112) );
INVX1 U126 ( .A(v7), .Y(n113) );
INVX1 U127 ( .A(n113), .Y(n114) );
endmodule
Yosys commands:
read_verilog s386.v
hierarchy -generate * o:Y o:Q i:*
torder -stop DFFSR Q
Yosys output:
loop O1
loop O2
loop O3
loop O4
loop O5
loop O6
loop O7
cell U2
cell U117
cell U1
cell U12
cell U122
cell U116
cell U115
cell U9
cell U114
cell U124
cell U125
cell U126
cell U101
cell U119
cell U39
cell U38
cell U120
cell U127
cell U79
cell U37
cell U36
cell U35
cell U48
cell U118
cell U91
cell U90
cell U47
cell U34
cell DFF_0/Q_reg
cell U111
cell U110
cell U5
cell U6
cell U109
cell U43
cell U45
cell U44
cell U42
cell U41
cell U7
cell U46
cell U40
cell DFF_1/Q_reg
cell U123
cell U53
cell U52
cell U72
cell U71
cell U51
cell U83
cell U82
cell U50
cell U70
cell U75
cell U73
cell U69
cell U68
cell U49
cell DFF_2/Q_reg
cell U57
cell U121
cell U81
cell U56
cell U55
cell U59
cell U58
cell U54
cell DFF_3/Q_reg
cell U89
cell U104
cell U106
cell U105
cell U103
cell U102
cell U98
cell U97
cell U96
cell U4
cell U100
cell U99
cell U95
cell U94
cell U93
cell U92
cell U88
cell U87
cell DFF_4/Q_reg
cell U113
cell U112
cell U108
cell U107
cell DFF_5/Q_reg
cell U61
cell U62
cell U60
cell O1
cell U66
cell U67
cell U65
cell U64
cell U78
cell U77
cell U76
cell U74
cell U63
cell O2
cell U86
cell U85
cell U84
cell U80
cell O3
cell U18
cell U3
cell U17
cell U20
cell U19
cell U16
cell U15
cell O4
cell U8
cell U21
cell O5
cell U24
cell U23
cell U22
cell O6
cell U26
cell U30
cell U32
cell U33
cell U31
cell U29
cell U28
cell U27
cell U25
cell O7
I really appreciate your help and feed backs.
Related
Oracle repeated function calls in select and where clause
I have the following Oracle SQL query select /*+ORDERED */ payr.payroll_name payroll_name, nvl(papf.employee_number, papf.npw_number) employee_number, nvl ( xxpay_util.safe_to_number ( xxpay_util_element.get_run_result ( p_business_group_id => paaf.business_group_id, -- in number p_payroll_id => paaf.payroll_id, -- in number p_payroll_action_id => null, -- in number, p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Disability Cover ER$', -- in varchar2 '^Disability Cover ER Opt Out$' p_input_value => 'Pay Value', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'sum', -- in varchar2 p_round => 2 -- in number default 2 ) ), 0 ) disability_benefit, nvl ( xxpay_util.safe_to_number ( xxpay_util_element.get_run_result ( p_business_group_id => paaf.business_group_id, -- in number p_payroll_id => paaf.payroll_id, -- in number p_payroll_action_id => null, -- in number, p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Death Cover ER Opt Out$', -- in varchar2 p_input_value => 'Pay Value', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'sum', -- in varchar2 p_round => 2 -- in number default 2 ) ), 0 ) death_cover, nvl ( xxpay_util.safe_to_number ( xxpay_util_element.get_run_result ( p_business_group_id => paaf.business_group_id, -- in number p_payroll_id => paaf.payroll_id, -- in number p_payroll_action_id => null, -- in number, p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Funeral Cover ER$', -- in varchar2 '^Funeral Cover ER Opt Out$' p_input_value => 'Pay Value', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'sum', -- in varchar2 p_round => 2 -- in number default 2 ) ), 0 ) funeral_cover, ppos.actual_termination_date termination_date from ( select ptp.payroll_id, min(ptp.start_date) real_month_start, max(ptp.end_date) real_month_end from per_time_periods ptp where decode(ptp.prd_information_category, 'ZA', to_char(ptp.pay_advice_date, 'yyyymm'), to_char(ptp.regular_payment_date, 'yyyymm')) = '201612' group by ptp.payroll_id ) mon, pay_all_payrolls_f payr, per_all_assignments_f paaf, per_periods_of_service ppos, per_people_f papf, per_business_groups pbg, hr_all_organization_units haou, per_jobs pj, pay_cost_allocation_keyflex pcak where payr.payroll_id = mon.payroll_id and mon.real_month_end between payr.effective_start_date and payr.effective_end_date and paaf.payroll_id = mon.payroll_id and paaf.assignment_type = 'E' and paaf.primary_flag = 'Y' and paaf.effective_start_date = ( select max(paaf2.effective_start_date) from per_all_assignments_f paaf2 where paaf2.assignment_id = paaf.assignment_id and paaf2.assignment_type = 'E' and paaf2.primary_flag = 'Y' and paaf2.payroll_id = mon.payroll_id and mon.real_month_start <= paaf2.effective_end_date and mon.real_month_end >= paaf2.effective_start_date ) and ppos.period_of_service_id = paaf.period_of_service_id and mon.real_month_start <= nvl(ppos.actual_termination_date, to_date('31/12/4712', 'dd/mm/yyyy')) and mon.real_month_end >= ppos.date_start and papf.person_id = paaf.person_id and papf.effective_start_date = ( select max(papf2.effective_start_date) from per_all_people_f papf2 where papf2.person_id = paaf.person_id and mon.real_month_start <= papf2.effective_end_date and mon.real_month_end >= papf2.effective_start_date ) and pbg.business_group_id = paaf.business_group_id and haou.organization_id (+) = paaf.organization_id and pj.job_id (+) = paaf.job_id and pcak.cost_allocation_keyflex_id (+) = haou.cost_allocation_keyflex_id and ( nvl ( xxpay_util.safe_to_number ( xxpay_util_element.get_run_result ( p_business_group_id => paaf.business_group_id, -- in number p_payroll_id => paaf.payroll_id, -- in number p_payroll_action_id => null, -- in number, p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Disability Cover ER$', -- in varchar2 -- Disability Cover ER Opt Out p_input_value => 'Pay Value', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'sum', -- in varchar2 p_round => 2 -- in number default 2 ) ), 0 ) + nvl ( xxpay_util.safe_to_number ( xxpay_util_element.get_run_result ( p_business_group_id => paaf.business_group_id, -- in number p_payroll_id => paaf.payroll_id, -- in number p_payroll_action_id => null, -- in number, p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Death Cover ER Opt Out$', -- in varchar2 p_input_value => 'Pay Value', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'sum', -- in varchar2 p_round => 2 -- in number default 2 ) ), 0 ) + nvl ( xxpay_util.safe_to_number ( xxpay_util_element.get_run_result ( p_business_group_id => paaf.business_group_id, -- in number p_payroll_id => paaf.payroll_id, -- in number p_payroll_action_id => null, -- in number, p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Funeral Cover ER$', -- in varchar2 -- Funeral Cover ER Opt Out p_input_value => 'Pay Value', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'sum', -- in varchar2 p_round => 2 -- in number default 2 ) ), 0 ) ) != 0 and nvl ( xxpay_util_element.get_element_entry ( p_business_group_id => paaf.business_group_id, -- in number p_start_period => mon.real_month_start, -- in date p_end_period => mon.real_month_end, -- in date p_element_name_regex => '^Retirement Fund Opt In$', -- in varchar2 p_input_value => 'Opt In or Out', -- in varchar2 p_assignment_id => paaf.assignment_id, -- in number p_aggregation => 'none', -- in varchar2 p_round => 0 -- in number default 2 ), '$XXX$' ) in ('NC', 'OUT') and exists ( select 1 from pay_payroll_actions ppap, pay_assignment_actions paap, pay_action_interlocks pai, pay_assignment_actions paar, pay_payroll_actions ppar, per_time_periods ptp where ppap.action_type in ('P', 'U') and ppap.action_status = 'C' and paap.payroll_action_id = ppap.payroll_action_id and paap.action_status = 'C' and pai.locking_action_id = paap.assignment_action_id and paar.assignment_action_id = pai.locked_action_id and ppar.payroll_action_id = paar.payroll_action_id and ppar.action_type in ('R', 'Q') and ptp.time_period_id = ppar.time_period_id and decode(ptp.prd_information_category, 'ZA', to_char(ptp.pay_advice_date, 'yyyymm'), to_char(ptp.regular_payment_date, 'yyyymm')) = '201612' and paap.assignment_id = paaf.assignment_id and paar.assignment_id = paaf.assignment_id ) order by pcak.segment2, papf.employee_number, paaf.assignment_number Is there a way to rewrite the query so that the function calls from the select clause (xxpay_util_element.get_run_result) that is repeated in the where clause are not repeated and only called once?
you can try creating this sql as subquery and add where clause in parent query : Select * from ( select xxpay_util_element.get_run_result as get_run_result_1, --only fetch values here ....... from ..... ) where get_run_result_1 ......... --add where clause here
Faster Query Execution
I have 42 columns and 4 joins in my table. Execution needs 140 seconds, I want to reduce the time of execution. What to do? SELECT DISTINCT GR_ID, CONVERT(VARCHAR, GR_DT, 106) AS GRDate, GR_GN, GR_GID, GR_BS, GR_BN, GR_DC, GR_COP, GR_PA, GR_AR, GR_BG, GR_SM, GR_KG, GR_IN, GR_TS, CMLC_BC, CMLC_SC, CMLC_KG, CMLC_BL, CMBC_BC, CMBC_SC, CMBC_KG, CMBC_BL, GR_BRN, GR_BLC, GR_LEA, GR_ALF, GR_BTA, GR_PID, GR_UTS, GR_LR, CMGB_BC, CMGB_SC, CMGB_KG, CMGB_BL, CMGB_LR, GR_UPC, GR_UPT, GR_UTA, GR_TTA, GR_SPA, GR_SAR, GR_NR, ISNULL(ACK_ACK, 'NO') AS ACK_ACK FROM GR LEFT JOIN CMBC ON ( CMBC_ID = GR_GID ) AND ( CMBC_IID = GR_PID ) RIGHT JOIN CMLC ON ( CMLC_ID = GR_GID ) AND ( CMLC_IID = GR_PID ) RIGHT JOIN CMGB ON ( CMGB_ID = GR_GID ) AND ( CMGB_IID = GR_PID ) AND ( CMGB_TS = GR_UTS ) LEFT JOIN ACK ON ( ACK_GN = GR_GN ) AND ( ACK_GID = GR_GID ) ORDER BY GR_GN, GR_GID
Why can't I insert data to my table?
I created a table using this IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[DimRegion]') AND type in (N'U')) DROP TABLE [DimRegion] Go Create Table DimRegion (RegionViewKey int NOT NULL identity Primary Key, RegionView varchar(10), RegionViewCode varchar(10), ActiveYear smallint, SublocationString varchar(7)NULL, SubLocationCode char(10)NOT NULL, LocationCode char(10)NULL, RegionCode char(10)NULL, RegionGrpCode char(10)NULL, DivisionCode char(10)NOT NULL, DivisionGrpCode char(10)NULL, SubLocationDescription char(50)NULL, LocationDescription char(50)NULL, RegionDescription char(50)NULL, RegionGrpDescription char(50)NULL, DivisionDescription char(50)NULL, DivisionGrpDescription char(50)NULL) And I inserted data using this script insert into DWResourceTask.dbo.DimRegion --(2013) Select 'Region1' as RegionView, 'R1' as RegionViewCode, '2013' as ActiveYear, sl.sublocationstring, sl.subLocationCode, l.locationcode, r.regioncode, rg.RegionGrpCode, d.DivisionCode, dg.DivisionGrpCode, sl.SubLocationDescription, l.LocationDescription, r.regiondescription, rg.RegionGrpDescription, d.divisionDescription, dg.DivisionGrpDescription from SCSubLocation sl, SCLocation l, SCRegion r, SCRegionGrp rg, SCDivision d, SCDivisionGrp dg where l.LocationCode = sl.LocationCode and r.RegionCode = l.RegionCode and r.RegionGrpCode = rg.RegionGrpCode and d.divisioncode = rg.divisioncode and d.divisiongrpcode = dg.divisiongrpcode But when I created this script below where it would only insert new and latest data, it gives me an error such as Msg 102, Level 15, State 1, Line 33 Incorrect syntax near 'R1'. Script: insert into DWResourceTask.dbo.DimRegion --(2013) Select 'Region1' as RegionView, 'R1' as RegionViewCode, '2013' as ActiveYear, sl.sublocationstring, sl.subLocationCode, l.locationcode, r.regioncode, rg.RegionGrpCode, d.DivisionCode, dg.DivisionGrpCode, sl.SubLocationDescription, l.LocationDescription, r.regiondescription, rg.RegionGrpDescription, d.divisionDescription, dg.DivisionGrpDescription from SCSubLocation sl, SCLocation l, SCRegion r, SCRegionGrp rg, SCDivision d, SCDivisionGrp dg where l.LocationCode = sl.LocationCode and r.RegionCode = l.RegionCode and r.RegionGrpCode = rg.RegionGrpCode and d.divisioncode = rg.divisioncode and d.divisiongrpcode = dg.divisiongrpcode and not exists(select * from DWResourceTask.dbo.DimRegion x where(Region1=x.RegionView R1=x.RegionViewCode 2013=x.ActiveYear sl.sublocationstring=x.sublocationstring sl.subLocationCode=x.subLocationCode l.locationcode=x.locationcode r.regioncode=x.regioncode rg.RegionGrpCode=x.RegionGrpCode d.DivisionCode=x.DivisionCode dg.DivisionGrpCode=x.DivisionGrpCode sl.SubLocationDescription=x.SubLocationDescription l.LocationDescription=x.LocationDescription r.regiondescription=x.regiondescription rg.RegionGrpDescription=x.RegionGrpDescription d.divisionDescription=x.divisionDescription dg.DivisionGrpDescription=x.DivisionGrpDescription) ) How do I fix this script on top where it only inserts latest data
It looks like your WHERE clause is missing the ANDs between parts of the condition: ... where(Region1=x.RegionView AND R1=x.RegionViewCode AND 2013=x.ActiveYear AND sl.sublocationstring=x.sublocationstring AND sl.subLocationCode=x.subLocationCode AND l.locationcode=x.locationcode AND r.regioncode=x.regioncode AND rg.RegionGrpCode=x.RegionGrpCode AND d.DivisionCode=x.DivisionCode AND dg.DivisionGrpCode=x.DivisionGrpCode AND sl.SubLocationDescription=x.SubLocationDescription AND l.LocationDescription=x.LocationDescription AND r.regiondescription=x.regiondescription AND rg.RegionGrpDescription=x.RegionGrpDescription AND d.divisionDescription=x.divisionDescription AND dg.DivisionGrpDescription=x.DivisionGrpDescription) )
Oracle - SubQuery returning Multiple rows
I have the following table structure: HSM HSM_EXC_CODE Y VARCHAR2(60) HSM_INSTR_CODE Y VARCHAR2(60) HSM_ISIN Y VARCHAR2(60) HSM_VWD_TICKERSYMBL Y VARCHAR2(80) TENFORE_EXCHANGE_MAP HS_MARKET Y VARCHAR2(40) TF_EXCHANGE Y VARCHAR2(40) TFV TFE_ID Y NUMBER(22) TFE_VSE_CODE Y VARCHAR2(1000) Different TFE_ID can have same TFE_VSE_CODE! I think this is what I'm missing in the update query below. VSD VSD_ON Y VARCHAR2(160) VSD_ISIN Y VARCHAR2(15) The tables are connected like the following: TENFORE_EXCHANGE_MAP.HS_MARKET = HSM.HSM_EXC_CODE TENFORE_EXCHANGE_MAP.TF_EXCHANGE = TFV.TFE_ID I'm trying to fill hsm_isin and hsm_on fields. To reach the goal I'm trying to generate the names from hsm.hsm_exc_code . tfv.tfe_vse_code. But I'm doing it wrong, cause I'm getting the error from the topic. This is what I have tried: UPDATE hsm SET hsm_isin = (SELECT distinct vsd.vsd_isin FROM vsd, tfv, TENFORE_EXCHANGE_MAP WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id) ,hsm.hsm_vwd_tickersymbl = (SELECT distinct vsd.vsd_on FROM vsd, tfv, TENFORE_EXCHANGE_MAP WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id);
There must be more than one line for key in either first or second subquery: Try something like: SELECT hsm.hsm_instr_code, count( distinct( vsd.vsd_on ) ) cnt1, count( distinct( vsd.vsd_isin ) ) cnt2 FROM vsd, tfv, TENFORE_EXCHANGE_MAP, hsm WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id GROUP BY hsm.hsm_instr_code HAVING count( distinct( vsd.vsd_on ) ) > 1 OR count( distinct( vsd.vsd_isin ) ) > 1 NOTE: Once you fix multiline problem, you can simplify two subqueries in one, like below: UPDATE hsm SET ( hsm_isin, hsm.hsm_vwd_tickersymbl ) = (SELECT distinct vsd.vsd_isin, vsd.vsd_on FROM vsd, tfv, TENFORE_EXCHANGE_MAP WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id);
SQL Query works different than expected
I have problems with understanding sql statement. When I execute the it(see below), I'm getting only people with sgtn_typ 'L'. SELECT DISTINCT kun_id kid ,dep_id ,ddg_rang_g RANG ,dep_perf_g ,TO_CHAR(dep_buchwert + dep_kasse, '999G999G990D99') WERT ,kun_name1 ,Kun_vorname ,kun_cust_id ,kun_strasse ,kun_plz ,kun_ort ,kun_e_mail ,kun_pseudonym ,kka_value FROM ddg, dep, kun, kat, kka, sgtn WHERE dep_spi_id = 245 AND dep_abr_id = 24 AND ddg_dgr_id = 3 AND ddg_abr_id = dep_abr_id AND ddg_spi_id = dep_spi_id AND ddg_dep_id = dep_id AND dep_kun_id = kun_id AND kun_aktiv = 'J' AND dep_spi_id = kun_spi_id AND dep_id IS NOT NULL AND dep_id NOT IN (SELECT ddg_dep_id FROM ddg WHERE ddg_spi_id = 245 AND ddg_abr_id = 0 AND ddg_dgr_id = 1) AND kun_id = kka_kun_id AND kka_spi_id = 245 AND kat_spi_id = 245 AND kka_kat_kuerzel = kat_kuerzel AND kat_kuerzel = 'NSCH' AND kka_spi_id = sgtn_spi_id AND kka_kun_id = sgtn_kun_id AND sgtn_spi_id = 245 AND sgtn_e_mail = kun_e_mail AND (sgtn_typ = 'L' OR (sgtn_typ = 'T' AND sgtn_e_mail NOT IN (SELECT sgtn_e_mail FROM sgtn WHERE sgtn_spi_id = 245 AND sgtn_typ = 'L')) ) ORDER BY kun_id, sgtn_typ; But when I execute this, I'm getting people with sgtn_typ 'T': SELECT * FROM sgtn WHERE sgtn_spi_id = 245 AND (sgtn_typ = 'L' OR (sgtn_typ = 'T' AND sgtn_e_mail NOT IN (SELECT sgtn_e_mail FROM sgtn WHERE sgtn_spi_id = 245 AND sgtn_typ = 'L')) ) ORDER BY sgtn_kun_id; I don't understand why? Could someone give me any clue? I was expecting, that I substitute all people with type 'L' and will get people with type 'T': AND (sgtn_typ = 'L' OR (sgtn_typ = 'T' AND sgtn_e_mail NOT IN (SELECT sgtn_e_mail FROM sgtn WHERE sgtn_spi_id = 245 AND sgtn_typ = 'L')) ) There are 'duplicates' in sgtn table(some people are entered with 'T' and 'L'). And apart from that the whole record is the same. Table scheme are like the folowing: SGTN: SGTN_ID NUMBER(22) SGTN_SPI_ID NUMBER(22) SGTN_KUN_ID NUMBER(22) SGTN_TYP VARCHAR2(4) SGTN_GESCHLECHT VARCHAR2(4) SGTN_VORNAME VARCHAR2(160) SGTN_NAME1 VARCHAR2(240) SGTN_STRASSE VARCHAR2(240) SGTN_PLZ VARCHAR2(60) SGTN_ORT VARCHAR2(240) SGTN_E_MAIL VARCHAR2(240) SGTN_GEB_DAT DATE(7) SGTN_KLASSE VARCHAR2(200) SGTN_SCHULE VARCHAR2(200) SGTN_TELEFON VARCHAR2(120) SGTN_KONTONUMMER VARCHAR2(120) KUN: KUN_ID NUMBER(22) KUN_SPI_ID NUMBER(22) KUN_LAN_ID NUMBER(22) KUN_MED_KBEZ VARCHAR2(40) KUN_NAME1 VARCHAR2(240) KUN_MKZ VARCHAR2(80) KUN_TS DATE(7) KUN_AKTIV VARCHAR2(12) KUN_KTOINH VARCHAR2(240) KUN_BLZ VARCHAR2(40) KUN_BANK VARCHAR2(240) KUN_KTONR VARCHAR2(80) KUN_ZAHLART VARCHAR2(4) KUN_NAME2 VARCHAR2(240) KUN_VORNAME VARCHAR2(160) KUN_STRASSE VARCHAR2(240) KUN_PLZ VARCHAR2(60) KUN_ORT VARCHAR2(240) KUN_TEL1 VARCHAR2(120) KUN_TEL2 VARCHAR2(120) KUN_FAX VARCHAR2(120) KUN_E_MAIL VARCHAR2(240) KUN_PSEUDONYM VARCHAR2(120) KUN_PWD VARCHAR2(60) KUN_CUST_ID VARCHAR2(240) KUN_GESCHLECHT VARCHAR2(4) KUN_K_NAME VARCHAR2(80) KUN_K_NR NUMBER(22) KUN_K_VALID VARCHAR2(40) KUN_ZUSATZ_1 VARCHAR2(400) KUN_ZUSATZ_DATUM DATE(7) KUN_COMMENT VARCHAR2(4000) KUN_EVT_SMS VARCHAR2(80) KUN_EVT_E_MAIL VARCHAR2(240) KUN_COMMENT2 VARCHAR2(4000) KUN_AKTIV_BIS DATE(7) KUN_FLG_AGB VARCHAR2(4) KUN_TITEL VARCHAR2(200) Thank you in advance for clues. Greetings R. Bada