Select From Oracle Function
I have a function that return an oracle table of object type.
When I run the function it runs successfully but I need to output its data and so for that I use the code select * from table(my_func_name); however this is coming through with an error that says table or view does not exists.
So I would like to get assistance as to why could this be happening
select * from table(my_func_name);
I want to get results as a table.
Related
I am attempting what I thought was a very simple view. It contains one table, and just does an "ORDER BY" so I can sort the output.
I created the view on DB2 LUW using IBM Data Studio. I used the following statement:
FROM TCIS.JRGS
ORDER BY JRGSORT ASC, JRGNAME ASC;
When I attempt to execute this, I get the following error:
The specification ORDER BY, OFFSET, or FETCH clause is invalid.. SQLCODE=-20211, SQLSTATE=428FJ, DRIVER=3.69.56
Is anyone with DB2 experience able to tell me what I'm doing wrong? How do I order a view?
CREATE VIEW uses fullselect.
The SQLSTATE you get is described at the latter link. Read it carefully.
Despite the fact, that you can create a view like below, it doesn't guarantee the order of rows, if you use this view without the order by clause.
CREATE VIEW MYVIEW AS
SELECT *
FROM
(
SELECT *
FROM TCIS.JRGS
ORDER BY JRGSORT ASC, JRGNAME ASC
);
I am looking at an already existing code base which connects to an Oracle database. It contains the query that looks like select some_name(?) from dual. What is some_name here? Is it a stored procedure? How can I view the source code for that function?
if you have SQLDeveloper, you can view the source code of SOME_NAME function in the function section, or TOAD, you can find it in the Schema Browser,
or you can query it using below select statement,
SELECT *
FROM all_source
WHERE name = 'SOME_NAME'
ORDER BY line;
Created table and loaded data from txt file to this table. select * from tablename displays all record however when i run select statement with condition, query runs successfully (no error prompts by hive) however no results are displayed. Table exists in the folder.
I ran the below two queries-
select * from plan1 where contid = "%H0001%";
select * from plan1 where contid = "H0001";
any thoughts? TIA
Our database has a package that returns a type t_daily_array_table.
This type is defined as:
TYPE t_daily_array_table IS TABLE OF r_daily_array_rec
and r_daily_array_rec is defined as a record with a number of fields.
We have a package called schedule_pkg with the function f_daily_array_table which returns the t_daily_array_table. The function takes a single Number parameter.
I've tried calling it a number of ways, but I can't seem to get it to work (I know this function works. It's called from an COBOL app that functions just fine).
I've tried:
select schedule_pkg.f_daily_array_table(74501) from dual;
When I do that, I get
SQL Error: ORA-00902: invalid datatype
I've tried:
select * from schedule_pkg.f_daily_array_table(74501)
That gives me:
SQL Error: ORA-00933: SQL command not properly ended
I've tried using code (C#) and calling in various ways using OleDb, OracleClient, and ODBC and I have yet to find a way I can call this, other than using COBOL.
If you want to query the values from an SQL context but have a PL/SQL collection type, you can create a pipelined wrapper function, either within the package or as a standalone object for testing/debuggging. Something like this should work:
create function f_daily_array_pipe(p_id IN number)
return schedule_pkg.t_daily_array_table pipelined is
l_daily_array_table schedule_pkg.t_daily_array_table;
begin
l_daily_array_table := schedule_pkg.f_daily_array_table(p_id);
for i in 1..l_daily_array_table.count loop
pipe row (l_daily_array_table(i));
end loop;
end f_daily_array_pipe;
/
select * from table(f_daily_array_pipe(74501));
This calls your original function, assigns the result to a local collection, iterates over it, and pipes each record in turn back to the caller; which uses the SQL table() collection expression to convert it to something you can query from.
SQL Fiddle demo.
If you are using an OCI or JDBC client you can use an array descriptor and retrieve the data as an array, but that won't work from plain SQL.
I think the syntax you're looking for is:
select * from table(schedule_pkg.f_daily_array_table(74501));
I am getting error while doing a simple select * from a view. created a view successfully but getting this error on select :
non-aggregate values must be part of the associated group
I tried to insert the result set in table and it was successful and even select worked for that table.
For same set of select statements the view creation was successful and the select failed(select * from viewname)
What is the reason for this?