we have two tables : Account and Client
CREATE TABLE Client ( NumClient NUMBER(3) NOT NULL PRIMARY KEY,
ClientName VARCHAR (25) NOT NULL,
City VARCHAR (25) NOT NULL
);
CREATE TABLE Compte ( NumCompte NUMBER(1) NOT NULL PRIMARY KEY,
NumClient NUMBER(3) NOT NULL REFERENCES Client(NumClient),
DateOpening DATE NOT NULL,
balance FLOAT ,
PMVR NUMBER DEFAULT 0
);
procedure is as follows:
OpenAccount(NumCli in number, Amount in number)
This procedure creates a new account for a customer (NumCli) with a first balance (Amount):
- NumCaccount is automatically assigned by a sequence;
- DateOpen is the system date;
- Amount > 0;
- PMVR is initialized to 0;
If the customer does not exist, there is an error.
I have a sequence called :
CREATE SEQUENCE seqClient START WITH 101 INCREMENT BY 1;
CREATE SEQUENCE seqAccount START WITH 1 INCREMENT BY 1;
Here is text of procedure
CREATE OR REPLACE PROCEDURE OpenAccount(NumCli IN NUMBER, Amount in NUMBER)
IS
non-existent_client EXCEPTION;
PRAGMA EXCEPTION_INIT (non-existent_client, -2291);
BEGIN
IF (Amount < 0)
THEN
RAISE_APPLICATION_ERROR (-20002,'the amount must be greater than 0');
ELSE
INSERT INTO Account (AccountNumber,
ClientNumber,
DateOpening date,
Balance,
PMVR)
VALUES (seqCount.NEXTVAL,
NumCli,
TO_DATE (sysdate,'DD.MM.YY'),
Amount,
0);
END IF;
EXCEPTION
WHEN
non-existent_customer
THEN
DBMS_OUTPUT.PUT_LINE (
Client No' ||| TO_CHAR (NumCli) ||| ' non-existent');
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE (
Oracle error:' |||| SQLCODE ||| '; Oracle message: ||||| SQLERRM);
END;
When I run it like this
execute OpenAccount(101,1600);
I get this error :
9/9 PL/SQL: SQL Statement ignored
10/81 PL/SQL: ORA-00984: Column not permissible here
Translated with www.DeepL.com/Translator (free version)