What is wrong with declaration variable in function - oracle

I am trying to declare function and pass variable fixed_cost = 0 IN INT something like
FUNCTION GET_ALL_ENABLED_ACC(fixed_cost IN INT)
So the point is to declare fixed_cost and initialize value to 0 but I ge error
Error(37,16): PLS-00103: Encountered the symbol " " when expecting one of the following: . ( * # % & = - + ; < / > at in is mod remainder not rem <an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec between using || multiset member submultiset The symbol " " was ignored.
I try something like
fixed_cost : = 0 IN INT
AND
fixed_cost =: 0 IN INT
Also I try to change INT to NUMBER and after BEGIN initialize value but doesn't work.
FUNCTION GET_ALL_ENABLED_ACC(fixed_cost NUMBER)
RETURN SYS_REFCURSOR IS
rc SYS_REFCURSOR;
BEGIN
OPEN rc FOR
fixed_cost = 0;
SELECT Number_ FROM accounting_plan WHERE Enabled = 1 AND FixedCost = fixed_cost;
RETURN rc;
END GET_ALL_ENABLED_ACC;
What should I do in this case ?

It must be FUNCTION GET_ALL_ENABLED_ACC(fixed_cost IN INT:=0) or FUNCTION GET_ALL_ENABLED_ACC(fixed_cost IN INT default 0)

Related

Why does the dynamic sql statement erroring

I am trying to run the Dynamic SQL Query and get the output in the cursor. How to rewrite this statement?
OPEN ecur_SS FOR
EXECUTE IMMEDIATE 'select sSQLQUERY FROM DUAL';
END;
sSQLQUERY has my select statement.
sSQL := 'SELECT * from forms' ;
ecur_SS is out sys_refcursor
I am getting the following error:
Error: PLS-00103: Encountered the symbol "IMMEDIATE" when expecting
one of the following:
. ( * # % & = - + ; < / > at in is mod remainder not rem
<> or != or ~= >= <= <> and or like like2
like4 likec between using || multiset member submultiset The symbol "* was inserted before "IMMEDIATE" to continue.

PLS-00103 Encountered symbol ">" error while executing stored prcedure

I am having below stored procedure, when I try to execute it throws error. All the things are proper but don't know why this error it throws. can anybody help me to sort out this.
create or replace PROCEDURE FR_Notes_Mng (
P_STR_ID IN VARCHAR2,
p_Ref_no in VARCHAR2,
P_UserId in VARCHAR2,
P_Note IN VARCHAR2,
P_datestamp IN VARCHAR2,
p_Request_ID in varchar2,
p_WrittenDate IN VARCHAR2
) AS
numSqlCode Number := 0;
RecCounter Number :=0;
strTable varchar2(30) := 'FR_Notes';
strAction varchar2(30) := 'Insert';
vSQLERM VARCHAR2(200) :=SUBSTR(SQLERRM, 1, 85);
BEGIN
Select Count(*) into RecCounter From FR_Notes where str_id=P_str_ID and ref_no=P_Ref_No and user_id=P_UserId and notes=P_note and datestamp=P_Datestamp and to_date(writtendate,'YYYYMMDDHH24MISS')=to_Date(p_WrittenDate,'YYYYMMDDHH24MISS') and request_id=p_request_id;
If RecCounter=0 then
insert into Fr_Notes Values
(p_str_ID,p_ref_no,p_UserId,P_note,p_Datestamp,to_date(p_WrittenDate,'YYYYMMDDHH24MISS'),p_Request_ID,'FR',sysdate);
commit;
end if;
EXCEPTION
WHEN OTHERS THEN
numSqlCode := SQLCODE;
INSERT INTO FR_UNEXPECTED_ERRORS (TABLE_NAME, KEY, ACTION, ERR_CODE)
VALUES (strTable, vSQLERM, strAction, numSqlCode);
END;
Error Thrown:
ORA-06550: line 1, column 47: PLS-00103: Encountered the symbol ">" when expecting one of the following: . ( ) , * # % & = - + < / > at in is
mod remainder not rem <> or != or ~= >= <= <>
and or like like2 like4 likec between || multiset member submultiset
When I execute it at database level its executed properly but failed in vbscript code. Below is the vb-script code I used to execute and which is throwing this error
function InsertNotes(str_id,ref_no,userId,Note,strdatestamp,writtenDates)
Dim strcon2: set strcon2=server.CreateObject("ADODB.Connection")
Dim sql2
Dim strcmd2
strcon2.open "Provider=MSDAORA;Data Source="&Application("DBDsn")&";User Id="&Application("DBUserName")&"; Password="&Application("DBPassword")&";"
sql2 = "rep2.FR_Notes_Mng"
Set strcmd2 = Server.CreateObject("ADODB.Command")
Set strcmd2.ActiveConnection = strCOn2
strcmd2.CommandText = sql2
strcmd2.CommandType = 4
strcmd2.Parameters.Append strcmd2.CreateParameter("p_str_id", 200,1,50,str_id)
strcmd2.Parameters.Append strcmd2.CreateParameter("p_ref_no", 200,1,50,ref_no)
strcmd2.Parameters.Append strcmd2.CreateParameter("p_UserId", 200,1,50,userId)
strcmd2.Parameters.Append strcmd2.CreateParameter("p_note", 200,1,200,Note)
strcmd2.Parameters.Append strcmd2.CreateParameter("p_Datestamp", 200,1,50,strdatestamp)
strcmd2.Parameters.Append strcmd2.CreateParameter("p_Request_id", 200,1,50,"012")
strcmd2.Parameters.Append strcmd2.CreateParameter("p_WrittenDate", 200,1,50,writtenDates)
strcmd2.Execute
end function
Actually I have checked what values are getting passed in VB script call to that stored procedure and found that value for str_id is not getting passed hence the procedure execution was getting failed and throwing above error.
ORA-06550: line 1, column 47: PLS-00103: Encountered the symbol ">" when expecting one of the following: . ( ) , * # % & = - + < / > at in is
mod remainder not rem <> or != or ~= >= <= <>
and or like like2 like4 likec between || multiset member submultiset
I have assigned one value to str_id variable and rechecked by executing the code and it worked properly.
One thing I came to know here by this error which is, when we don't pass required parameter value or we pass the parameter as null even if it is mandatory that time this type of error get generated.
Thanks for all who helped me over this ask.

If statement inside Trigger not working SQL(Oracle)

My goal is to create a trigger that checks if the number you are trying to enter NR_RECIBO is in the table Doc_cabecalho with the attribute TIPO_DOC = 4
CREATE OR REPLACE TRIGGER ValidaRecibo
BEFORE INSERT ON Recibo
FOR EACH ROW
DECLARE val NUMBER;
BEGIN
SELECT COUNT(*) INTO val
FROM Doc_cabecalho
WHERE (TIPO_DOC = 4 AND NR_DOCUMENTO = :NEW.NR_RECIBO);
IF val = 0
THEN (-20502, ' Only from department 4 ');
END IF;
END ValidaRecibo;
Yet, this raises the following error:
PLS-00103: Encountered the symbol "," when expecting one of the following:
* & = - + < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like like2 like4 likec as between || member submultiset
IF val = 0 THEN
raise_application_error(-20502, ' Only from department 6 ');
And you should decide between DOC_TIPO and TIPO_DOC ;)

Oracle Database PLSQL Error: PLS-00103

I'm writing simple function in Oracle Database 11g that count summary salary for employee. For this we need to count days with specific status. Days is present as fields in table (Day_1, Day_2, ..., Day_30).
But i have got error during compilation:
Error(50,9): PLS-00103: Encountered the symbol ";" when expecting one of the following: :=.(#%;
Code of my package (a place where there is an error marked in code of function f2):
CREATE OR REPLACE PACKAGE pack IS
FUNCTION f1 (id IN NUMBER) return t2 PIPELINED;
FUNCTION f2 (id IN NUMBER) return number;
end pack;
/
CREATE OR REPLACE PACKAGE BODY pack IS
FUNCTION f1 (id IN NUMBER) return t2 PIPELINED IS
name VARCHAR2(50);
num number;
BEGIN
FOR i IN 1 .. id LOOP
SELECT отдел
into name
from отдел
where ид_отдела = i;
select sum(КОЛИЧЕСТВО)
into num
from Таблица_3
join Таблица_2
on Таблица_3.КТО_ПРОДАЛ = Таблица_2.ЧЛВК_ИД
where отдел = i;
PIPE ROW( t1(i, name, num) );
END LOOP;
RETURN;
END f1;
FUNCTION f2 (id IN NUMBER) return NUMBER AS
WorkingDays NUMBER := 0;
CurrentDay VARCHAR2(50);
Salary NUMBER := 120;
Total NUMBER := 0;
BEGIN
FOR i IN 1 .. 30 LOOP
EXECUTE IMMEDIATE 'SELECT День_' || i || ' FROM Таблица_2 WHERE ЧЛВК_ИД = id INTO CurrentDay';
IF WorkingDays IN ('КОМАНДИРОВКА','ВЫХОДНОЙ','ПРАЗДНИК') THEN -- <--- Here
WorkingDays := WorkingDays + 1;
END IF;
END LOOP;
Total : = Salary * WorkingDays;
RETURN Total;
END f2;
end pack;
/
How can i solve this? Maybe the problem is in the logic of the program?
That is an error on parsing, and be aware that it often does not accurately show the error itself, but where the next symbol error occurred. For example:
declare
x number;
y number;
begin
if x = 1 then
y := 1 --I forget to put on the semi-colon to end the line
end if;
end;
You'd expect an error on the missing semi-colon. What you get is:
ORA-06550: line 7, column 2:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
The symbol ";" was substituted for "END" to continue.
Since in your comments you talk about changing things - perhaps to make it more readable for us (and thank you!), it may be obscuring the actual syntax glitch.
Two things I notice:
Total : = Salary * WorkingDays;
That has a space between the : and = that shouldn't be there
and:
FUNCTION f2 (id IN NUMBER) return NUMBER AS
which is normally
FUNCTION f2 (id IN NUMBER) return NUMBER IS

Find string value based on a string key in a given string

I have a string like so:
Directory=Voice Active Directory A,ID=VT-AD1,Location=Canada,UserName=admin,Password=passw0rd,Selector=AD1
I'm writing a function that will receive this value as parameter and another parameter as UserName
I need to find the value against key UserName from the given string which is admin
I'm searching if there is a RegEx within oracle to help out here.
Here is what I have made so far:
CREATE OR REPLACE FUNCTION GET_CSV_FIELD(Parameter_RowData IN CLOB, Parameter_Field_Name IN VARCHAR2 )
RETURN VARCHAR2
AS
Found_Index INTEGER;
End_Index INTEGER;
Pair_Index INTEGER;
Return_Result VARCHAR2(4000);
BEGIN
Found_Index := INSTR(Parameter_RowData, Parameter_Field_Name);
IF Found_Index > 0 THEN
End_Index := INSTR(Parameter_RowData, ',', Found_Index);
Pair_Index := INSTR(Parameter_RowData, '=', Found_Index);
IF End_Index = 0 THEN
Return_Result := '';
RETURN Return_Result;
END IF;
IF Pair_Index = 0 THEN
Return_Result := '';
RETURN Return_Result;
END IF;
Return_Result := SUBSTR(Parameter_RowData, Pair_Index + 1, End_Index - Pair_Index - 1);
ELSE
Return_Result := '';
END IF;
RETURN Return_Result;
END;
Any better method? Thanks.
You can do this with regular expressions:
select substr(regexp_substr(str, 'UserName=[^,]+'), 10)
The general method would be
select substr(regexp_substr(str, v_param || '=[^,]+'), length(v_param) + 2)

Resources