Json_table function in oracle forms 12c - oracle

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.

Related

Compilation Errors in Procedure of Oracle 10g

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;

getting error while compiling the stored procedure

I am writing this below stored procedure but i am also getting the exception while compiling the procedure in oracle, below is the procedure
CREATE OR REPLACE PACKAGE BODY TEST_TABLE AS
PROCEDURE TEST_TABLE
--This procedure will delete partitions for the following tables:
--TEST_TABLE
BEGIN
FOR cc IN
(
SELECT partition_name, high_value
FROM user_tab_partitions
WHERE table_name = 'TEST_TABLE'
)
LOOP
EXECUTE IMMEDIATE 'BEGIN
IF sysdate >= ADD_MONTHS(' || cc.high_value || ', 3) THEN
EXECUTE IMMEDIATE
''ALTER TABLE TEST_TABLE DROP PARTITION ' || cc.partition_name || '
'';
END IF;
dbms_output.put_line('drop partition completed');
END;';
END LOOP;
exception
when others then
dbms_output.put_line(SQLERRM);
END;
END;
/
and the exception that I am getting it while compiling is Please advise how to overcome from this.
Error(7,1): PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: ( ; is with authid as cluster order using external deterministic parallel_enable pipelined result_cache The symbol ";" was substituted for "BEGIN" to continue.
Error(22,25): PLS-00103: Encountered the symbol "DROP" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem return returning <an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec between into using || bulk member submultiset
You need to make correct quotation as below( and one more is keyword just after PROCEDURE TEST_TABLE "thanks to Alex who make me awaken" ) :
CREATE OR REPLACE PACKAGE BODY PKG_TEST_TABLE IS
PROCEDURE TEST_TABLE IS
--This procedure will delete partitions for the following tables:
--TEST_TABLE
BEGIN
FOR cc IN
(
SELECT partition_name, high_value
FROM user_tab_partitions
WHERE table_name = 'TEST_TABLE'
)
LOOP
BEGIN
IF sysdate >= ADD_MONTHS(cc.high_value, 3) THEN
EXECUTE IMMEDIATE
'ALTER TABLE TEST_TABLE DROP PARTITION ' || cc.partition_name;
Dbms_Output.Put_Line('Dropping partition is completed.');
END IF;
END;
END LOOP;
EXCEPTION WHEN Others THEN Dbms_Output.Put_Line( SQLERRM );
END TEST_TABLE;
END PKG_TEST_TABLE;
/
As a little suggestion use a different name for package than procedure such as PKG_TEST_TABLE against confusion.
Edit : of course you need to create a specification part for a package before the body part of the package :
CREATE OR REPLACE PACKAGE PKG_TEST_TABLE IS
PROCEDURE TEST_TABLE;
END PKG_TEST_TABLE;
/
The first error message tells you something is missing before BEGIN, and even mentions the two possible options in the 'when expecting' list. You need to change it to:
PROCEDURE TEST_TABLE IS
-- ^^
Or you can use AS instead of IS if you prefer...
The second error is because you have a string literal embedded in your dynamic SQL and you haven't escaped the single quotes, though you have elsewhere:
...
dbms_output.put_line(''drop partition completed'');
-- ^ ^
END;';
You could use the alternative quoting mechanism instead.
I'm not sure why you're doing two levels of dynamic SQL; you can do the dbms_output() and evaluate cc.high_value statically, and decide whether to make the alter call, with only that part dynamic (as #BarbarosĂ–zhan has shown, so I wont repeat that!). Or do the high-value check within the cursor query.
I am still getting exception Error(1,14): PLS-00304: cannot compile body of 'TEST_TABLE' without its specification
If you want a package then you have to create its specification before you try to create its body:
CREATE OR REPLACE PACKAGE TEST_TABLE AS
PROCEDURE TEST_TABLE;
END TEST_TABLE;
/
CREATE OR REPLACE PACKAGE BODY TEST_TABLE AS
PROCEDURE TEST_TABLE IS
BEGIN
FOR cc IN
...
LOOP
...
END LOOP;
END TEST_TABLE; -- end of procedure
END TEST_TABLE; -- end of package
/
Having the package name the same as a procedure within it is a bit odd and confusing.
But maybe you didn't actually want a package at all, and were trying to create a standalone procedure, in which case just remove the package-body part:
CREATE OR REPLACE PROCEDURE TEST_TABLE AS
BEGIN
FOR cc IN
...
LOOP
...
END LOOP;
END TEST_TABLE; -- end of procedure
/
Read more.
I would strongly suggest you get rid of the exception handler, and I've left that out of those outlines - you should let any exception flow back to the caller. You don't know that whoever calls this will even have output enabled, so might well not even see the message you're printing instead. Only ever catch exceptions you can handle and need to handle at that point.

I am getting compilation error in creating Oracle Proceedure

iam creating a proceedure it is giving compilation error
of right paranthesis missing
Line # = 9 Column # = 21 Error Text = PL/SQL: ORA-00907: missing right
parenthesis
CREATE OR REPLACE PROCEDURE user1.trns (XMLDATA XMLTYPE)
IS
BEGIN
UPDATE table1 SET T$fld1 = 1, T$dat1 = TO_DATE(TO_CHAR(sysdate,'DD/MM/YYYY'),'DD/MM/YYYY')
WHERE table1.T$docn IN
(
SELECT DISTINCT docn
FROM XMLTABLE
('/DataSet/Document/DocumentRow'
PASSING XMLDATA COLUMNS
docn PATH '#DOCN'
)
);
COMMIT;
END trns;
/
what am i doing wrong here
You are missing data type here as below please provide data type for XMLTABLE column:
here i have written varchar2(30)
CREATE OR REPLACE PROCEDURE user1.trns (XMLDATA XMLTYPE)
IS
BEGIN
UPDATE table1 SET T$fld1 = 1, T$dat1 = TO_DATE(TO_CHAR(sysdate,'DD/MM/YYYY'),'DD/MM/YYYY')
WHERE table1.T$docn IN
(
SELECT DISTINCT docn
FROM XMLTABLE
('/DataSet/Document/DocumentRow'
PASSING XMLDATA COLUMNS
docn varchar2(30) PATH '#DOCN'
)
);
COMMIT;
END trns;
Here is my output

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.

Getting inconsistent datatypes error while fetching data from ref cursor into a nested table

I'm getting an error while fetching data from ref cursor into a nested table. Here is what I'm doing.
Object and table types:
CREATE OR REPLACE TYPE obj_report_org IS OBJECT
(dummy1 VARCHAR2(50),
dummy2 VARCHAR2(50),
dummy3 VARCHAR2(50),
dummy4 NUMBER(10));
CREATE OR REPLACE TYPE tab_report_org IS TABLE OF obj_report_org;
Procedure:
CREATE OR REPLACE PROCEDURE areaReport_test(v_name1 VARCHAR2,
v_name2 VARCHAR2, tab_report_set OUT tab_report_org)
IS
str VARCHAR2(2000);
v_num NUMBER := 1;
recordset SYS_REFCURSOR;
lv_tab_report_set tab_report_org := tab_report_org();
BEGIN
str := ' SELECT tab2.dummy1 ,tab3.dummy2,tab2.dummy3,tab1.dummy4 '||
' FROM tab1,tab2, tab3, tab4'||
' WHERE <JOIN CONDITIONS>';
OPEN recordset FOR
str||' START WITH tab1.name = :name1'||
' CONNECT BY PRIOR tab1.id = tab1.parent_id'||
' UNION '||
str||' START WITH tab1.name = :name2'||
' CONNECT BY PRIOR tab1.id = tab1.parent_id'
USING v_name1,v_name2;
FETCH recordset BULK COLLECT into lv_tab_report_set;
CLOSE recordset;
tab_report_set := lv_tab_report_set;
END;
Then I have an anonymous block to call the procedure:
DECLARE
l_tab_report_set tab_report_org;
BEGIN
areaReport_test('PRASHANT',null,l_tab_report_set);
FOR i in 1 .. l_tab_report_set.count
LOOP
DBMS_OUTPUT.PUT_LINE(
l_tab_report_set(i).dummy1|| ' | ' ||
l_tab_report_set(i).dummy2|| ' | ' ||
l_tab_report_set(i).dummy3|| ' | ' ||
l_tab_report_set(i).dummy4|| );
END LOOP;
END;
After running the anonymous block, I'm get this error:
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "AREAREPORT_TEST", line 36
ORA-06512: at line 5
00932. 00000 - "inconsistent datatypes: expected %s got %s"
It seems we cannot bulk fetch data into nested table formed from a SQL object. While sequence of fields and datatypes in object match with select query.
Please advise.
I will start from the bottom:
FETCH recordset BULK COLLECT into lv_tab_report_set;
There is a recordset that you are fetching into table of objects. So, recordset should contain list of objects.
SELECT tab2.dummy1 ,tab3.dummy2,tab2.dummy3,tab1.dummy4...
It is a list of columns and not an object. Here is a list of objects:
select obj_report_org(tab2.dummy1 ,tab3.dummy2,tab2.dummy3,tab1.dummy4) ...
few remarks about code in general
When you use UNION instead of UNION ALL, Oracle would sort both results and eliminate duplicates (there is no other way to do that). So just think about if you really need UNION and remember that there is a price for that.
You UNION two datasets that looks like could be combined together
START WITH tab1.name in (:name1, :name2)
Continues after ORA-22950
You are implisitly ordering your elements, but how ORACLE knows how to sort them?
By dummy1 or dummy2 or ...?
You have to options:
do not use sorting
that basically means no DISTINCT, GROUP BY, ORDER BY and no UNION (you are OK with UNION ALL)
define sorting for your objects
Follow up about methods in ORACLE Types
Your oracle type could have additional methods, some of them are special, notice 'ORDER MEMBER FUNCTION' below (copy from the link):
<!-- language: pl/sql -->
CREATE OR REPLACE TYPE location_typ AS OBJECT (
building_no NUMBER,
city VARCHAR2(40),
ORDER MEMBER FUNCTION match (l location_typ) RETURN INTEGER
);
/
CREATE OR REPLACE TYPE BODY location_typ AS
ORDER MEMBER FUNCTION match (l location_typ) RETURN INTEGER IS
BEGIN
IF building_no < l.building_no THEN
RETURN -1; -- any negative number will do
ELSIF building_no > l.building_no THEN
RETURN 1; -- any positive number will do
ELSE
RETURN 0;
END IF;
END;
END;/
Its not a problem of fetch its kind of datatype mismatch. Opening cursors and fetching is correct what you have written.

Resources