Unique Key를 생성하는 방법은DBMS마다 차이가 있다. MS-SQL은IDENTITY를, MySQL은auto_increment,
오라클에서는Sequence를 사용하여 다음과 같이 유사하게 구현할 수 있다.
1. 자동증가컬럼을 사용하고자 하는MYTABLE테이블을 생성한다.
CREATE TABLE MYTABLE(
ID NUMBER, NAME VARCHAR2(20)
);
2.CREATE SEQUENCE라는 문장을 사용하여SEQ_ID라는 이름의 시퀀스를 만든다.
CREATE SEQUENCE SEQ_ID INCREMENT BY 1 START WITH 10000;
-- INCREMENT BY 1 : 증가값은 1
-- START WITH 10000 : 10000부터 증가
3. 테이블에 데이터 입력시에는NEXTVAL이라는 슈도 컬럼(Pseudo-column)을 이용하여 시퀸스를 사용한다.
INSERT INTO MYTABLE VALUES( SEQ_ID.NEXTVAL, '홍길동');
-- CURRVAL : 현재 값을 반환 합니다. .
-- NEXTVAL : 현재 시퀀스값의 다음 값을 반환 합니다.
Sequence 구문
CREATE SEQUENCE sequence_name
[START WITH n]
[INCREMENT BY n]
[MAXVALUE n | NOMAXVALUE]
[MINVALUE n | NOMINVALUE]
[CYCLE | NOCYCLE]
* START WITH 시퀀스의 시작 값을 지정합니다. n을 1로 지정하면 1부터 순차적으로 시퀀스번호가 증가 합니다.
* INCREMENT BY 시퀀스의 증가 값을 말합니다. n을 2로 하면 2씩 증가합니다. START WITH를 1로 하고 INCREMENT BY를 2으로 하면 1, 3, 5,7,.. 이렇게 시퀀스 번호가 증가하게 됩니다.
* MAXVALUE n | NOMAXVALUE MAXVALUE는 시퀀스가 증가할수 있는 최대값을 말합니다. NOMAXVALUE는 시퀀스의 값을 무한대로 지정합니다.
* MINVALUE n | NOMINVALUE MINVALUE는 시퀀스의 최소값을 지정 합니다. 기본값은 1이며, NOMINVALUE를 지정할 경우 최소값은 무한대가 됩니다
[사용규칙]
* NEXTVAL, CURRVAL을 사용할 수 있는 경우 - subquery가 아닌 select문 - insert문의 select절 - insert문의 value절 - update문의 set절
* NEXTVAL, CURRVAL을 사용할 수 없는 경우 - view의 select절 - distinct 키워드가 있는 select문 - group by, having, order by절이 있는 select문 - select, delete, update의 subquery - create table, alter table 명령의 default값
[수정]
ALTER SEQUENCE sequence_name
[INCREMENT BY n]
[MAXVALUE n | NOMAXVALUE]
[MINVALUE n | NOMINVALUE]
[CYCLE | NOCYCLE]
START WITH는 수정할수 없습니다. START WITH 절이 없다는 점을 빼고는 CREATE SEQUENCE와 같습니다.
<h1>1. Uppercase or lowercase a string </h1>
<%
name = "Bill Gates"
response.write(ucase(name))
response.write("<br>")
response.write(lcase(name))
%>
2. TRIM, LTRIM, RTRIM 사용
<h1>2. Trim a string</h1>
<%
name = " W3Schools "
response.write("visit" & name & "now<br>")
response.write("visit" & trim(name) & "now<br>")
response.write("visit" & ltrim(name) & "now<br>")
response.write("visit" & rtrim(name) & "now")
%>
3. STRREVERSE 사용
<h1>3. How to reverse a string?</h1>
<%
sometext = "Hello Everyone!"
response.write(strReverse(sometext))
%>
4. ROUND 사용
<h1>4. How to round a number?</h1>
<%
i = 48.66776677
j = 48.33333
response.write(Round(i))
response.write("<br>")
response.write(Round(j))
%>
5. Randomize / Rnd : 랜덤 / 난수 생성
* Randomize란?
ASP에서 랜덤한 숫자를발생시키는 것은 Rnd 함수인데, Rnd 함수를 사용하기 전에 Randomize를 사용하여야 난수 발생기가 초기화되어 Rnd함수를 사용하였을 때 새로운 난수가 발생한다.
* Rnd란?
0부터 1사이의 랜덤한 숫자를 발생시키는 함수
<h1>5. A random number</h1>
<%
randomize()
response.write(rnd())
%>
<br>
<%
Randomize()
randomNumber=Int(100*Rnd())
response.write("A random number : <b>" & randomNumber & "</b>")
%>
6. LEFT, RIGHT, MID, REPLACE 사용
<h2>6. Return a specified number of characters from left/right of a string</h2>
<%
sometext="Welcome to this Web"
response.write(Left(sometext, 5))
response.write("<br>")
response.write(Right(sometext, 5))
response.write("<br>")
response.write(Mid(sometext, 9, 2))
response.write("<br>")
response.write(Replace(sometext, "Web", "Page"))
%>
7. Sub Procedure 사용
<h1>7. Sub Procedure</h1>
<%
Sub mysub()
response.write("I was written by a sub procedure")
End Sub
response.write("I was written by the script<br>")
Call mysub()
%>
8. Function Procedure 사용
<h1>8. Function Procedure</h1>
<%
Function myfunction()
myfunction=Date()
End Function
response.write("Today's date : ")
response.write(myfunction())
%>
<html>
<body>
Today's date is: <%response.write(date())%>.
<br>
The server's local time is: <%response.write(time())%>.
</body>
</html>
2. Get the name of a day
<html>
<body>
<p>
VBScripts' function <b>WeekdayName</b> is used to get a weekday:
</p>
<%
response.Write(WeekDayName(1))
response.Write("<br>")
response.Write(WeekDayName(2))
%>
<p>Abbreviated name of a weekday:</p>
<%
response.Write(WeekDayName(1,true))
response.Write("<br>")
response.Write(WeekDayName(2,true))
%>
<p>Current weekday:</p>
<%
response.Write(WeekdayName(weekday(date)))
response.Write("<br>")
response.Write(WeekdayName(weekday(date), true))
%>
</body>
</html>
3. Get the name of a month
<html>
<body>
<p>VBScripts' function <b>MonthName</b> is used to get a month:</p>
<%
response.Write(MonthName(1))
response.Write("<br>")
response.Write(MonthName(2))
%>
<p>Abbreviated name of a month:</p>
<%
response.Write(MonthName(1,true))
response.Write("<br>")
response.Write(MonthName(2,true))
%>
<p>Current month:</p>
<%
response.Write(MonthName(month(date)))
response.Write("<br>")
response.Write(MonthName(month(date), true))
%>
</body>
</html>
4. Get todays' day and month
<html>
<body>
Today it is
<%response.write(WeekdayName(weekday(date)))%>,
<br>
and the month is
<%response.write(MonthName(month(date)))%>
</body>
</html>
5. Countdown to year 3000
<html>
<body>
<p>Countdown to year 3000:</p>
<p>
<%millennium=cdate("1/1/3000 00:00:00")%>
It is
<%response.write(DateDiff("yyyy", Now(), millennium))%>
years to year 3000!
<br>
It is
<%response.write(DateDiff("m", Now(), millennium))%>
months to year 3000!
<br>
It is
<%response.write(DateDiff("ww", Now(), millennium))%>
weeks to year 3000!
<br>
It is
<%response.write(DateDiff("d", Now(), millennium))%>
days to year 3000!
<br>
It is
<%response.write(DateDiff("h", Now(), millennium))%>
hours to year 3000!
<br>
It is
<%response.write(DateDiff("n", Now(), millennium))%>
minutes to year 3000!
<br>
It is
<%response.write(DateDiff("s", Now(), millennium))%>
seconds to year 3000!
</p>
</body>
</html>
6. Calculate the day which is n days from today
<html>
<body>
<%
response.write(DateAdd("d",30,Date()))
%>
<p>
This example uses <b>DateAdd</b> to calculate a date 30 days from today.
</p>
<p>
Syntax for DateAdd: DateAdd(interval,number,date).
</p>
<%
response.write(DateAdd("d",10,Date()))
%>
<p>
This example uses <b>DateAdd</b> to calculate a date 10 days from today.
</p>
<p>
Syntax for DateAdd: DateAdd(interval,number,date).
</p>
</body>
</html>