PL/SQL with INSERT new data to table with validation [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Created a simple PL/sql
CREATE OR REPLACE PROCEDURE Insert_Invoice(
inv_number IN NUMBER,
cust_id IN NUMBER,
date_in DATE,
date_out DATE,
Sub_tot IN NUMBER,
tax IN NUMBER,
total IN NUMBER) IS
BEGIN
INSERT INTO INVOICE VALUES( inv_number, cust_id, date_in,date_out,
Sub_tot,tax,total);
COMMIT;
END Insert_Invoice;
I having an error that ORA-06550 at line1, column 7
PLS-00201,indentifier 'INSERT_INVOICE' must be declared
but i following the example at website but it's still doesn't work. isn't my structure problem?

I haven't seen the procedure name on the end statement in PL/SQL. Try putting it in a comment:
BEGIN
INSERT INTO INVOICE VALUES( inv_number, cust_id, date_in,date_out,
Sub_tot,tax,total);
COMMIT;
END; -- Insert_Invoice

Related

How to create TRIGGER column id auto increment with string in oracle database? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Result that I want in column id: S-1, S-2, S-3
CREATE OR REPLACE TRIGGER auto_id
BEFORE INSERT ON login
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
:NEW.id := :NEW.id || to_char('"S-"',to_char(seq_log.nextval));
END login;
But when I insert data its error
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "WKSP_WORKSPACE0089.AUTO_ID", line 3
ORA-04088: error during execution of trigger 'WKSP_WORKSPACE0089.AUTO_ID'
ORA-06512: at "SYS.DBMS_SQL", line 1721
Should be
:NEW.id := :NEW.id || 'S-' || to_char(seq_log.nextval);

postgresql- how to define a variable by a function call in an if statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have this function:
CREATE OR REPLACE FUNCTION findMyList( p_user_id bigint)
....
DECLARE
myVar_id bigint;
...
IF myVar_id = select p_user_id from myFunction(p_user_id ) THEN
NULL;
ELSE
myVar_id := NULL;
END IF;
however there appears to be a syntax issue that I can't work out why it does not allow this as it doesnt seem unreasonable:
ERROR: syntax error at or near "select"
LINE 78: IF myVar_id = select p_user_id from myFunction...
why does it not let me define the variable as such?
Try :
myVar_id := (SELECT p_user_id from myFunction(p_user_id))

sql project aid required [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm trying to generate a trigger that if a column within a table is filled in with a specific set value e.g. i have a column named 'Volunteertype' which can only be assigned either 'staff' of 'student', if student is entered the trigger must nullify all columns relating to staff details within the volunteer table such as 'area of work', 'staffmanager' etc below is code i have tried to put together utilising the resources on the website however i'm having no luck.
CREATE TRIGGER trg_voltype
ON Volunteer
AFTER INSERT
AS
IF EXISTS (SELECT NULL FROM inserted i WHERE VolunteerType = 'student')
FOR EACH ROW BEGIN;
UPDATE v
SET Area_of_work = NULL
SET StaffManagerName = NULL
SET StaffManagerEmail = NULL
SET StaffManagerPhone = NULL
FROM Volunteer v
JOIN inserted i ON v.Volunteer_id = i.Volunteer_id
WHERE v.VolunteerType = 'student';
END;
However when this is run within the Oracle environment an error is produced ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword. when i attempt to shift the 'AFTER INSERT' to before the keyword i get an 'invalid trigger' error
Is anyone able to assist and inform me if the code itself is correct/ incorrect and how i should go about amending the code, thanks in advance and have a wonderful end to the year thanks!
Your trigger should be like :
CREATE OR REPLACE TRIGGER trg_voltype
BEFORE INSERT ON volunteer
FOR EACH ROW
BEGIN
if :new.Volunteertype = 'STUDENT'
then
:new.Area_of_work := NULL;
:new.StaffManagerName := NULL;
:new.StaffManagerEmail := NULL;
:new.StaffManagerPhone := NULL ;
end if;
END;

SQL procedure to select a column value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am tring to write a sql procedure with some select and insert statements. But I am getting some errors. I am not able to figure out what the problem is. Kindly help me.
Following is the error I am getting:
Error(15,1): PL/SQL: Statement ignored
Error(15,22): PLS-00201: identifier 'PROJECT_ID' must be declared
Code:
create or replace
PROCEDURE UPDATION
(
NO_IN IN VARCHAR2
) IS
poject_id defects.reference_id%type;
BEGIN
Select REFERENCE_ID INTO poject_id from DEFECTS where ID=NO_IN;
dbms_output.put_line(project_id);
if poject_id is not null then
dbms_output.put_line('proj not null');
end if;
end;
You had syntax error on the project_id declaration.
create or replace
PROCEDURE UPDATION
(
NO_IN IN VARCHAR2
) IS
project_id defects.reference_id%type;
BEGIN
Select REFERENCE_ID INTO project_id from DEFECTS where ID=NO_IN;
dbms_output.put_line(project_id );
if project_id is not null then
dbms_output.put_line('proj not null');
end if;
end;
line 6
poject_id defects.reference_id%type;
project*

overloading procedure in package [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Below is the HEADER for the Package TASK5
CREATE OR REPLACE PACKAGE TASK5
AS
PROCEDURE TASK5APROCEDURE (
REG_NO IN NUMBER,
CERT_TITLE OUT VARCHAR2,
E_DATE OUT DATE,
C_MARKS OUT INTEGER);
PROCEDURE TASK5BPROCEDURE (
CERT_ID IN CHAR,
C_T OUT CHAR) ;
END TASK5;
The BODY for the PACKAGE TASK5
CREATE OR REPLACE PACKAGE BODY TASK5
AS
PROCEDURE TASK5APROCEDURE (
REG_NO IN NUMBER,
CERT_TITLE OUT VARCHAR2,
E_DATE OUT DATE,
C_MARKS OUT INTEGER)
IS
BEGIN
SELECT
O.PCP_TITLE,
C.CERT_EXAMDATE,
C.CERT_MARKS
INTO
CERT_TITLE,
E_DATE,
C_MARKS
FROM
PROFCERTPROGRAM O
INNER JOIN
CERTIFICATION C
ON O.PCP_ID = C.PCP_ID
WHERE
C.S_REGNO LIKE REG_NO;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND');
END TASK5APROCEDURE;
PROCEDURE TASK5BPROCEDURE (
CERT_ID IN CHAR, C_T OUT CHAR)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE ('COURSE NAMES: ');
FOR R IN (
SELECT O.C_TITLE C_T
FROM
COURSE O
INNER JOIN
CERTIFICATIONREQUIREMENT C
ON O.C_ID = C.C_ID
WHERE
C.PCP_ID LIKE '%'||CERT_ID||'%')
LOOP
DBMS_OUTPUT.PUT_LINE (R.C_T);
END LOOP ;
END TASK5BPROCEDURE;
END TASK5;
I wrote the package with two different procedure for 2 different input.
But, I want to rewrite the header and body with overloading procedure, any suggestions?
Overloading means creating multiple procedures or functions of the same name in a package, which take different numbers of arguments and / or where the arguments have different datatypes. This enables you to call a procedure and have different things happen depending on the arguments given.
The answer to your question, therefore, is that simple. Rename TASK5BPROCEDURE to TASK5APROCEDURE in both the package specification and the package body. Alternatively, rename them both to something different. As an example your specification might look like this afterwards:
create or replace package task5 as
procedure task5procedure (
, reg_no in number
, cert_title out varchar2
, e_date out date
, c_marks out integer);
procedure task5procedure (
, cert_id in char
, c_t out char);
end task5;
On a little side note using dbms_output.put_line in a caught exception isn't really best practice. If you're going to catch an exception you should do something with it.
As APC notes in the comment it would be normal to overload a procedure when you are doing highly related things. For example if you're sending an e-mail using a procedure and you're passing the e-mail addresses either as a string or as an array. You don't seem to be doing the same thing in your procedures here and may want to reconsider the necessity of doing this.