Getting query results from a PL/SQL procedure
Hi! So, I’m a little stumped and I can’t seem to find the answer to what I believe is probably a simple question…
So, here goes… I have a big ol’ union query that I use to create a report on a page, it’s about 25k – not over the 32k limit, but fails to be able to compile every time (I always get a 400 – Bad Request error). I’m not sure why this is happening, but I can remove a union statement and it compiles just fine – so it has something to do with the size of the query. ANYWAY – I’ve resolved that I should put this bad boy into the database as a stored procedure and just call it from Apex, my problem is I can’t figure out quite how to do this with variables, etc.…
Instead of giving you my whole big query, I’ll use the emp table as the concept is the same:
Say we have a query that creates a report on a page:
select empno, ename, job, mgr, hiredate, sal, comm, deptno
from emp
where job = :P_JOB
and hiredate >= :P_HIREDATE;
How would I take this query, create it as a stored procedure on the db, pass the variables from Apex and return the query result set from the stored proc as a report?
I really appreciate any help on this!
Best,
Gilcrest
Hi Gilcrest,
You should create the query as a View and use the view name and the WHERE clause in the report's sql source.
Andy
Similar Messages
-
How to get query result in comma dilimited text or excel file?
Does anybody know how to get query results in comma delimited
text file or excel file, I tried spool abc.txt, but the result
showed some ------ lines
ThanksTry doing this in your sql scripts
set heading off
set pagesize 0
set linesize 4000
set feedback off
set verify off
set trimespace on
set colsep ","
spool output.txt
select * from dual (or whatever you are querying
spool off
There may be a couple other set statement that you could add but
this should get you started in the right direction -
How to send query results from BW to R/3 abap program
Hi,
I have to bring in query results from BW into a abap program written in R/3...can anyone help me on how to accomplish this(BW to R/3) please...i was thinking if reporting agent or broadcasting should help but i dont know how to get started.
Please help.
Thank you so much.Hi Vijay,
As i know, you can send data from BW to Flat file or into any table in BW or to BW application server only.
You need 3rd party to send data to different server.
You can use
1. Tcode : RSCRM_BAPI to download query values/results into a table or into a flat file. OR
2. You can use Infospokes to generate files from ODS/CUBE/master data objects to flat files(local/application server) or to a table.
3. Using information broadcasting we can send mail(dont know much options), but i dont think generation of file possible.
You need to trnasfer generated file from BW to R/3 and load into R/3 using BDC or LSMW(if data is low).
I think, you can also use RFC function modules to read data from BW to R/3, plz check with ABAPer.
Hope it Helps
Srini -
Getting XML result from Oracle request
We have Oracle 8i Entreprise Edition and We like to get XML result from an Oracle request. Can I use only Oracle 8i Entreprise Edition product or should i use another oracle product to do this job ?
Thank youDownload our XSQL Pages technology with the XSQL Servlet and you'll be in business in no time. If you want to just get XML programmatically from SQL in your own programs, you can try the XML SQL Utility (which XSQL Pages makes use of under the covers). XSQL Pages comes with lots of demos and a tutorial.
-
Basic Report Run from a PL/SQL Procedure
I am hosed trying to start a BI Publisher report from a PL/SQL procedure. Basically, I have a procedure with a local variable defined as an XMLType. I need to call an RTF source, pass the xmlfile in and tell the RTF Engine where to send the output.
The users guide implies that it involves calls to a Java program and I am totally ignorant of Java.
I have successfully linked the RTF source into the XML_Publisher application and previewed it against a known data set. hat works.
So, if I have a PL/SQL package with the local variable L_XML defined as XMLTYPE
and an output file L_OUTBUT defined as VARCHAR2(100), what do I use to call the RTF Processor and generate the report to the output file?
That is
declare
l_xml xmltype;
l_output varchar2(100);
begin
-- stuff to build the xml variable
-- insert the call to FTP Processor here Apparently, it should be
-- something like
package.procedure('linked_rtf file name', l_xml, l_output);
end;
If this calls a Java script, would also appreciate a sample copy of the script.
My need is desperate so any assistance will be greatly appreciated.
Many thanks
FrankI don't think you can. The parameters passed to a VB dll are formatted differently than a C dll, especially strings. I know a C program has to use special data structures when working with a VB dll, and this is basically what Oracle is doing.
It should be possible, however, to create a C dll that acts as a wrapper for the VB dll. I'm not sure this would save you anything, though. If you have to do that you may as well write the function in C. -
Generating an xml from a pl/sql procedure
Hi Friends,
I have come up with a requirement to generate an xml from a pl/sql procedure.
I did some R & D and also got some sample procedures but could not understand the datatypes being used.
The procedure declares variables like this:
doc xmldom.DOMDocument;
mainNode xmldom.DOMNode;
headerElem xmldom.DOMElement; Pls could anyone tell what do these xmldom.DOMDocument, xmldom.DOMNode and xmldom.DOMElement mean?
Later in the procedure, these variables are assigned values like
doc := xmldom.newDOMDocument;
mainNode := xmldom.makenode(doc); This went a bouncer on me.
Pls help.
Thanks in advance ...!You can check this one -- Learned this from michael.
satyaki>
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
satyaki>
satyaki>
satyaki>with person_h
2 as
3 (
4 select 1 id, 'M' gender, 'W' race, '170' weight from dual union all
5 select 1, 'M', 'W', '170' from dual union all
6 select 1, 'M', 'W', '180' from dual union all
7 select 1, 'M', NULL, '175' from dual union all
8 select 1, NULL, 'W', NULL from dual
9 )
10 select xmlelement("Person",(
11 select xmlagg(xmlelement("Sex", gender))
12 from (
13 select distinct gender
14 from person_h
15 where id = 1
16 and gender is not null
17 ) pg
18 ),
19 (
20 select xmlagg(xmlforest(race as "Race"))
21 from (
22 select distinct race
23 from person_h
24 where id = 1
25 ) pg
26 ),
27 (
28 select xmlagg(xmlforest(weight as "Weight"))
29 from (
30 select distinct weight
31 from person_h
32 where id = 1
33 ) pg
34 )
35 ).getstringval() Res
36 from dual;
RES
<Person><Sex>M</Sex><Race>W</Race><Weight>170</Weight><Weight>175</Weight><Weight>180</Weight></Person>
satyaki>Regards.
Satyaki De. -
How to call shell script from a pl/sql procedure
Hi all,
I am little bit new to plsql programming, i have a small problem as follows
I have to call a shell script from a pl/sql procedure ..
Please suggest me some methods in oracle 10g, which i could make use of to achieve my goal. also please tell me what are the constraints for those methods if any.
I already came across dbms_scheduler, but i have got a problem and its nor executing properly its exiting giving 255 error or saying that permission problem, but i have already given full access to my shell scripts.
Thanks in advance
Best Regards
SatyaHi,
Read this thread, perhaps is there your response :
Host...
Nicolas. -
How to make a http request from a pl/sql procedure(URGENT)
I need to make a http request from a pl/sql procedure, can any one tell me which built-in package and which procedure/function we serve my need?
Thanks in advance.
Ram Prasad.You should use UTL_HTTP package, but before it install the JVM into DB
-
Invoking a BPEL process from a PL/SQL procedure(URGENT)
hello,
Is it possible to invoke a BPEL process from a pl/sql procedure??
Please reply ...Yes it is.
On my current project i needed this too.
http://orasoa.blogspot.com/2006/11/calling-bpel-process-with-utldbws.html
Re: Error running demo PL/SQL consuming web services
I used this utl_http example:
declare
soap_request varchar2(30000);
soap_respond varchar2(30000);
http_req utl_http.req;
http_resp utl_http.resp;
launch_url varchar2(240) ;
begin
soap_request:='<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body xmlns:ns1="http://xmlns.oracle.com/testtask">
<ns1:testtaskProcessRequest><ns1:input>leeg</ns1:input></ns1:testtaskProcessRequest>
</soap:Body>
</soap:Envelope>';
http_req:= utl_http.begin_request('http://yourhostname/orabpel/default/testtask/1.0'
,'POST',
'HTTP/1.1'
utl_http.set_header(http_req, 'Content-Type', 'text/xml') ;
utl_http.set_header(http_req, 'Content-Length', length(soap_request)) ;
utl_http.set_header(http_req, 'SOAPAction', 'initiate');
utl_http.write_text(http_req, soap_request) ;
http_resp:= utl_http.get_response(http_req) ;
utl_http.read_text(http_resp, soap_respond) ;
utl_http.end_response(http_resp) ;
dbms_output.put_line(soap_respond);
end; -
Problem in Flex to get XML result from web services
Hi all
I am struggling a proplem for a whole day, i hope somebody can help.
I am trying to get the list file of files located on the server, so i use flex to access a ASP.NET ASMX web services, that returns all the file names in a folder.
I can see that web servicese worked perfectly, however when i try to get the result from flex, i could not figure out how to get the real data i wantted
public function LoadImage(e:ResultEvent):void{
imageList.dataProvider = e.result;
the e.result has some addtional tags, such as
<GetImageFileListResponse xmlns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetImageFileListResult>
<images>
<image>01417_ccurve_1280x1024.jpg</image>
<image>1915619295407381096.png</image>
<image>21051802471898733113.png</image>
where GetImageFileList is the operation name used in web service
I am only interested in the data starting from <images> . I don't know why the addtioanl tag has been added.
here is the code i have used in flex.
<mx:WebService
wsdl="http://localhost/Flex/GetImageFiles.asmx?WSDL" id="imageWs">
<mx:operation name="GetImageFileList" result="LoadImage(event)" fault="mx.controls.Alert.show(event.fault.faultString)" resultFormat="
e4x">
</mx:operation>
</mx:WebService>
Thanks in advance!!!Hi,
Just replace the below line in your code and check...
imageList.dataProvider = e.result.GetImageFileListResult.images;
If this post answers your question or helps, please mark it as such.
Thanks,
Bhasker Chari -
How to get save result from EXECUTE from a dynamic SQL query in another table?
Hi everyone,
I have this query:
declare @query varchar(max) = ''
declare @par varchar(10)
SELECT @par = col1 FROM Set
declare @region varchar(50)
SELECT @region = Region FROM Customer
declare @key int
SELECT @key = CustomerKey FROM Customer
SET @query = 'SELECT CustomerKey FROM Customer where ' + @par + ' = '+ @key+ ' '
EXECUTE (@query)
With this query I want get col1 from SET and compare it to the column Region from Customer. I would like to get the matching CustomerKey for it.
After execution it says commands are executed successfully. But I want to save the result from @query in another table. I looked it up and most people say to use sp_executesql. I tried a few constructions as sampled and I would always get this error:
Msg 214, Level 16, State 2, Procedure sp_executesql, Line 12
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
So the output should be a list of CustomerKeys in another table.
How can I save the results from EXECUTE into a variable? Then I assume I can INSERT INTO - SELECT in another table.
ThanksCREATE TABLE Customer
(CustomerKey INT , Name NVARCHAR(100));
GO
INSERT dbo.Customer
VALUES ( 1, N'Sam' )
GO
DECLARE @query nvarchar(max) = ''
declare @par varchar(10) = 'Name',
@key varchar(10) = 'Sam'
CREATE TABLE #temp ( CustomerKey INT );
SET @query =
insert #temp
SELECT CustomerKey
FROM Customer
where ' + @par + ' = '''+ @key+ ''' '
PRINT @query
EXEC sp_executesql @query
SELECT *
FROM #temp
DROP TABLE #temp;
DROP TABLE dbo.Customer
Cheers,
Saeid Hasani
Database Consultant
Please feel free to contact me at [email protected] as well as on Twitter and Facebook.
[My Writings on TechNet Wiki] [T-SQL Blog] [Curah!]
[Twitter] [Facebook] [Email] -
How to get accurate results from sql code ?
Hello everybody,
I have a problem with some portion of my code.
I get more results than I specify in the where clause.
Here is the sample code:
c.gl_acct_id between '110'||'-'||'6890'||'-'||'69000'||'-'||'%'
and '110'||'-'||'7000'||'-'||'67999'||'-'||'%'
For some reason I also get the following results back:
110-6910-51001-001, and 110-6910-51003-001 But I don't need the 51001 and 51003. How do I specify in sql what range I really want. I was sure that the code above is correct. I guess not.
I would appreciate any help,
Thanks,
SonyaHave you tried using the query either of the following...
1) c.gl_acct_id between '110-6890-69000-000'
and '110-7000-67999-999'
and c.gl_acct_id not like '110-6910-51001-%'
and c.gl_acct_id not like '110-6910-51003-%'
assuming you have only 3 digits at the end of gl_acct.
2)If you know that your acct_id belongs to only 69000 or 67999
then
(c.gl_acct_id LIKE '110-6890-69000-%' OR
c.gl_acct_id LIKE '110-7000-67999-%' )
Plz. let me know if this not what you are looking for.
thanx
rajkiran
Here is the whole script:
select distinct c.gl_acct_id acct_no,
c.gl_acct_desc,
min(a.local_act_beg_bal) local_act_beg_bal,
sum(b.local_act_mtd_dr_amt) debits,
sum(b.local_act_mtd_cr_amt) credits,
nvl(min(a.local_act_beg_bal),0)+sum(nvl(b.local_act_mtd_dr_amt,0))-
sum(nvl(b.local_act_mtd_cr_amt,0)) end_bal
from gl_acct c, gl_acct_bal a, gl_acct_bal b
where c.org_unit_id = '110'
and b.gl_acct_id = c.gl_acct_id
and a.gl_acct_id = c.gl_acct_id
and c.sum_det_ind = 'D'
and c.gl_acct_class_ind in ( 'A' , 'L' , 'Q' , 'I' , 'E' )
and a.year_no = '2001'--:loyear
and a.period_no = '1'--:loperiod
and ( ( b.year_no = '2001'--:hiyear
and b.period_no between '1'--:loperiod
and'13')-- :hiperiod
and c.gl_acct_id between '110'||'-'||'6890'||'-'||'69000'||'-'||'%'
and '110'||'-'||'7000'||'-'||'67999'||'-'||'%'
group by c.gl_acct_id, c.gl_acct_desc
I want to have ability to specify ranges for gl_accoount.
Thanks,
Sonya -
T-sql 2008 r2 place results from calling a stored procedure with parameters into a temp table
I would like to know if the following sql can be used to obtain specific columns from calling a stored procedure with parameters:
/* Create TempTable */
CREATE TABLE #tempTable
(MyDate SMALLDATETIME,
IntValue INT)
GO
/* Run SP and Insert Value in TempTable */
INSERT INTO #tempTable
(MyDate,
IntValue)
EXEC TestSP @parm1, @parm2
If the above does not work or there is a better way to accomplish this goal, please let me know how to change the sql?declare @result varchar(100), @dSQL nvarchar(MAX)
set @dSQL = 'exec @res = TestSP '''+@parm1+''','' '''+@parm2+' '' '
print @dSQL
EXECUTE sp_executesql @dSQL, N'@res varchar(100) OUTPUT', @res = @result OUTPUT
select @result
A complicated way of saying
EXEC @ret = TestSP @parm1, @parm2
SELECT @ret
And not only compliacated, it introduces a window for SQL injection.
Erland Sommarskog, SQL Server MVP, [email protected] -
How to suppy and get the results from a procedure dynamically.
Hi all,
I have a simple procedure, which should prompt five times for
values and display the values dynamically. but it is not
behaving like that. while compilation it is asking for the
value, once i enter the value , it is prompted that procedure
created. while executing, it is diplaying all five same values
what i have entered at compilation time. Please check out. Here
is the code.
create or replace procedure test is
t_var integer;
t_count integer := 0;
begin
loop
t_var := &r;
dbms_output.put_line('The value is: ' || t_var);
If t_count = 5 Then
Exit;
End If;
t_count := t_count + 1;
end loop;
End;
Regards,
G. Rajakumar.See now what happens is
When u use &variable in sql or plsql it tries to substitute with
the value held by that variable. If it dosent find that value in
that session then it prompts for one. (that is why ur proc asks
for value only once)
What happens in your proc is
fisrt time it will ask for &r value, but subsequent i will not
ask because when second time it tries to do &r in your prog it
finds the value that u had entered above. Also as u said that
prog takes the input and dosent show anything this is cos sql
engine takes the value and compiles the proc it actucally shows
when u run it. U can have look at the below executed program
In this once u have eneterd say value 199 then it display 199
for those many number of times. I hope this answers your
question.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure test is
2 t_var integer;
3 t_count integer := 0;
4 begin
5 loop
6 t_var := &r;
7 dbms_output.put_line('The value is: ' || t_var);
8 If t_count = 5 Then
9 Exit;
10 End If;
11 t_count := t_count + 1;
12 end loop;
13* End;
SQL> /
Enter value for r: 12
old 6: t_var := &r;
new 6: t_var := 12;
Procedure created.
SQL> exec test
The value is: 12
The value is: 12
The value is: 12
The value is: 12
The value is: 12
The value is: 12
PL/SQL procedure successfully completed.
SQL> -
Obtaining HTML page by issuing a call from a PL/SQL procedure
Is there any possibility to obtain HTMLDB -> HTML page from a user defined PL/SQL procedure ?
For example I build an procedure which calls directly
flows_010500.wwv_flow.show(null,p_flow_step_id=>'2',p_flow_id=>'104')
and i try to read the result from htp.showpage, but I get a html response page with a security error.
Maybe is necessary to initialize other parameters?
Any help?Scott, I have got two pages in an application one is login page the other is welcome page. my login page will be process by store proceduer to validate the user based on users table that I have created on my schema. If the user login with username and password, if they exist on this table I will like to send them to welcome page. but I get http://htmldb.oracle.com/pls/otn/wwv_flow.accept.
The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Please try the following:
If you typed the page address in the Address bar, make sure that it is spelled correctly.
Open the htmldb.oracle.com home page, and then look for links to the information you want.
Click the Back button to try another link.
Click Search to look for information on the Internet.
HTTP 404 - File not found
Internet Explorer
the procedure is below:
CREATE OR REPLACE PROCEDURE obj_pls_login_chk(p_UserName IN varchar2
,p_Password IN varchar2
,Login IN varchar2 ) IS
l_usr_id number;
l_url varchar2(2000);
BEGIN
l_url := 'http://htmldb.oracle.com/pls/otn/f?';
select user_id into l_usr_id
from s_cdm_users
where upper(username) = upper(p_UserName)
and upper(Password) = upper(p_Password);
if l_usr_id is not null then
l_url := l_url||'p=29921:2:4413779570974471450';
--wwv_flow.show(null,p_flow_step_id=>'29921',p_flow_id=>'29921:2');
--htp.print(p_UserName);
end if;
EXCEPTION
when others then
return;
END
Maybe you are looking for
-
I have a website that displays images in black on an ipad air - it didn't do this before I upgraded to iOS8. The same website works fine on an ipad 2 gen 4 and iphone 4 running iOS8 and the images show when I use other browsers on the ipad air. What
-
I am having some trouble playing games.
I have an older gateway. I am not sure of the specific name of the model. specs
-
Upgradation from XI 3.0 to PI 7.0
Hi All, If anybody have upgradation document from XI 3.0 to 7.0 Please share it with me..what are the major differences between XI 3.0 and PI 7.0? Thanks in advance, Hemu
-
Is it true iOS7 doesn't have a monthly calendar display?
That would be a real problem if I upgrade. I sync with Microsoft's Outlook Calendar but don't have access to an Exchange server, and so I've been unable to idnetify an alternative calendar app.
-
Hi, This is regarding an issue with the MSS tab in Portal. There is an option to change the language in Portal. And when i change the language and go to the MSS tab, some standard texts are not displayed in the language selected.This issue is only fo