两个具有相同序列的表

时间:2011-09-02 18:12:56

标签: oracle primary-key sequence

是否可以有两个具有相同递增顺序的表?

我试图用ID, NAME, ParentID做一棵树,我必须加入两张桌子。 如果我有不同的id,ID - ParentId的树方案将不起作用。

     Table A                Table B
  ID | NAME | PID       ID | NAME | PID
  1  | xpto | 0          1 | xpto | 1

4 个答案:

答案 0 :(得分:5)

如果您同时进行两个插入,则可以使用SEQUENCE.NEXTVAL插入第一个表以获取新ID,然后使用SEQUENCE.CURRVAL插入第二个表以重用相同的ID

答案 1 :(得分:3)

你可以拥有一个只有序列PK / FK的主表,然后有两个子表。在master中插入一行以获取序列,然后将该序列用作子表中的PK。如果子表具有相同的序列,那么为什么不是一个表?

答案 2 :(得分:2)

我找到了答案:“序列号是独立于表生成的,因此相同的序列可以用于一个或多个表。”

http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6015.htm

坦克为你提供帮助。

答案 3 :(得分:0)

import { Component, Input, OnInit,SimpleChange } from '@angular/core';

// amCharts imports
import * as am4core from '@amcharts/amcharts4/core';
import * as am4charts from '@amcharts/amcharts4/charts';
import am4themes_animated from '@amcharts/amcharts4/themes/animated';

interface data{
  aborted: string;
  dut_build_version: string;
  dut_name: string;
  failed: string;
  passed: string;
  suite: string;
  tested: string;
  totalcase:string;
  suiteid:number;
}
@Component({
  selector: 'app-pie-chart',
  templateUrl: './pie-chart.component.html',
  styleUrls: ['./pie-chart.component.scss']
})

export class PieChartComponent implements OnInit {

  @Input() data:data;
  id:string;

  chart: am4charts.PieChart;
  constructor() { 
    
  }
  ngOnChanges(changes: SimpleChange): void {
    
  }
  ngOnInit(): void {
    this.id=`${this.data.dut_name}-${this.data.dut_build_version}-${this.data.suite}`;
    
  }
  ngAfterViewInit(): void {
    
    am4core.useTheme(am4themes_animated);
    var chart = am4core.create(this.id, am4charts.PieChart);
    // Add data
    chart.data = [{
      "status":"Passed",
      "value": this.data.passed,
      "color": am4core.color("#235789")
    }, {
      "status": "Failed",
      "value": this.data.failed,
      "color": am4core.color("#ED1C24")
    }, {
      "status": "Aborted",
      "value": this.data.aborted,
      "color": am4core.color("#F1D302")
    },{
      "status": "To be tested",
      "value": parseInt(this.data.totalcase) - (parseInt(this.data.passed) + parseInt(this.data.failed) + parseInt(this.data.aborted)),
      "color": am4core.color("#c7da2b")
    }];

    // Add and configure Series
    var pieSeries = chart.series.push(new am4charts.PieSeries());
    pieSeries.dataFields.value = "value";
    pieSeries.dataFields.category = "status";
    pieSeries.slices.template.propertyFields.fill = "color";
    pieSeries.ticks.template.disabled = true;
    pieSeries.labels.template.disabled = true;
    chart.legend = new am4charts.Legend();
    chart.legend.useDefaultMarker = true;
    let markerTemplate = chart.legend.markers.template;
    markerTemplate.width = 10;
    markerTemplate.height = 10;
    markerTemplate.stroke= am4core.color("#ccc");
    markerTemplate.strokeWidth = 2;
    markerTemplate.strokeOpacity = 1;
    this.chart=chart;

  }
  ngOnDestroy(){
    
    if (this.chart) {
      console.log("Enter chart dispose");
      this.chart.dispose();
    }
   
  }

}

Sample Image

create sequence v_seq
INCREMENT by 1
minvalue 1
maxvalue 10;

create table v_t_s_emp(v_id number,vname varchar2(10));
insert into v_t_s_emp values(v_seq.nextval,'krishna');
create table v_t_s_emp1(v_id number,vname varchar2(10));
insert into v_t_s_emp1 values(v_seq.nextval,'RAMesh');
commit;