Encountered the symbol "#" when expecting one of the following sql - sql

I am tring to create a stored procedure that will add a horse to my currently table but i am getting this error. Does anyone know why this error is occuring?
CREATE OR REPLACE PROCEDURE ADDHORSE (
HorseID IN INTEGER,
Stable IN VARCHAR2,
Horse_Name IN VARCHAR2,
DateofBirth IN DATE,
Sex Char:=1);
Height FLOAT,
Dam VARCHAR2:=30),
Sire VARCHAR2:=30)
)
AS
BEGIN
INSERT INTO horse(
[HorseID],
[Stable],
[Horse_Name],
[DateofBirth],
[Sex],
[Height],
[Dam],
[Sire]
) VALUES (
HorseID,
Stable,
Horse_Name,
DateofBirth,
Sex,
Height,
Dam,
Sire
)
END ADDHORSE;

I noted you had some missing quotes (') with your varchar and char and a missing ';' at the end of the insert.
This works for me:
CREATE OR REPLACE PROCEDURE ADDHORSE (
HorseID IN INTEGER,
Stable IN VARCHAR2,
Horse_Name IN VARCHAR2,
DateofBirth IN DATE,
Sex Char := '1',
Height FLOAT,
Dam VARCHAR2 := '30',
Sire VARCHAR2 := '30'
)
AS
BEGIN
INSERT INTO horse(
HorseID,
Stable,
Horse_Name,
DateofBirth,
Sex,
Height,
Dam,
Sire
) VALUES (
HorseID,
Stable,
Horse_Name,
DateofBirth,
Sex,
Height,
Dam,
Sire
);
END ADDHORSE;

You have a semi-colon and an extra bracket in your parameter list, does this work for you...
CREATE PROCEDURE ADDHORSE (
HorseID INTEGER,
Stable VARCHAR2,
Horse_Name VARCHAR2,
DateofBirth DATE,
Sex CHAR(1),
Height FLOAT,
Dam VARCHAR2(30),
Sire VARCHAR2(30)
)
AS
BEGIN
INSERT INTO horse(
[HorseID],
[Stable],
[Horse_Name],
[DateofBirth],
[Sex],
[Height],
[Dam],
[Sire]
) VALUES (
HorseID,
Stable,
Horse_Name,
DateofBirth,
Sex,
Height,
Dam,
Sire
)
END ADDHORSE;

Related

ORA-06553: PLS-801:Internal Error [55018]

I want to make a function call like SELECT URUN_GETIR('test1') FROM DUAL; but i got ORA-06553: PLS-801: Internal Error [55018].
I tried ORA-06553: PLS-801: internal error [55018] when testing function returning ROWTYPE this like for ex URUN_GETIR('test1').KULUSERNAME but getting same error. It didn't work for me.Thanks in advance.
My db table :
My plsql function code :
create or replace FUNCTION URUN_GETIR(KULADI VARCHAR2)
RETURN URUN%ROWTYPE
AS
URUN_TABLO URUN%ROWTYPE;
BEGIN
SELECT * INTO URUN_TABLO FROM URUN ur WHERE ur.kulusername = KULADI;
RETURN URUN_TABLO;
END;
You can achieve your goal with using table functions. Other than that you can not call directly your function like you wanted. Here is another choice for you Use Stackoverflow Wisely
CREATE TABLE URUN
(
CREATED_BY VARCHAR2 (50 CHAR),
CREATED_DATE DATE,
UPDATED_BY VARCHAR2 (50 CHAR),
KULUSERNAME VARCHAR2 (50 CHAR),
ID NUMBER (10)
);
INSERT INTO URUN (CREATED_BY, CREATED_DATE, UPDATED_BY, KULUSERNAME, ID) VALUES('TEST1',TO_DATE('19000101','YYYYMMDD') ,'TTEST1','USER1',1);COMMIT;
INSERT INTO URUN (CREATED_BY, CREATED_DATE, UPDATED_BY, KULUSERNAME, ID) VALUES('TEST2',TO_DATE('19000102','YYYYMMDD') ,'TTEST2','USER2',2);COMMIT;
INSERT INTO URUN (CREATED_BY, CREATED_DATE, UPDATED_BY, KULUSERNAME, ID) VALUES('TEST3',TO_DATE('19000103','YYYYMMDD') ,'TTEST3','USER3',3);COMMIT;
INSERT INTO URUN (CREATED_BY, CREATED_DATE, UPDATED_BY, KULUSERNAME, ID) VALUES('TEST4',TO_DATE('19000104','YYYYMMDD') ,'TTEST4','USER4',4);COMMIT;
CREATE OR REPLACE TYPE URUN_OBJ AS OBJECT
(
CREATED_BY VARCHAR2 (50 CHAR),
CREATED_DATE DATE,
UPDATED_BY VARCHAR2 (50 CHAR),
KULUSERNAME VARCHAR2 (50 CHAR),
ID NUMBER (10)
);
CREATE OR REPLACE TYPE URUN_OBJ_TAB AS TABLE OF URUN_OBJ;
CREATE OR REPLACE FUNCTION URUN_GETIR (KULADI IN VARCHAR2)
RETURN URUN_OBJ_TAB
PIPELINED
AS
REC_OBJ URUN_OBJ;
CURSOR DATA
IS
SELECT *
FROM URUN UR
WHERE UR.KULUSERNAME = KULADI;
BEGIN
FOR REC IN DATA
LOOP
REC_OBJ :=
URUN_OBJ (REC.CREATED_BY,
REC.CREATED_DATE,
REC.UPDATED_BY,
REC.KULUSERNAME,
REC.ID);
PIPE ROW (REC_OBJ);
END LOOP;
RETURN;
END;
/
SELECT * FROM TABLE(URUN_GETIR('USER1'));
CREATED_BY CREATED_DATE UPDATED_BY KULUSERNAME ID
TEST1 1.01.1900 TTEST1 USER1 1

Select object inside an object in PL/SQL

I have the following code:
SET SERVEROUTPUT ON
CREATE OR REPLACE TYPE work_t AS OBJECT(
company VARCHAR2(50),
salary NUMBER(5)
);
/
CREATE OR REPLACE TYPE person_t AS OBJECT(
personnum NUMBER(5),
personname VARCHAR2(20),
personwork work_t
);
/
CREATE TABLE people OF person_t(
PRIMARY KEY (personnum)
);
INSERT INTO people VALUES(12, 'George', work_t('Google',75500));
If I want to print personname:
DECLARE
per1 person_t;
BEGIN
SELECT VALUE(e) INTO per1 FROM people e WHERE e.personnum = 12;
dbms_output.put_line(per1.personname);
END;
/
Now I want to print the company (and update it in different blocks) but I don't know how to do it.
Thanks.
Just add
dbms_output.put_line(per1.personwork.company);
in
DECLARE
per1 person_t;
BEGIN
SELECT VALUE(e) INTO per1 FROM people e WHERE e.personnum = 12;
dbms_output.put_line(per1.personname);
dbms_output.put_line(per1.personwork.company);
END;
/

Teradata error SPL 1076 - The right parenthesis in parameter declaration is missing

I have created a blank table in Teradata called EMPLOYEE
CREATE MULTISET VOLATILE TABLE EMPLOYEE (
EmployeeNo INTEGER,
FirstName VARCHAR(30),
LastName VARCHAR(30),
DOB DATE FORMAT 'YYYY-MM-DD',
JoinedDate DATE FORMAT 'YYYY-MM-DD',
DepartmentNo BYTEINT
)
PRIMARY INDEX ( EmployeeNo ) On COMMIT PRESERVE ROWS;
Table is created.
Now i am trying to define a procedure to enter data into the table.
CREATE PROCEDURE InsertEmployee (
IN in_EmployeeNo INTEGER, IN in_FirstName VARCHAR(30),
IN in_LastName VARCHAR(30), IN in_DOB DATE FORMAT 'YYYY-MM-DD',
IN in_JoinedDate DATE FORMAT 'YYYY-MM-DD', IN in_DepartmentNo BYTEINT
)
BEGIN
INSERT INTO EMPLOYEE(
EmployeeNo,
FirstName,
LastName,
DOB,
JoinedDate,
DepartmentNo
)
VALUES (
:in_EmployeeNo,
:in_LastName,
:in_FirstName,
:in_DOB,
:in_JoinedDate,
:in_DepartmentNo
);
END;
This is where I repeatedly get 2 errors:
SPL1076:E(L3), The right parenthesis in parameter declaration is missing.
SPL1048:E(L3), Unexpected text ';' in place of SPL statement.

function that will only insert Monday-Friday?

I've created a function that will insert a customer into the database, I just wondered if it was possible to make it so it will only except inserts on Monday to Friday days at how this would be done in Oracle SQL?
Here is the code for the function that is running and works
FUNCTION CREATE_CUSTOMER(
Country IN VARCHAR2
,First_Name IN VARCHAR2
,Last_Name IN VARCHAR2
,Birth_Date IN VARCHAR2
,Customer_Type IN VARCHAR2
,Address IN VARCHAR2
) return VARCHAR2 IS
new_customer_id VARCHAR2(8);
BEGIN
SELECT custid_seq.NEXTVAL
INTO new_customer_id
FROM DUAL;
INSERT INTO customer (Customer_id, Country, First_Name, Last_name, Birth_date, Customer_Type, Address)
VALUES (new_customer_id, Country, First_Name, Last_name, Birth_date, Customer_Type, Address);
total_customers := total_customers + 1;
RETURN (new_customer_id);
end;
Anyone got any idea how to develop this or if its possible?
thanks
You want the insert statement to run only on Weekdays? If so, you can check the day of the weeks using
to_char(sysdate,'D')
It returns numbers 1-7(Sunday to Saturday). Based on this you can decide whether to insert or not.

SELECT COMMAND SQL more than 1 value

Im trying to create a select command to query the database I have and find different values from different tables in the database.
Try the following, I change all ID columns from CHAR to NUMBER
CREATE TABLE Actor
(actorID NUMBER,
lastName CHAR(24),
firstName CHAR(24),
middleName CHAR(24),
suffix CHAR(6),
gender CHAR(1),
birthDate DATE,
deathDate DATE)
/
CREATE TABLE Movie
(movieID NUMBER,
title CHAR(36),
year NUMBER,
company CHAR(50),
totalNoms NUMBER,
awardsWon NUMBER,
DVDPrice NUMBER(5,2),
discountPrice NUMBER(5,2))
/
CREATE TABLE Role
(roleID NUMER,
roleName CHAR(36),
gender CHAR(1),
actorID NUMBER,
movieID NUMBER)
/
CREATE TABLE Quote
(quoteID NUMBER,
quoteCHAR CHAR(255))
/
CREATE TABLE RoleQuote
(roleID NUMBER,
quoteID NUMBER)
/
and the select will be:
SELECT Movie.Title , Movie.Year , Actor.Firstname, Actor.lastname, Role.roleName, Quote.quoteCHAR
FROM Movie, Actor, Role, Quote, RoleQuote
WHERE Movie.movieID = Role.movieId AND
Actor.actorID = Role.ActorId AND
Role.roleID = RoleQuote.roleID AND
Quote.quoteID = RoleQuote.quoteID AND
Quote.quoteCHAR LIKE '%Houston, we have a problem.%'