Query a stored procedure
Hi
I am using oracle 10g R2 and i am wondering if there is any way which i can query a stored procedure.
lets say have this table
EMP
1
2
3
and i want from a stored procedure to return all this values
like
select * from stored_proc;
is this possible in any way?
thx
Doron
the idea behind all this mess is because we have a hierarchic query which gets parameters to query by.
i thought of creating a view but then i colud not pass the parameters to it.
if no solution will be found i will have to change the code but we prefer to try and find this kind of solution
Doron
Similar Messages
-
Failed to retrieve all the results. Try running the query or stored procedure again
I have a Product table in Azure SQL Database. I can't open data in Product table. I got an error message like this.."Failed to retrieve all the results. Try running the query or stored procedure again". In my Database
all tables showing their data expect Product table. Please let me know why only Product table showing error message. Thanks in Advance.Hi,
I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience
As this requires an expert advice, I suggest you to open a support case and our experts would be able to assist you further.
http://support2.microsoft.com/common/international.aspx?RDPATH=%2fdefault.aspx%3fid%3dfh%253ben-us%253bofferprophone
Girish Prajwal -
Query in Stored Procedure accessing another schema
Hi - this is going to sound kind of strange and even i can't come up with an explanation. My JDK 1.1.7 applet uses a type 4 JDBC thin driver (i think v 8.04.06) to access an Oracle 7.3.4 database. We also have a link with full grants and synonymns to another Oracle schema in an Oracle 8 database. Has never been a problem - we can access anything we need to through queries or stored procedures from either of these databases.
So, i have a new stored procedure that needs to be called through JDBC that queries a table in the Oracle 8 database. For some reason, whenever i execute this stored procedure from java it hangs on this query and the instance needs to be restarted. If i execute that same stored procedure from SQL Plus, it runs fine.
I tried a little test. I put a straight query in my java code that goes directly to that table (no stored procedure involved). It runs great through java!
is this weird or what? my dbas have checked out all privelages and it seems that i have access to everything i could possibly need.
If anyone has any suggestions i would love to hear them.
thanks for your help...
Lori - [email protected]
nullYou can only access an object in another user's schema if you either:
(a) Specify the 'other' schema name explicitly: SCHEMA.OBJECT
(b) A synonymn has been created to access the object: CREATE SYNONYM OBJECT FOR SCHEMA.OBJECT.
The user requiring the synonym should create it, or the user owning the object can create a PUBLIC synonym, if they have the authority.
To check my hypothesis, try typing 'DESCRIBE procedure_name' from SQL*Plus as both users. -
Index in Query inside Stored procedure
How to put a index on Select query inside a stored procedure.Please help me on below to write a index
Coalesce ((select sum (ICD.mAmount)
from ItemCommonData ICD (Index(PK_ItemCommonData))
Join ItemsInBundle IIBun on
(ICD.iBundleDocId = IIBun.iBundleDocId) and
(ICD.iDocId = IIBun.iDocId)
Join ItemsInBlock IIB (Index(ItemsInBlockbyBlockDoc)) on
(ICD.iDocId = IIB.iDocId)
where (Bundles.iDocId = ICD.iBundleDocId
and IIBun.fDeleted = False
and IIB.iBlockId = iBlockId)),Are you migrating to Oracle SQL and PL/SQL?
Anyway, you don't define an Index on the fly in Oracle. You create them ahead of time on the table. You can use hints to manipulate the query into using a certain execution path. -
I have a stored procedure that dynamically creates a pivot query. The procedure works and returns the correct data. Now I have a requirement to show this data in reporting system that can only pull from a table or view. Since you can not
create a dynamic query in a view I tried to do a select from using openquery.
Example 'Select * from OpenQuery([MyServername], 'Exec Instance.Schema.StoredProcedure')
I get the error back "the linked server indicates the object has no columns". I assume this is because of the first select statement that is stuffing the variable with column names.
CODE FROM PROCEDURE
Alter PROCEDURE [dbo].[Procedure1]
AS
BEGIN
SET NOCOUNT ON
Declare @cols nvarchar(2000),
@Tcols nvarchar(2000),
@Sql nvarchar (max)
select @cols = stuff ((
Select distinct '], ['+ModelName + ' ' + CombustorName
from CombustorFuel cf
join Model m on cf.modelid = m.modelid
join Combustors cb on cf.CombustorID = cb.CombustorID
where cf.CombustorID > 0
for XML Path('')
),1,2,'')+']'
Set @Tcols = replace(@Cols, ']', '] int')
--Print @Tcols
--Print @Cols
Set @Sql = 'Select GasLiquid, FuelType, '+ @Cols +'
from
Select GasLiquid, FuelType, ModelName+ '' '' +CombustorName ModelCombustor, CombFuelStatus+''- ''+CombFuelNote CombFuelStatusNote
from Frames f
join Family fa on f.Frameid = fa.frameid
join Model m on fa.FamilyID = m.FamilyID
join CombustorFuel cf on m.Modelid = cf.modelid
Join Combustors c on cf.CombustorId = c.CombustorID
join FuelTypes ft on cf.FuelTypeID = ft.FuelTypeID
where cf.CombustorFuelID > 0
and CombustorName <> ''''
) up
Pivot
(max(CombFuelStatusNote) for ModelCombustor in ('+ @Cols +')) as pvt
order by FuelType'
exec (@Sql)Then again, a good reporting tool should be able to do dynamic pivot on its own, because dynamic pivoting is a presentation feature.
SSRS Supports dynamic columns: Displaying Dynamic Columns in SSRS Report
SQL Reporting Services with Dynamic Column Reports
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
Displaying and reading are two very different things.
#1) SSRS Needs a fixed field list on the input side to know what what to make available in the designer.
#2) SSRS cant read "exec (@Sql)" out of a proc, even if there is a fixed number of columns (at
least it can't use it to auto build the field list from the proc)
I use dynamic SQL in my report procs on a fairly regular basis and I've found it easiest to simply dump
the results of my dynamic sql into a temp table at the end of the procs and then select from the temp table.
Basically, Erland is correct. Stop trying to pivot in the query and let SSRS (or whatever reporting software you're using) handle it with a Martix.
Jason Long -
Cursor with nested query in stored procedure problem
Hello
I'm trying to declare the folowing (example) cursor in a stored procedure in Oracle 8i:
CURSOR RECORDS IS SELECT d.DUMMY, (SELECT dd.DUMMY FROM dual dd) FROM dual d;
The nested part "(SELECT d.DUMMY FROM dual)" is not alowed, while the same query runs outside the stored procedure. Can someone explain why this is not alowed and how to solve the problem whitout rewriting the query?
TomWhen i run the same code in SQL plus:
SQL> declare
2 CURSOR RECORDS IS SELECT d.DUMMY, (SELECT dd.DUMMY FROM dual dd) FROM dual d;
3 begin
4 null;
5 end;
6 /
CURSOR RECORDS IS SELECT d.DUMMY, (SELECT dd.DUMMY FROM dual dd) FROM dual d;
FOUT in regel 2:
.ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string>
ORA-06550: line 2, column 66:
PLS-00103: Encountered the symbol "FROM" when expecting one of the following:
; return returning and or
Different versions of Oracle? -
Can we query a stored procedure results as an SQL Table ?
Hi,
Can we query a results from the results of a stored procedure returning a result set either as cursors or as PL/SQL Table like what we do like this
select * from <tablename>
select * from (select * from tablename) alias. instead of this, can we do like this
select * from (results of stored procedure) alias.
Please Provide any Help.I agree. Pipelined Table Functions are the way to go.
Docs at http://tahiti.oracle.com
Working demos in Morgan's Library at www.psoug.org under Pipelined Table Functions. -
Query on Stored Procedure for UDF's
Hi guys,
I have created 3 UDF's T0.[U_LR_Receipt], T0.[U_Removal_Time], T0.[U_Removal_Date]
at header level for the marketing documents.I want the invoice to be added only if the above fileds is entered or else it has to show the error message.
to acheive this i have created a stored procedure in SBO_SP_TransactionNotification for U_LR_Receipt.
But i want to know whether we can add two more procedures in the same or else i need a single query for the 3 fields.
Below is the code i used ,
if @object_type = '13' and @transaction_type IN ('A','U')
begin
declare @LRRECEIPT NVARCHAR(10)
set @LRRECEIPT = (select isnull(T0.U_LR_Receipt,0) from OINV T0 where T0.DocEntry = @list_of_cols_val_tab_del)
If (@LRRECEIPT = 0)
begin
select @error = 1
select @error_message = 'You cannot post the INVOICE without LR Receipt No'
End
End
Thanks in advance,
Regards,
Vamsi.Hi Vamsi,
Give this a go.
Kind Regards,
Adrian
if @object_type = '13' and (@transaction_type= 'A' or @transaction_type= 'U')
begin
if (select count(1) from OINV where DocEntry = @list_of_cols_val_tab_del and (U_LR_Receipt IS NULL or U_Removal_Time IS NULL or U_Removal_Date IS NULL)) > 0
begin
select @error = 1
select @error_message = N'You cannot post the Invoice without the LR Receipt No, Removal Time or Removal Date'
end
end -
SELECT QUERY USING STORED PROCEDURE
Hi,
I am using stored procedure in package, i need to execute select statement using
stored procedure.
regards,
p.kumaran? not framed properly i think so if u dnt mind plz check it out once
if u wnt to invoke a proc from package 2 ways r there
1) execute pac_name.proc_name[(arg_list)];
2) pl/sql
[declare]
begin
pac_name.proc_name[(arg_list)];
end;
/ -
Hi ,
I am using EXECUTE IMMEDIATE to execute a DDL Statement inside a Stored Procedure .
But i am unable to see this table , please tell me why .
create or replace procedure NAmes
is
begin
EXECUTE IMMEDIATE 'CREATE TABLE execute_table (col1 VARCHAR(10))';
commit;
end;
Procedure created.Hi,
user10503747 wrote:
I am using EXECUTE IMMEDIATE to execute a DDL Statement inside a Stored Procedure .Why? Performing DDL in strored procedures is usually not the best way to do things in Oracle.
Whenever you have a problem, post a compete test script that people can use to re-create the problem and test their ideas. The CREATE TABLE statement that you posted was a good start; add code to show how you ran it, and what you did to see if it worked or not.
For example:
create or replace procedure NAmes
is
begin
EXECUTE IMMEDIATE 'CREATE TABLE execute_table (col1 VARCHAR(10))';
commit; -- Not needed. DDL automatically causes COMMIT
end;
SHOW ERRORS
PROMPT ===== Before Running Names Procedure =====
DESCRIBE execute_table
EXEC names;
PROMPT ===== After Running Names Procedure =====
DESCRIBE execute_tableThis worked fine for me in Oracle 10.2.0.1.0 and SQL*Plus 10.2. Output:
Procedure created.
No errors.
===== Before Running Names Procedure =====
ERROR:
ORA-04043: object execute_table does not exist
PL/SQL procedure successfully completed.
===== After Running Names Procedure =====
Name Null? Type
COL1 VARCHAR2(10)What are you doing different?
Did you get any error messages?
Are you creating the procedure in one schema, and running it in another?
Did you call the names procedure from another procedure?
Don't make people guess. Guessing is not the best way to solve problems. -
Query regarding stored procedure ?
hi
i am writing a stored procedure in which i have to pass a date and i have to get the data from the table from 1-jan2007 to the passed date. there are 64 different currencies in the table and i have to get the avg of px_last of each currencies.
every currency have suppose different values of px_last on different dates
i have written a code but it is calculating avg of px_last not for particular currencies.
here is the code
create or replace
PROCEDURE PP
(DATAPROVIDER IN VARCHAR
, T_DATE IN DATE
, RESULT OUT VARCHAR
, MESSAGE OUT VARCHAR
) AS
PX_LAST NUMBER(15,4);
MTD_START_DATE DATE;
YTD_START_DATE DATE;
MTD_AVG NUMBER(15,4);
YTD_AVG NUMBER(15,4);
INV_PX_LAST NUMBER(15,4);
INV_MTD_AVG NUMBER(15,4);
INV_YTD_AVG NUMBER(15,4);
CURSOR C1 IS
SELECT A.FROM_CURRENCY, A.TO_CURRENCY,A.FX_DATE,A.PX_LAST,A.FX_TIME FROM CURRENCY_EXCHANGE_TXN A,
(SELECT FROM_CURRENCY, TO_CURRENCY, FX_DATE, MAX(FX_TIME) TIM FROM
CURRENCY_EXCHANGE_TXN WHERE FX_DATE BETWEEN '01-JAN-'||TO_CHAR(T_DATE,'YYYY') AND T_DATE
AND SOURCE = DATAPROVIDER GROUP BY FROM_CURRENCY, TO_CURRENCY,FX_DATE) NEW_TAB
WHERE A.FROM_CURRENCY = NEW_TAB.FROM_CURRENCY AND A.TO_CURRENCY = NEW_TAB.TO_CURRENCY AND
A.FX_DATE = NEW_TAB.FX_DATE AND A.FX_TIME = NEW_TAB.TIM;
TYPE CUR_TYPE IS REF CURSOR;
C_CURSOR CUR_TYPE;
V_QUERY VARCHAR2(1000);
V_MTD_AVG NUMBER(15,4);
V_YTD_AVG NUMBER(15,4);
V_FX_DATE DATE;
V_CURRENCY_CODE VARCHAR2(10);
M_AVG NUMBER(15,4);
Y_AVG NUMBER(15,4);
BEGIN
-- If the data exist in the target table, clear it first.
DELETE FROM TABLE1 WHERE FX_DATE BETWEEN '01-JAN-'||TO_CHAR(T_DATE,'YYYY') AND T_DATE;
-- arrange the currency exchange in terms of USD ( take inverse if the exchange is other way)
MTD_START_DATE :='01-'||TO_CHAR(T_DATE,'MON-YYYY');
YTD_START_DATE :='01-JAN-'||TO_CHAR(T_DATE,'YYYY');
DBMS_OUTPUT.PUT_LINE('MTD DATE -----> ' || MTD_START_DATE);
DBMS_OUTPUT.PUT_LINE('YTD DATE -------> ' || YTD_START_DATE);
FOR I IN C1
LOOP
SELECT ROUND(AVG(PX_LAST),4) INTO MTD_AVG FROM
CURRENCY_EXCHANGE_TXN WHERE FX_DATE BETWEEN
MTD_START_DATE AND T_DATE;
--DBMS_OUTPUT.PUT_LINE('MTD_AVG ===== ' || MTD_AVG);
SELECT ROUND(AVG(PX_LAST),4) INTO YTD_AVG FROM
CURRENCY_EXCHANGE_TXN WHERE FX_DATE BETWEEN
YTD_START_DATE AND T_DATE;
DBMS_OUTPUT.PUT_LINE('PX_LAST > '||I.PX_LAST);
INV_PX_LAST:=1/I.PX_LAST;
DBMS_OUTPUT.PUT_LINE('INV_PX_LAST > '||INV_PX_LAST);
INV_MTD_AVG:=1/MTD_AVG;
INV_YTD_AVG:=1/YTD_AVG;
INSERT INTO TABLE1(CURRENCY_CODE,PX_LAST,MTD_AVG,YTD_AVG,FX_DATE,INV_PX_LAST,INV_MTD_AVG,INV_YTD_AVG) VALUES
(I.TO_CURRENCY,I.PX_LAST,MTD_AVG,YTD_AVG,I.FX_DATE,INV_PX_LAST,INV_MTD_AVG,INV_YTD_AVG);
COMMIT;
END LOOP;
RESULT := 'SUCCESS';
MESSAGE := '';
END PP;
/* SAMPLE CODE TO RUN THE PROCEDURE
DECLARE
RESULT VARCHAR2(300);
MESSAGE VARCHAR2(300);
begin
PP('BLOOMBERG' ,'15-MAY-07',RESULT , MESSAGE );
DBMS_OUTPUT.PUT_LINE('RESULT-----'||RESULT);
DBMS_OUTPUT.PUT_LINE('MESSAGE-----'||MESSAGE);
end;
*/plz help
Message was edited by:
user578145this is the format of table
FROM_CURRENCY VARCHAR2(5 BYTE)
TO_CURRENCY VARCHAR2(5 BYTE)
ASK_RATE NUMBER(15,4)
BID_RATE NUMBER(15,4)
SOURCE VARCHAR2(25 BYTE)
FX_TIME VARCHAR2(2 BYTE)
FX_DATE DATE suppose i have a data like this
FROM CURRENCY TOCURRENCY FXDATE FXTIME PXLAST MTD YTD
USD GBP 5-Jun 10 1 AVG(2+3) avg(2+3+8+9)
USD GBP 6-Jun 17 2 AVG(2+3) avg(2+3+8+9)
USD GBP 9-Jun 17 3 AVG(2+3) avg(2+3+8+9)
USD GBP 2-Jan 10 8 AVG(2+3) avg(2+3+8+9)
USD GBP 3-Jan 17 9 AVG(2+3) avg(2+3+8+9)
USD GBP 3-Mar 10 10 AVG(2+3) avg(2+3+8+9)
USD AWD 2-Feb 17 5 AVG(6+7)
USD AWD 2-Jun 10 6 AVG(6+7)
USD AWD 7-Jun 17 7 AVG(6+7)
suppose I pass 11-jun-2007 then for mtd for a particular tocuurency like gbp mtd will be from 1jun to 11jun avg of px_last which has fx_time max
here for gbp max xtime is 17 and mtd is avgof pxlast of 6 and 9 because they have max time
and ytd is 1jan to 11 jun avg of pxlast of 6 9 2 3 because they have max time -
Problem in framing a query in stored procedure
I have problem in framing a query string.
This query contains a link (ie hyperlink). In this i have to add single quotes and double quotes in the middle. I dont know how to frame this query. I am sending this query. I am getting an error message "missing double quotes in the expression". So kindly frame this query.
Thanks in advance.
Here is my query
sql_Query := 'SELECT DISTINCT(topic_name) TOPIC,course_title TITLE,'||'''''||course_description||'||
'''''"Description",'||'''COURSE''"ModuleName"'||
' FROM V_COURSE '||' WHERE COURSE_ID IN('||'''NOTHING'''||')';Don't try to write a query like this in one time. Do it step by step (adding the next string every time), print the result with dbms_output.put_line, and see at which point the error occurs.
-
Need Help in with Querying Stored Procedures from UCCX Database
Hi All
We are trying to build a custom reporting solution using a BI tool and for which we have provided the ODBC connectivity to the UCCX database to our SQL server.
We have installed the ODBC drivers on our SQL server and made a connection to UCCX version 10.0 successfully. we are using the username 'uccxhruser' to connect to the DSN.
We want to query the stored procedure sp_csq_activity from the Microsoft SQL Server Management Studio. When we add the Linked Server in the SQL Server, we are able to see the Data Tables and also query them using the select statement. However, we are not able to see any of the Stored procedures within the Linked Server Tab.
Can someone guide us in the right direction as to how to go about the process. Is calling the stored proedure the right way or we need to query the individual tables as mentioned in the Database Schema Guide and then once the historical tables our there in our server , then build the report.
Any help will be much appreciated.
Regards
AbhinavHi,
what happens if you try to execute the above SP? They should be accessible AFAIK.
G. -
SSRS - Stored procedure with Dynamic SQL Query
Am calling stored procedure in SSRS report. I have used Dynamic SQL query in stored procedure as I don't know the column name and column count. And I have used like below at end of the stored procedure "select * from ##temptable".
As I have used dynamic column, am not able to create report with this stored procedure. Can someone help me out to resolve this issue.
It will be highly appreciated if I get help.
ThanksI have tried everything. But nothing has worked out.
If I get solution for below issue, it would be highly appreciated.
"An error occurred during local report processing.
The definition of the repport 'Main Report' is invalid.
The report defintion is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition' which cannot be upgraded.
Thanks
Hello,
I would suggest you post the complete error message to us for further investigation, if you preview the report before you deploy you may get a more detailed error that will help diagnose the source of the problem.
This issue is more related to SQL Server Reporting Services, it's more appropriate to discuss it in the forum below:
https://social.technet.microsoft.com/Forums/sqlserver/en-US/home?forum=sqlreportingservices
Don't forget to elaborate your issue with more detail.
For the manual column, it might be the calculated field in SSRS. Here is the article for your reference, please see:
http://technet.microsoft.com/en-us/library/dd239322(v=sql.110).aspx
Regards,
Elvis Long
TechNet Community Support -
FOR XML will not run in stored procedure but will in Query
The following is the Query and stored procedure for a XML export. The query runs find and returns a clickable link. The stored procedure does not.
Stored Procedure
USE [db]
declare @XmlOutput1 xml
set @XmlOutput1 =
(SELECT incident_num,
unit_id, unit_status_datetime,
unit_status_remarks
FROM unit_status_hist
where convert(varchar,unit_status_datetime,102)
=
convert(varchar,getdate(),102)
FOR XML
RAW)
select @XmlOutput1
Query:
use db
SELECT incident_num, unit_id,
unit_status_datetime, unit_status_remarks
FROM unit_status_hist
WHERE convert(varchar,unit_status_datetime,102)
=
convert(varchar,getdate(),102)
for XML
auto, Elements
Any help would be greatly appreciated. Thank you.The following is the Query and stored procedure for a XML export. The query runs find and returns a clickable link. The stored procedure does not.
Stored Procedure
USE [db]
declare @XmlOutput1 xml
set @XmlOutput1 =
(SELECT incident_num,
unit_id, unit_status_datetime,
unit_status_remarks
FROM unit_status_hist
where convert(varchar,unit_status_datetime,102)
=
convert(varchar,getdate(),102)
FOR XML
RAW)
select @XmlOutput1
Query:
use db
SELECT incident_num, unit_id,
unit_status_datetime, unit_status_remarks
FROM unit_status_hist
WHERE convert(varchar,unit_status_datetime,102)
=
convert(varchar,getdate(),102)
for XML
auto, Elements
Any help would be greatly appreciated. Thank you.
I cant see any stored procedure here
both of the code posted are queries only
also clickable link will come in only SSMS query window. Are you trying to execute this from some application?
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Maybe you are looking for
-
I'm not sure if this a Leopard, iPod Touch, or iTunes issue. Problem seems to occur after I've synced the touch and later restarted iTunes (say, after a software update). Haven't noticed the problem with my wife's 5G ipod. I get the following message
-
Not able to attach final signed document in the contract document
Dear Experts, The upload field for final signed document in the contract document is visible only for the latest/last contract document if there are more than one contract document exist in the Master Agreement. For the previous contract documents, n
-
Webutil invoke.string problem with c++
hi , am using forms 10g and trying to call a dll in c++ it works when i call the dll using webutil to return an integer from the dll by sending 2 parameters of type varchar2 to invoke the function returning integer rc1 := WEBUTIL_C_API.Invoke_int('ca
-
Prime Infrastructure 2.0: Inventory/detailed HW reports customizing
Hello, isn't it possible to run a/one detailed hardware report that includes the chassis information Name, the device name, the chassis serial number? Example: Chassis Information Name Device Hostname Serial Number WS-C3750V2-24PS-S switch1x2 FX31338
-
HT1657 How long do I have to wait before I can rent a movie
How long do I have to wait