executing query inside column in a table - sql

I have a table A with columns 1.Column 1 contains a query select * from tableD;
I need to execute the query inside column1 using single query if possible..How to do this..
Database is netezza.If u provide ans for oracle Db also fine.

This seems Dynamic query problem for me ..
In Oracle you can create a procedure to call this query which is actually stored in a table.
In my knowledge you can not directly run query stored as text.
You need to create a procedure or function where you can call this query as dynamically with execute immediate command.

Related

How to save all the output in snowflake procedure?

I have written a procedure wherein a variable has a select statement which is creating multiple update statements..
If I execute the variable it will give the query from select statement and if I execute the variable which has all the update statement list will it update everything as required??
I also want to know how can I save all each update query's row count as there are more than 300 updates statements

I have a db2 stored procedure returning 2 values, how do i use this procedure in a select statement?

I have a DB2 stored procedure (my_proc) that returns two values. I want these two values to be displayed as two different columns.
Is the following correct way to use it?
select my_proc(parameter1,parameter2,parameter3) as column1,column2;
Please guide as I am learning DB2 and new to stored procedure.
Consider if it is possible or not for you to convert your stored procedure to a UDTF (user defined table function). This can be selected from and joined to and works very similar to a stored procedure.
https://www.itjungle.com/2016/06/14/fhg061416-story03/

How to re-use a SQL query in a PL/SQL procedure?

I am writing a PL/SQL procedure. In the body of this procedure, how can I use twice the same query without re-writing it ?
To simplify, let's say that I have this SQL query :
SELECT *
FROM mytable
WHERE age > 18
Is there a way to "store it", so I could do for example :
SELECT COUNT(*) INTO var1
FROM myQuery
I know the WITH ... AS keywords, but as I know it can be only used in the current statement, and I want to be able to call it from different statements.
Thanks !
There are various possibilities. Here are the ones I think of immediately, there are probably others:
Declare an explicit CURSOR using your query, and use that cursor multiple times in the body of your procedure.
Store the query in a string variable, and use EXECUTE IMMEDIATE to run it multiple times
Execute the query once, storing the results in a local collection (nested table, most likely), and process those stored results multiple times
Create a function that executes the query and returns its results as a nested-table type. Then SELECT FROM TABLE( my_function ) multiple times

Selecting from the result set of a DB2 stored procedure

I have a stored procedure which returns multiple records (the SP cannot be changed, I need to work with what I have). I'd like to do a DB2 select statement from Shell script that selects one record based on a combination of column data like the following:
select a.description_column from (call my_stored_proc) a where a.name_column='name_filter' and a.value_column='value_filter';
The columns description_column, name_column and value_column exist in the result set of the SP. I get a SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2 error. As I need to sort it out from a Shell script and I only have read access to the DB, I can't create additional tables for this.
You can't select from SP.
But you can from a Table-Function.
SELECT ... FROM TABLE(<table-function(param1, param2, ..., paramN))) as t WHERE ....
So, easiest way is to ask the DBA to create a table-function based in the source SP.
Good luck

View parameterized queries ran on oracle

I would like to view parameterized update, select, and delete statements executed on an oracle database.
I can see the query by running the following:
select * from v$sqlarea where parsing_schema_name = 'SCHEMA_NAME' order by last_active_time desc
But I want to also view the parameters that go with the SQL in the SQL_TEXT column. Is there a way to do this?
If by parameterized you mean bind variables, you need V$SQL_BIND_CAPTURE. Search it by the SQL_ID you found in V$SQLAREA.
Each row represents a variable captured by position, so you'll have to match it up with your names from your query.