오라클 쿼리중 

조회하려는 row(s)단위로 lock설정이가능한데,

"FOR UPDATE 구문"을 사용한다



select * from employees

where empno = 1234

for update nowait;


해당 empno=1234에 lock을 획득하지 못하면 ORA-00054로 에러발생시키고 종료한다.

현재 해당 rows가 lock상태라고 이해하면 되겠다.

(ORA-00054:자원이 사용중이고,NOWAIT가 지정되어 있음)


select * from employees

where empno = 1234

for update wait 10  --(10 seconds동안 lock잡기위해 대기);


10초이후도 lock을 얻지 못하면 ORA-00054 에러 발생시키고 종료된다.


아래 출처의 내용을 보게되면

ORA-00054에러 발생시 계속해서 try하는 로직이 있다.

반드시 수행되어야 하는 내용이 있으면 이렇게 반복적인 작업을 진행하더라고 진행되도록 처리한다.

(예, 프로세스 처리를 위해 중요한 key, 값이 되는 것의 채번/값수정 할때 사용할 수 있겠다.)



예)로직수행시 기lock이 있을경우 sleep후 재시도하여 처리

샘플)출처: http://www.java2s.com/Tutorial/Oracle/0500__Cursor/CursorFORUPDATENOWAIT.htm

'DataBase > Oracle' 카테고리의 다른 글

ORA-01403 no data found, ORA-01422 TOO_MANY_ROWS  (0) 2018.12.16
Oracle Error Code description  (0) 2018.04.20

1개월간 공부한 R에 사용방법 정리.


R에 내장된 데이터 

Iris, BOD

 

 

데이터프레임(dataframe)구조 파악하기 => str(iris)

아래는 150개의 관측치(observation)가 있고 5개의 변수가 있다는 정보를 보여준다.

4개의 변수는 number형태이고

1개의 변수는 factor이다.

 

> str(iris)

'data.frame': 150 obs. of  5 variables:

 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...

 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...

 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...

 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...

 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...


데이터 일부확인하기

상위5하위5개 보기

> head(iris)

  Sepal.Length Sepal.Width Petal.Length Petal.Width Species

1          5.1         3.5          1.4         0.2  setosa

2          4.9         3.0          1.4         0.2  setosa

3          4.7         3.2          1.3         0.2  setosa

4          4.6         3.1          1.5         0.2  setosa

5          5.0         3.6          1.4         0.2  setosa

6          5.4         3.9          1.7         0.4  setosa

> tail(iris)

    Sepal.Length Sepal.Width Petal.Length Petal.Width   Species

145          6.7         3.3          5.7         2.5 virginica

146          6.7         3.0          5.2         2.3 virginica

147          6.3         2.5          5.0         1.9 virginica

148          6.5         3.0          5.2         2.0 virginica

149          6.2         3.4          5.4         2.3 virginica

150          5.9         3.0          5.1         1.8 virginica


데이터에 대한 summary로 자료의 특성 파악하기

> summary(iris)

  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width          Species  

 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100   setosa    :50  

 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300   versicolor:50  

 Median :5.800   Median :3.000   Median :4.350   Median :1.300   virginica :50  

 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199                  

 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800                  

 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500     


  

cbind() 함수를 사용해 두 데이터를 병합한 데이터프레임 생성해보기

먼저 행의 개수가(observation) 일치한 데이터프레임이어야 합니다.

내장 데이터프레임 BOD, iris가공해서 진행

 

> iris2 <- head(iris)


> str(BOD)

'data.frame': 6 obs. of  2 variables:

 $ Time  : num  1 2 3 4 5 7

 $ demand: num  8.3 10.3 19 16 15.6 19.8

 - attr(*, "reference")= chr "A1.4, p. 270"

> str(iris2)

'data.frame': 6 obs. of  5 variables:

 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4

 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9

 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7

 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4

 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1


> iris2BOD <- cbind(iris2, BOD)

> show(iris2BOD)

  Sepal.Length Sepal.Width Petal.Length Petal.Width Species Time demand

1          5.1         3.5          1.4         0.2  setosa    1    8.3

2          4.9         3.0          1.4         0.2  setosa    2   10.3

3          4.7         3.2          1.3         0.2  setosa    3   19.0

4          4.6         3.1          1.5         0.2  setosa    4   16.0

5          5.0         3.6          1.4         0.2  setosa    5   15.6

6          5.4         3.9          1.7         0.4  setosa    7   19.8




# 데이터 정비

#iris2BOD 7개의 변수가 있는 데이터를  5개의 변수로 해서 새데이타프레임 생성

#즉, Sepal.Length, Sepal.Width, Species, Time, demand변수를 가진 iris2BOD2 데이터프레임생성하기


> iris2BOD2 <- iris2BOD[,c("Sepal.Length", "Sepal.Width", "Species", "Time", "demand")]

> show(iris2BOD2)

  Sepal.Length Sepal.Width Species Time demand

1          5.1         3.5  setosa    1    8.3

2          4.9         3.0  setosa    2   10.3

3          4.7         3.2  setosa    3   19.0

4          4.6         3.1  setosa    4   16.0

5          5.0         3.6  setosa    5   15.6

6          5.4         3.9  setosa    7   19.8




패키지 사용시

> library(ggplot2)

로 라이브러리에 추가하고 진행.




'빅데이타 > DATA분석' 카테고리의 다른 글

머신러닝 로드맵  (2) 2020.08.04

dustsensor.ino

dustsensorv2.ino



첨부된 2 가지  케이스로 코딩됨.

미세먼지 측정센서로 측정된 미세먼지 농도를 
16x2 LCD 에 표현하기.


아두이노 코딩도 계속하다 보니 자연스럽게 되는것 같다. 전자회로도 또한 친숙해지는것 같고.
연습이 완벽하게 만든다고 했나? 생각보다 쉽게 만들어짐에 놀라웠다.

Practice makes perfect, thanks.


#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int Vo = A0;
int V_LED = 2;

float Vo_value = 0;
float Voltage = 0;
float dustDensity = 0;
float dustCleanVoltage = 0.44;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;

void setup(){
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("dust");
Serial.begin(9600);

/*digital output:*/
pinMode(V_LED, OUTPUT);

/*analog input:*/
pinMode(Vo, INPUT);
}

/** references :
* http://blog.naver.com/PostView.nhn?blogId=darknisia&logNo=221222455928
* http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
* */
// 미세먼지 센서(GP2Y1010AU0F)
// : 적외선 발광 다이오드(IRED)와 포토다이오드가 대각선으로 배치되어 공기 중 먼지의 반사광을 감지
void loop(){
digitalWrite(V_LED,LOW); //ired 'on'
delayMicroseconds(samplingTime);
Vo_value = analogRead(Vo); //read the dust value
delayMicroseconds(deltaTime);// pulse width 0.32 - 0.28 = 0.04 msec
//0.32 msec의 펄스폭을 유지하기 위해 필요한 코드입니다

digitalWrite(V_LED,HIGH); //ired 'off'
delayMicroseconds(sleepTime);


/*
이 센서의 출력전압(Vo)는 먼지가 없을 때의 출력전압(Voc)과 먼지 농도(ΔV)에 비례하여 출력됩니다.
다시 표현하면 ΔV = Vo – Voc
미세먼지 농도[µg/m³] = (Vo – Voc) / 0.005
*/
Voltage = Vo_value * (5.0 / 1024.0);

dustDensity = (Voltage - dustCleanVoltage)/0.005;

Serial.print(" Raw Signal Value (0-1023):");
Serial.print(Vo_value);
Serial.print(" | Volatage:");
Serial.print(Voltage);
Serial.print(" | Dust Density:");
Serial.print(dustDensity);
Serial.print("[ug/m3]");
if(dustDensity<31){
Serial.println(" => [Great(~30)]");
} else if(dustDensity>30 && dustDensity<81){
Serial.println(" => [Good(31~80)]");
} else if(dustDensity>81 && dustDensity<151){
Serial.println(" => [Bad(81~150)]");
} else{
Serial.println(" => [Too Bad(151~)]");
}


// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print(dustDensity);
lcd.setCursor(0, 1);
if(dustDensity<31){
lcd.print(": Great(~30)");
} else if(dustDensity>30 && dustDensity<81){
lcd.print(": Good(31~80)");
} else if(dustDensity>81 && dustDensity<151){
lcd.print(": Bad(81~150)");
} else{
lcd.print(": Too Bad(151~)");
}
delay(5000);
}


 

+ Recent posts