I want to write an XQUERY call in Oracle SQL Developer but I keep getting an error.
I have created a schema and table:
ALTER SYSTEM SET deferred_segment_creation=false;
CREATE USER bookdb IDENTIFIED BY abc123;
GRANT RESOURCE TO bookdb;
GRANT UNLIMITED TABLESPACE TO bookdb;
ALTER SESSION SET CURRENT_SCHEMA=bookdb;
CREATE SEQUENCE book_id_seq START WITH 1 INCREMENT BY 1;
CREATE TABLE book (
id INTEGER NOT NULL PRIMARY KEY,
title VARCHAR2(50) NOT NULL UNIQUE,
originallanguage VARCHAR2(20) NOT NULL,
genre VARCHAR2(20)
);
Here is an example of a row in the table:
INSERT INTO book VALUES (book_id_seq.nextval,'Misty Nights','English','Thriller');
The table is found under "Other Users" in the SQL Developer object navigator.
If I just write SELECT * FROM BOOKDB.BOOK
it works. But using the XQUERY command and ora:view
function is not working for me.
The XQUERY command I want run is:
XQUERY
element Result {
for $lang in distinct-values(ora:view("BOOKDB.BOOK")//ORIGINALLANGUAGE/text())
let $sum := for $book in ora:view("BOOKDB.BOOK")//ORIGINALLANGUAGE
return $book[text() = $lang]
return element Language {attribute name {$lang}, attribute Total {count($sum)}}}
But I get the following error:
Error at Command Line : 1 Column : 9
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Is there something wrong with my query? Or is it the ora:view
function?