database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
ㆍOracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Oracle Q&A 3431 게시물 읽기
No. 3431
Re: proc에서 stored procedure(PL/SQL) 호출하기
작성자
유은영
작성일
2001-03-22 10:05
조회수
2,907

저는 아직 proc를 한번도 써본적이 없지만 어디서 sample program을 본 기억이 나서 올립니다.

도움이 되셨으면 합니다.

그리고 저는 proc로 짠 프로그램을 어떻게 compile을 할 줄을 모르겠거든요

어떤 다른 client program을 깔아야 하는지 등 .......

혹시 아시면 저도 갈켜주세요..

 

 

embedded PL/SQL

 

simple example

 

char username[100], password[20];

char job_title[20], hire_date[9], temp[32];

int emp_number;

float salary;

#include <sqlca.h>

printf("Username? \n");

gets(username);

printf("Password? \n");

gets(password);

EXEC SQL WHENEVER SQLERROR GOTO sql_error;

EXEC SQL CONNECT :username IDENTIFIED BY :password;

printf("Connected to Oracle\n");

for (;;)

{

printf("Employee Number (0 to end)? ");

gets(temp);

emp_number = atoi(temp);

if (emp_number == 0)

{

EXEC SQL COMMIT WORK RELEASE;

printf("Exiting program\n");

break;

}

/*-------------- begin PL/SQL block -----------------*/

EXEC SQL EXECUTE

BEGIN

SELECT job, hiredate, sal

INTO :job_title, :hire_date, :salary

FROM emp

WHERE empno = :emp_number;

END;

END-EXEC;

/*-------------- end PL/SQL block -----------------*/

printf("Number Job Title Hire Date Salary\n");

printf("------------------------------------\n");

printf("%6d %8.8s %9.9s %6.2f\n",

emp_number, job_title, hire_date, salary);

}

...

exit(0);

sql_error:

EXEC SQL WHENEVER SQLERROR CONTINUE;

EXEC SQL ROLLBACK WORK RELEASE;

printf("Processing error\n");

exit(1);

 

more complex example

#include <stdio.h>

#include <sqlca.h>

char username[20];

char password[20];

char status[80];

char temp[32];

int acct_num;

double trans_amt;

void sql_error();

main()

{

char trans_type;

strcpy(password, "TIGER");

strcpy(username, "SCOTT");

EXEC SQL WHENEVER SQLERROR DO sql_error();

EXEC SQL CONNECT :username IDENTIFIED BY :password;

printf("Connected to Oracle\n");

for (;;)

{

printf("Account Number (0 to end)? ");

gets(temp);

acct_num = atoi(temp);

if(acct_num == 0)

{

EXEC SQL COMMIT WORK RELEASE;

printf("Exiting program\n");

break;

}

printf("Transaction Type - D)ebit or C)redit? ");

gets(temp);

trans_type = temp[0];

printf("Transaction Amount? ");

gets(temp);

trans_amt = atof(temp);

/*----------------- begin PL/SQL block -------------------*/

EXEC SQL EXECUTE

DECLARE

old_bal NUMBER(9,2);

err_msg CHAR(70);

nonexistent EXCEPTION;

BEGIN

:trans_type := UPPER(:trans_type);

IF :trans_type = ’C’ THEN -- credit the account

UPDATE accts SET bal = bal + :trans_amt

WHERE acctid = :acct_num;

IF SQL%ROWCOUNT = 0 THEN -- no rows affected

RAISE nonexistent;

ELSE

:status := ’Credit applied’;

END IF;

ELSIF :trans_type = ’D’ THEN -- debit the account

SELECT bal INTO old_bal FROM accts

WHERE acctid = :acct_num;

IF old_bal >= :trans_amt THEN -- enough funds

UPDATE accts SET bal = bal - :trans_amt

WHERE acctid = :acct_num;

:status := ’Debit applied’;

ELSE

:status := ’Insufficient funds’;

END IF;

ELSE

:status := ’Invalid type: ’ || :trans_type;

END IF;

COMMIT;

EXCEPTION

WHEN NO_DATA_FOUND OR nonexistent THEN

:status := ’Nonexistent account’;

WHEN OTHERS THEN

err_msg := SUBSTR(SQLERRM, 1, 70);

:status := ’Error: ’ || err_msg;

END;

END-EXEC;

/*----------------- end PL/SQL block ----------------------- */

printf("\nStatus: %s\n", status);

}

exit(0);

}

void

sql_error()

{

EXEC SQL WHENEVER SQLERROR CONTINUE;

EXEC SQL ROLLBACK WORK RELEASE;

printf("Processing error\n");

exit(1);

}

[Top]
No.
제목
작성자
작성일
조회
3435ROWID를 이용하여 RECORD 읽어 오는 방법?
swkim
2001-03-22
1471
3432{질문}ORA-12500 에러에 대해
박진성
2001-03-22
1910
3430export 시 data만 backup하는 건..
이석환
2001-03-22
1316
3429proc에서 stored procedure(PL/SQL) 호출하기
이태경
2001-03-22
4192
3431┕>Re: proc에서 stored procedure(PL/SQL) 호출하기
유은영
2001-03-22 10:05:27
2907
3428ORA-00314: log 3 of thread 1, expected sequence# 336 doesn't match 333 - 급요망
이상일
2001-03-21
2045
3426personal oracle8i 8.1.6 서버에서 tns, libtner설정은 어떻게?
궁금이
2001-03-21
1578
3423[기초질문] 죄송..검색해도 없고..기초..
이대현
2001-03-20
1670
3424┕>Re: [기초질문] 죄송..검색해도 없고..기초..
문태준
2001-03-20 21:10:41
1893
3425 ┕>Re: Re: [기초질문] 죄송..검색해도 없고..기초..
이대현
2001-03-20 23:09:46
1637
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.018초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다