두번째 질문하신내용이, 실제 값을 변경할려고 하는것이 아니라
오라클의 decode나 M$-sql의 case문과 같은 역활을 원하신다면..
mers에서 검색해온 작은 팁하나 소개해드립니다..
어차피 ib에는 decode함수가없지만, 프로시저로 만들어서 사용할수도 있더군요..
(사실 udf로 만들어놓으면 좋은데, 실력이 없어서..)
검색한 내용을 첨부합니다..
Subject: Re: Decode on Interbase
Author: sskracic@lavsa.com (Sebastian Skracic)
Date: 15 Aug 2000 09:34:26 GMT
Newsgroup: mers.interbase.list
--------------------------------------------------------------------------------
In article <8n9la7$m2h$1@linux.mers.com>, Daniel Severo Junior wrote:
>Hello people, I need use an function like "decode" on ORACLE, this function
>make an condition for an expression and return the value passed, else return
>the second parameter.
Basically, you're out of luck. InterBase does not support CASE statement
(I was hoping it would be very high on priority list once open source
release got out of the doors).
But you can always resort to IB's stored procedures. For example,
you can write simple stored procedure that takes 4 input arguments
(arg1, arg2, ifeq, ifneq) and outputs scalar value (one row, one column)
'ifeq' if arg1=arg2; 'ifneq' otherwise:
SET TERM !! ;
CREATE PROCEDURE decode_proc (arg1 VARCHAR(200), arg2 VARCHAR(200),
ifeq VARCHAR(200), ifneq VARCHAR(200) )
RETURNS (decode VARCHAR(200))
AS
BEGIN
IF (:arg1 = :arg2) THEN
decode = :ifeq ;
ELSE
decode = :ifneq ;
SUSPEND ;
END !!
SET TERM ; !!
So this Oracle query:
SELECT
age,
decode(age, 20, '20 years old.', 'not 20 years old') AS age_text
FROM
employees
... can be reformulated in InterBase as:
SELECT
age,
(SELECT decode FROM decode_proc(age, 20, '20 years old.', 'not 20 years old'))
age_text
FROM
employees
Seb.
홍작새 님이 쓰신 글 :
: select name, job from PERSONAL;
:
: 이라는 쿼리를
:
: select name as 이름, job as 직업 from PERSONAL;
:
: 로 바꾸면 필드명이 이상한 문자로 깨져나오는데요... 어떻게 하면 좋을까요?
: (charset도 바꿔봤는데 잘 안되네요...)
:
: 또, INTEGER 필드의 값을 쿼리상에서 다른 값으로 replace하고 싶은데,
: 방법을 알려주시면 정말 고맙겠습니다.
:
: (예) 0 - 가, 1 - 나, 2 - 다...
:
: num
: ---
: 0
: 1
: 2
: ===
:
: > ...쿼리...
:
: num
: ---
: 가
: 나
: 다
: ===
:
: ...이렇게요... (설명이 좀 부족한 것 같습니다만...)
|