For cursor joining tables - oracle

could you help me out, can't figure out this one, I get the following error message:
ORA-06550: line 4, column 32:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 3, column 8:
PL/SQL: SQL Statement ignored
ORA-06550: line 11, column 32:
PLS-00364: loop index variable 'V_CUR_SPOKENLANG' use is invalid
ORA-06550: line 11, column 11:
PL/SQL: Statement ignored
Tried to find solution in Oracle Forum and
http://www.techonthenet.com/oracle/errors/ora00942.php
Also tried to do it by this example:
http://www.w3schools.com/sql/sql_join_inner.asp
But got basically the same results.
I have access to both these tables with SELECT.
The code I'm having problems with:
DECLARE
CURSOR cur_spokenlang IS
SELECT country_id, country_name, language_id
FROM wf_countries c, wf_spoken_langugages sl
WHERE c.country_id = sl.country_id;
BEGIN
FOR v_cur_spokenlang IN cur_spokenlang
LOOP
DBMS_OUTPUT.PUT_LINE(v_cur_spokenlang.country_name || ' ' ||
v_cur_spokenlang.country_id || ' ' ||
v_cur_spokenlang.language_id);
END LOOP;
END;
Thank you in advance :)

Either of the tables you mentioned is INVALID (May be invalid schema you run or no PUBLIC SYNONYM).
Also noticing that the country_id is left ambiguous . Needs to be c.country_id.
Please make sure, you have the privileges to the user directly and not via any ROLES. Because, to be access via a PL/SQL the user id needs to have direct SELECT privileges over the tables.!

If you are on windows Use SQLTools IDE. http://www.sqltools.net/
Whenever there is an error.The Cursor directly jump to the point where
the error is.

Related

I'm trying to write a PL/SQL Procedure that cancels a reservation. I keep getting an identifier error on a column name

create or replace procedure Cancel_Reservation(resid in number)
as
Begin
Update Reservation
set Res_cancel = 'yes'
where resid = reserve_id;
end;
Here is a picture of the table I'm working with
My goal is to cancel a reservation by inputting a reserve_id and changing res_cancel to 'yes' from 'no'. My plan is to not delete the reservation.
Here are the errors:
Error(3,1): PL/SQL: SQL Statement ignored
Error(4,5): PL/SQL: ORA-00904: "RES_CANCEL": invalid identifier
Whoever created a table using columns with mixed case ... well, didn't think twice. In Oracle, never do that; causes nothing but problems. I suggest you rename the column with
alter table reservation rename column "Res_cancel" to res_cancel;
Because, as it is, you must reference that table using double quotes and exactly match letter case. So:
Update Reservation
set "Res_cancel" = 'yes' --> this

oracle sql: collect aggregation

I want to group my database entries by an attribute and to know which entries are in each group at the same time. I collect the ids of the grouped entries with Oracle COLLECT function COLLECT Function
DECLARE
TYPE ids_type IS TABLE OF number(19, 0);
ids ids_type;
BEGIN
select cast(collect(r.id) as ids_type) into ids from rechnungsdaten r group by r.status;
END;
But then I get the error:
Error report - ORA-06550: Line 5, Column 44: PL/SQL:
ORA-00902: Invalid datatype ORA-06550: Line 5, Column 5:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What is wrong here?
You cannot use COLLECT function on a type declared in a PL/SQL anonymous block.
You have other options like
Create a database type and run your collect query.
create or replace TYPE ids_type IS TABLE OF number(19, 0);
SELECT
r.status,
CAST(COLLECT(r.id) AS ids_type)
FROM
rechnungsdaten r
GROUP BY
r.status;
Use a simple LISTAGG query to see the list of ids as a string
SELECT
r.status,
LISTAGG(r.id,',') WITHIN GROUP(
ORDER BY
id
)
FROM
rechnungsdaten r
GROUP BY
r.status;
Demo

ORA-06550 using a nested table type

I'm trying to create some output based on select items from APEX.
The case is as follows:
In APEX you select certain items.
APEX makes a nested table of those primary keys and call the function to create the output.
The function generates the output and returns it.
I already found out that I can't use locally defined nested tables in the where clause, but I am now stuck on the following:
My stored type:
CREATE OR REPLACE EDITIONABLE TYPE "T_NUMBERS" as table of NUMBER(10,0)
The part of the function that gives the ORA-06550 error:
DECLARE
c_asked T_NUMBERS;
BEGIN
c_asked := T_NUMBERS(21);
This is just a simple example of what is going wrong.
The error itself:
ORA-06550: line 9, column 23:
PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got <schema_name>.T_NUMBERS

SELECT a table from oracle data dictionary

I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.

pl/sql nested table assignment issue in APEX

All,
I've been fighting this issue for a little while, now, and it seems like there's something simple I'm missing, but I haven't been able to figure it out.
I'm trying to use a pl/sql nested table in APEX to collate and return data from disparate tables to a page view.
As a test, I created a nested table object and type:
CREATE OR REPLACE TYPE "E_TEST" as object (
col1 varchar2(8),
col2 varchar2(16)
)
/
CREATE OR REPLACE TYPE "E_TEST_TAB" as table of e_test
/
When I attempt to populate the nested table with this code:
declare
l_test e_test_tab := e_test_tab();
begin
l_test.extend;
l_test(l_test.last) := e_test_tab('testing','testing12345');
end
I get these errors:
ORA-06550: line 5, column 24:
PLS-00306: wrong number or types of arguments in call to 'E_TEST_TAB'
ORA-06550: line 5, column 24:
PLS-00306: wrong number or types of arguments in call to 'E_TEST_TAB'
ORA-06550: line 5, column 1:
PL/SQL: Statement ignored
I've been searching for an answer for a couple of days, but everything I can see says I'm creating and populating the object correctly, and searches related to the PLS-00306 error don't return much specific to the nested table context. I'm new to pl/sql, so there's a high probability that I've missed something simple, but the folks I know who might be able to help me don't use a lot of collections, so they're stumped by this one, as well.
Thanks in advance for your assistance.
Justin
declare
l_test e_test_tab := e_test_tab();
begin
l_test.extend;
l_test(l_test.last) := e_test('testing','testing12345');
end;
/
It has to be e_test() while assignment of individual record.
Only while initializing the nested collection we use e_test_tab()

Resources