전체 글 (166)

09
15

ex)

'use strict';

//Array
//1.Declaration
const arr1 = new Array();
const arr2 = [1,2];

//2.Index position
const fruits = ['사과','바나나'];
console.log(fruits);
console.log(fruits.length);
console.log(fruits[0]);
console.log(fruits[1]);
console.log(fruits.length-1);

//3.Looping over an array
//print all fruits
for(let fruit of fruits){
    console.log(fruit);
}

fruits.forEach((fruit, index, array) => console.log(fruit, index, array));

 

예제 실행 화면

 

ex)

//4. Addtion, deletion, copy
//push : add an item to the end
fruits.push('딸기','복숭아');
console.log('fruits');
//pop : remove an item from the end
fruits.pop();
fruits.pop();
console.log(fruits);
//unshift : add an item to the benigging
fruits.unshift('딸기','레몬');
//shift : remove an item from the benigging
fruits.shift();
fruits.shift();
console.log(fruits);
//note!! shift, unshift are slower than pop, push
//splice : remove an item by index position
fruits.push('딸기','복숭아','레몬');
console.log(fruits);
fruits.splice(1,1);//count를 적지 않으면 지정한 인덱스부터 모두 지움
console.log(fruits);
fruits.splice(1,1,'사과','수박');
console.log(fruits);

//combine tow arrays
const fruits2 = ['배','코코넛'];
const newfruits = fruits.concat(fruits2);
console.log(newfruits);

 

예제 실행 화면

 

예제 실행 화면

 

ex)

//5.Searching
//find the index
console.clear();
console.log(fruits);
console.log(fruits.indexOf('사과'));
console.log(fruits.indexOf('수박'));
console.log(fruits.indexOf('코코넛'));
console.log(fruits.includes('수박'));
console.log(fruits.includes('코코넛'));

//lastIndexOf
//console.clear();
fruits.push('사과');
console.log(fruits.indexOf('사과'));
console.log(fruits.lastIndexOf('사과'));

 

예제 실행 화면

COMMENT
 
09
15

특정한 로직을 처리하기만 하고 결과 값을 반환하지 않는 서브 프로그래이다. 테이블에서 데이터를 추출해 조작하고 그 결과를 다른 테이블에 다시 저장하거나 일련의 처리를 할 때 주로 프로시저를 사용한다.

 

생성

CREATE OR REPLACE PROCEDURE 프로시저명
	(매개변수형1 [IN | OUT | IN OUT] 데이터타입 [:= 디폴트값]
	,매개변수명2 [IN | OUT | IN OUT] 데이터타입 [:= 디폴트값]
	...
	)
IS[AS]
	변수, 상수 등 선언
BEGIN
	실행부
[EXCEPTION
	예외처리부]
END [프로시저명];

 

매개변수

IN은 입력, OUT은 출력, IN OUT은 입출력을 동시에 한다는 의미이다. 디폴트 값은 IN이다. OUT 매개변수는 프로시저 내에서 로직 처리 후, 해당 매개변수에 값을 할당해 프로시저 호출부분에서 이 값을 참조할 수 있다.

CREATE OR REPLACE PROCEDURE MY_NEW_JOB_PROC
(	P_JOB_ID	IN	JOBS.JOB_ID%TYPE,
	P_JOB_TITLE	IN	JOBS.JOB_TITLE%TYPE,
	P_MIN_SAL	IN	JOBS.MIN_SALARY%TYPE,
	P_MAX_SAL	IN	JOBS.MAX_SALARY%TYPE)
IS

BEGIN
	INSERT INTO JOBS (JOB_ID, JOB_TITLE, MIN_SALARY, MAX_SALARY, CREATE_DATE, UPDATE_DATE)
	VALUES (P_JOB_ID, P_JOB_TITLE, P_MIN_SAL, P_MAX_SAL, SYSDATE, SYSDATE);

	COMMIT;
END;

'스마트팩토리 > 오라클' 카테고리의 다른 글

계정과 스키마  (0) 2020.09.10
오라클 테이블 스페이스(Table Space)  (0) 2020.09.05
오라클 SQL 문법  (0) 2020.08.27
오라클 데이터 타입  (0) 2020.08.27
C#과 오라클 연동해보기  (0) 2020.08.26
COMMENT
 
09
14

ex)

//Objects
//one of the JavaScript's data types.
//a collection of related data and/or functionality.
//Nearly all objects in JavaScript are instances of Object
//object = {key : value};

//1.Literals and properties
const name = 'han';
const age = 4;
print(name, age);
function print(name, age){
    console.log(name);
    console.log(age);
}

const jin = {name: 'jin', age:27};
function print(person){
    console.log(person.name,person.age);
}
print(jin);

//가능한 이렇게 코딩하지 말것
jin.hasJob = true;
console.log(jin.hasJob);

delete jin.hasJob;
console.log(jin.hasJob);

 

예제 실행 화면

 

ex)

//2. Computed properties
//key should be always string
const jin = {name: 'jin', age:27};
console.log(jin.name);
console.log(jin['name']);
jin['hasJob'] = true;
console.log(jin.hasJob);

function printValue(obj, key){
    console.log(obj.key);
    console.log(obj[key]);
}
printValue(jin,'name');
printValue(jin,'age');

 

예제 실행 화면

 

ex)

//3.Property value shorthand
const person1 = {name: 'bob', age: 2};
const person2 = {name: 'steve', age: 3};
const person3 = {name: 'dave', age: 4};
const person4 = new Person('jin', 30);
console.log(person4);

//4. Constructor Function
function Person(name, age){
    //this = {};
    this.name = name;
    this.age = age;
    //return this;
}

 

예제 실행 화면

 

ex)

//5. in operator: property existence check (key in obj)
const jin = {name: 'jin', age:27};
console.log('name' in jin);
console.log('random' in jin);
console.log(jin.random);

 

예제 실행 화면

 

ex)

//6. for..in vs for..of
//for(key in obj)
const jin = {name: 'jin', age:27};
for(key in jin){
    console.log(key);
}

//for(value of iterable)
const array = [1,2,4,5];
for(let i = 0; i < array.length; i++){
    console.log(array[i]);
}
for(value of array){
    console.log(value);
}

 

예제 실행 화면

 

ex)

//7. Fun cloning
//Object.assign(des, [obj1, obj2, obj3...])
const user = {name: 'jin', age: '20'};
const user2 = user;
user2.name = 'han';
console.log(user);

//old way
const user3 = {};
for(key in user){
    user3[key] = user[key];
}
console.log(user3);

const user4 = Object.assign({}, user);
console.log(user4);

//another example
const fruit1 = {color: 'red'};
const fruit2 = {color: 'blue', size: 'big'};
const mixed = Object.assign({},fruit1, fruit2); // 같은 key는 뒤로 가면서 계속 덮어쓰기함
console.log(mixed.color);
console.log(mixed.size);

 

예제 실행 화면

 

COMMENT
 
09
14

class

  • template
  • declare once
  • no data in

object

  • instance of a class
  • created many times
  • data in

ex)

'use strict';
//Object-oriendted programming
//class: template
//object: instance of a class
//JavaScript classes
//-introduced in ES6
//-syntactical sugar over prototype-based inheritance

//1. Class declarations
class Person{
    //constructor
    constructor(name, age){
        //fields
        this.name = name;
        this.age = age;
    }

    //methods
    speak(){
        console.log(`${this.name}: hello!`);
    }
}

const han = new Person('hanjin', 27);
console.log(han.name);
console.log(han.age);
han.speak();

//2.Getter and setters
class User{
    constructor(firstName, lastName, age){
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
    }

    get age(){
        return this._age;
    }

    set age(value){
        //if(value < 0){
        //  throw Error('age can not be negative');
        //}
        this._age = value < 0 ? 0 : value;
    }
}

const user1 = new User('Steve','Job', -1);
console.log(user1.age);

 

예제 실행 화면

 

ex)

//3.Fields(public, private)
//Too soon!
class Experiment{
    publicField = 2;
    #privateField = 0;
}
const experiment = new Experiment();
console.log(experiment.publicField);
console.log(experiment.privateField);

//4.Static properties and methods
//Too soon!
class Article{
    static publisher = 'Dream Coding';
    constructor(articleNumber){
        this.articleNumber = articleNumber;
    }

    static printPublisher(){
        console.log(Article.publisher);
    }
}

const article1 = new Article(1);
const article2 = new Article(2);
console.log(Article.publisher);
Article.printPublisher();

 

예제 실행 화면

 

ex)

//5.Inheritance
//a way for one class to extend another class.
class Shape{
    constructor(width, height, color){
        this.width = width;
        this.height = height;
        this.color = color;
    }

    draw(){
        console.log(`drawing ${this.color} color of`);
    }

    getArea(){
        return this.width * this.height;
    }
}

class Rectangle extends Shape{}
class Triangle extends Shape{
    draw(){
        super.draw();
        console.log('삼각형');
    }
    getArea(){
        return (this.width*this.height)/2;
    }
}

const rectangle = new Rectangle(20,20,'blue');
rectangle.draw();
console.log(rectangle.getArea());
const triangle = new Triangle(20,20,'red');
triangle.draw();
console.log(triangle.getArea());

 

예제 실행 홤녀

 

ex)

class Shape{
    constructor(width, height, color){
        this.width = width;
        this.height = height;
        this.color = color;
    }

    draw(){
        console.log(`drawing ${this.color} color of`);
    }

    getArea(){
        return this.width * this.height;
    }
}

class Rectangle extends Shape{}
class Triangle extends Shape{
    draw(){
        super.draw();
        console.log('삼각형');
    }
    getArea(){
        return (this.width*this.height)/2;
    }
}

const rectangle = new Rectangle(20,20,'blue');
const triangle = new Triangle(20,20,'red');

//6. Class checking:instanceOf
console.log(rectangle instanceof Rectangle);
console.log(triangle instanceof Rectangle);
console.log(triangle instanceof Triangle);
console.log(triangle instanceof Shape);
console.log(triangle instanceof Object);

 

예제 실행 화면

 

참고사이트 : JavaScript reference developer.mozilla.org/ko/docs/Web/JavaScript

COMMENT