I receive the following error when I compile this function:
Compilation errors for PROCEDURE HAR.REPORT_INCOME_PROC PLS-00103:
Encountered the symbol "" when expecting one of the following
I have try to google for that, but I cant my fault...
CREATE OR REPLACE PROCEDURE REPORT_INCOME_PROC IS
BEGIN
DELETE FROM HAR.REPORT_INCOME;
INSERT INTO HAR.REPORT_INCOME RI
(RI.INCOME,
RI.AREA,
RI.INCOME_TYPE,
RI.DATA_DATE,
RI.CREATE_DATE,
RI.UPDATE_DATE)
SELECT SUM(YD.HJJE) DRSR,
MDYS.JYDQ SYB,
1,
TRUNC(YD.KDSJ) RQ,
(select sysdate from dual) XZSJ,
(select sysdate from dual) XGSJ
FROM HYDATA.LD_YD YD
LEFT JOIN HYDATA.LD_KHXX KHXX
ON YD.TYRBH = KHXX.KHBH
LEFT JOIN HYDATA.LD_GS GS
ON YD.QYDZBH = GS.GSBH
LEFT JOIN HAR.REPORT_JY_MDYS MDYS
ON YD.QYDZBH = MDYS.GSBH
WHERE YD.KDSJ >= TRUNC(ADD_MONTHS(SYSDATE, -12), 'yy')
AND (YD.YDZT != 5)
AND (YD.CYRQZ != '20000000000000000001' OR YD.CYRQZ IS NULL)
AND (KHXX.KHLB != 4 OR KHXX.KHLB IS NULL)
AND (GS.GSJC NOT LIKE '%F%' OR GS.GSJC IS NULL)
GROUP BY TRUNC(YD.KDSJ), MDYS.JYDQ
ORDER BY MDYS.JYDQ ASC, TRUNC(YD.KDSJ) DESC;
COMMIT;
END;
Here is the error
Error: PLS-00103: Encountered the symbol "" when expecting one of the
following:
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursor external language Line: 1
Hi I believe you need to use EXECUTE IMMEDIATE on a PLSQL BLOCK when doing DML statements.
try this:
CREATE OR REPLACE PROCEDURE REPORT_INCOME_PROC IS
BEGIN
EXECUTE IMMEDIATE 'DELETE FROM HAR.REPORT_INCOME';
EXECUTE IMMEDIATE 'INSERT INTO HAR.REPORT_INCOME RI <the rest of your codes>';
END;
Related
I am trying to write a PL/SQL function that returns a number. I must use the number in SQL where clause. The function is in the following:
CREATE OR REPLACE FUNCTION func_id(str_id IN STRING,num_group IN NUMBER)
RETURN NUMBER
IS
result NUMBER;
declare
temp STRING;
BEGIN
temp := substr(str_id, -least(length(str_id), 2));
result := TO_NUMBER(temp) % num_group;
RETURN result;
END;
select * from table where func_id("id",2)=1
2 and 1 are just an example. I want to call the function in my Scala Program that variables are replaced in place of 2 and 1.
When I run the code in SQL Developer I receive this error:
Function FUNC_ID compiled
LINE/COL ERROR
--------- -------------------------------------------------------------
5/1 PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type <an identifier> <a double-quoted delimited-identifier> current cursor delete exists prior The symbol "begin" was substituted for "DECLARE" to continue.
13/54 PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: . , # ; for <an identifier> <a double-quoted delimited-identifier> group having intersect minus order partition start subpartition union where connect sample
Would you please guide me how to write a PL/SQL function and call it in another query or any where else?
Any help is really appreciated.
DECLARE is syntactically invalid in that position;
STRING is not a valid data type, you want VARCHAR2;
% is not a valid operator, you want the MOD function; and
The intermediate variables are not required.
CREATE OR REPLACE FUNCTION func_id(
str_id IN VARCHAR2,
num_group IN NUMBER
) RETURN NUMBER
IS
BEGIN
RETURN MOD(TO_NUMBER(substr(str_id, -LEAST(2, LENGTH(str_id)))), num_group);
END;
/
Then, if you have the table:
CREATE TABLE table_name ( id ) AS
SELECT '1' FROM DUAL UNION ALL
SELECT '24' FROM DUAL UNION ALL
SELECT '10-05' FROM DUAL;
You can call the function using:
select id,
func_id(id, 23)
from table_name
Which outputs:
ID
FUNC_ID(ID,23)
1
1
24
1
10-05
5
db<>fiddle here
I am fairly new to the oracle forms. I have a requirement of using the json_table function. When i run the below query I get the error message mentioned below. But when I run the same query in sql developer it works. Would be great if someone could help me find out the rootcause for the same. Thank you.
SELECT RPTD.GROUP_TODO_ID,
query_json.event_id
into :GLOBAL.RVS_ID,:GLOBAL.RV_EV_ID
FROM RGTD ,
RPTD
,json_table(RGTD.REVSHARE_INFO, '$' COLUMNS ( NESTED PATH '$.revenueShareFunds[*]' COLUMNS ( ID
VARCHAR2(10) PATH '$.rapId' , EVENT_ID VARCHAR2(12) PATH '$.revenueShareEventId')))
query_json
WHERE QUERY_JSON.ID = 'xxxxx'
AND RGTD.ID = RPTD.GROUP_TODO_ID
AND rownum =1;
Error I get while compiling the 12c oracle forms :
Compiling PRE-QUERY trigger on REVSHARE_PART_TO_DO data block...
Compilation error on PRE-QUERY trigger on REVSHARE_PART_TO_DO data block:
PL/SQL ERROR 103 at line 23, column 95
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 || multiset member submultiset
The symbol ")" was substituted for ";" to continue.
For the recent versions of Forms(10,11), even the explicit join was not possible within the forms. So, you rather can put the query into a stored procedure within the DB such as
CREATE OR REPLACE PROCEDURE Get_ID_Values(
i_json_id IN VARCHAR2,
o_rvs_id OUT rptd.group_todo_id%type,
o_rv_ev_id OUT VARCHAR2,
o_error OUT VARCHAR2
)
AS
BEGIN
SELECT rptd.group_todo_id, query_json.event_id
INTO o_rvs_id, o_rv_ev_id
FROM rgtd
JOIN rptd
ON rgtd.id = rptd.group_todo_id
CROSS JOIN json_table(rgtd.revshare_info,
'$' COLUMNS(NESTED PATH '$.revenueShareFunds[*]'
COLUMNS(id VARCHAR2(10) PATH '$.rapId',
event_id VARCHAR2(12) PATH
'$.revenueShareEventId'))) query_json
WHERE query_json.id = i_json_id
AND rownum = 1;
EXCEPTION WHEN no_data_found THEN o_error := 'No Data Found';
WHEN others THEN o_error := sqlerrm;
END;
/
all call that from the current PRE-QUERY trigger.
Hi I am writing a simple set of oracle statements but I am getting an error saying "PLS-00103: Encountered the symbol DROP when expecting one of the following". I am not sure what is wrong with my statements. Any help is appreciated.
DECLARE
table_exists number := 0;
BEGIN
SELECT COUNT(*) INTO table_exists FROM dba_tables WHERE owner = 'ABC'
AND table_name = 'XYZ';
If (table_exists = 1) then
DROP TABLE "ABC"."XYZ";
End If;
End;
If you want use DDL statements in PL/SQL blocks, you have to use dynamic SQL.
Try this:
execute immediate 'DROP TABLE ' || owner.table_name
I am trying to to set a variable (v_flag_id) to the result of a query. I've been looking online at examples and it seems like my formatting/syntax is correct. What am i doing wrong? Thanks in advance.
create or replace PROCEDURE RUN_AGG
is
declare
v_Flag_id Number := select flag_id from flag where flag_tx = 'Processed / Calculated';
CURSOR hours IS
SELECT distinct(HR) as RHR
, submission_value_id
from (
select
v.DATA_DATE,
v.HR,
sv.submission_value_id
from value v
inner join submission_value sv on sv.value_id = v.value_id
where sv.SUBMISSION_VALUE_ID NOT IN (
SELECT SUBMISSION_VALUE_ID FROM VALUE_FLAG WHERE VALUE_FLAG.FLAG_ID = v_Flag_id
);
BEGIN
OPEN hours;
LOOP
FETCH hours into l_hr;
EXIT WHEN hours%NOTFOUND;
AGG_HOURLY_REG_FINAL(l_hr.RHR);
END LOOP;
CLOSE hours;
END RUN_AGG;
The error that I am receiving is as follows:
Error(6,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one
of the following: begin function pragma procedure subtype type <an
identifier> <a double-quoted delimited-identifier> current cursor delete
exists prior external language
Use the following :
CREATE OR REPLACE PROCEDURE RUN_AGG IS
l_rhr VARCHAR2 (100);
l_sub_vl_id VARCHAR2 (100);
CURSOR hours is
SELECT distinct (HR) as RHR, submission_value_id
FROM (SELECT v.DATA_DATE, v.HR, sv.submission_value_id
FROM value_ v
INNER JOIN submission_value sv
ON (sv.value_id = v.value_id)
WHERE sv.SUBMISSION_VALUE_ID NOT IN
(SELECT SUBMISSION_VALUE_ID
FROM VALUE_FLAG
WHERE VALUE_FLAG.FLAG_ID in
(SELECT flag_id
FROM flag
WHERE flag_tx = 'Processed / Calculated')));
BEGIN
OPEN hours;
LOOP
FETCH hours INTO l_rhr, l_sub_vl_id;
EXIT WHEN hours%NOTFOUND;
AGG_HOURLY_REG_FINAL(l_rhr);
END LOOP;
CLOSE hours;
END RUN_AGG;
remove declare
take select flag_id into v_Flag_id from flag where flag_tx =
'Processed / Calculated'; sql in hours cursor's select. So, remove v_Flag_id variable.
return two variables for two columns l_rhr and l_sub_vl_id.
I replaced the name of the table value with value_, since it's a
reserved keyword for oracle.
I have created a procedure using the following code using iSQL Plus on Firefox. The procedure compiles successfully.
create or replace procedure get_staff (
product_no in varchar2,
o_cursor out sys_refcursor)
is
begin
open o_cursor for
'select sr.name, sr.bonus from sales_staff sr inner join product p on p.sales_staff_id = sr.staff_id where product_no = ' || product_no ;
end;
I am trying to call this procedure using the following code
var rc refcursor
exec get_staff('A56',:rc)
print rc
I get the following error.
ERROR at line 1:
ORA-00904: "A56": invalid identifier
ORA-06512: at "AA2850.GET_STAFF", line 6
ORA-06512: at line 1
ERROR:
ORA-24338: statement handle not executed
SP2-0625: Error printing variable "rc"
in the case you have, there's no need for dynamic sql:
open o_cursor for
select sr.name, sr.bonus
from sales_staff sr
inner join product p
on p.sales_staff_id = sr.staff_id
where p.product_no = product_no;
if you were using dynamic SQL then ideally you would in most cases want to bind:
open o_cursor for
'select sr.name, sr.bonus
from sales_staff sr
inner join product p
on p.sales_staff_id = sr.staff_id
where p.product_no = :b1' using product_no;
failing that (edge cases, sometimes you want to avoid bind variables for skewed data), varchar2s need enclosing in quotes:
open o_cursor for
'select sr.name, sr.bonus
from sales_staff sr
inner join product p
on p.sales_staff_id = sr.staff_id
where p.product_no = ''' ||product_no||'''';
but you should escape single quotes and validate that product_no has no semi colons etc (i.e. careful of SQL injection)