Not enough values when inserting a row in oracle

54 views Asked by At

I'm trying to insert a row by selecting some datas from another table.

insert into spb (id_barang,nama_barang,qty,lokasi_tujuan,lokasi_asal,waktu)
values
((select stg.id_barang,stg.nama_barang,calculate_req_stok(display.max_stok,display.stok,display.pcs_in_ctn,display.id_barang),display.lokasi,stg.lokasi
from display
inner join stg
on display.nama_barang = stg.nama_barang
where stg.stok >= calculate_req_stok(display.max_stok,display.stok,display.pcs_in_ctn,display.id_barang) * display.pcs_in_ctn),current_time_ms);

It shows this error : ORA-00947: not enough values. I don't know what causes this even though I inserted enough values

1

There are 1 answers

0
Littlefoot On

Wrong syntax; remove values and move the last value to be inserted (current_time_ms) into select's column list:

INSERT INTO spb(
  id_barang,
  nama_barang,
  qty,
  lokasi_tujuan,
  lokasi_asal,
  waktu
)
  (SELECT stg.id_barang,
          stg.nama_barang,
          calculate_req_stok(
            display.max_stok,display.stok,
            display.pcs_in_ctn,
            display.id_barang
          ),
          display.lokasi,
          stg.lokasi,
          current_time_ms
  FROM display
  INNER JOIN stg ON display.nama_barang = stg.nama_barang
  WHERE stg.stok >= 
    calculate_req_stok
     (display.max_stok,display.stok,
      display.pcs_in_ctn,
      display.id_barang
     ) * display.pcs_in_ctn
  );