Inline sqls in Plsql stored procedures
I am trying to create the following procedure in Oracle8i(8.1.7) but it gives compilation becuase i have used INLINE queries in the procedure. The code is:
create or replace procedure proc1
is
master_name VARCHAR2(50);
child_name VARCHAR2(50);
begin
select (select master_nm
from master_table
where master_id = a2.master_id) master_name,
child_nm
into master_name,
child_name
from child_table a2
where child_id = 130;
end;
I have to write very complex sqls as part of my work & if PLSQL allows INLINE views my work becomes easy. And also the performance of sqls with INLINE queries compared to OUTER join queries is better.
Suggest some solution for this.
Regards,
Sunil.
Your SQL is fine, but the PL/SQL compiler in 8i does not understand all SQL syntax. The workaround is to use dynamic SQL (this is not needed in 9i and later).
First, we try static SQL:
sql8i>declare
2 v_object_id all_objects.object_id%type;
3 v_status all_objects.status%type;
4 begin
5 select object_id, (select ao2.status
6 from all_objects ao2
7 where ao2.object_id = ao1.object_id)
8 into v_object_id, v_status
9 from all_objects ao1
10 where object_name = 'DUAL'
11 and object_type = 'TABLE';
12 dbms_output.put_line( v_object_id || ' ' || v_status);
13 end;
14 /
select object_id, (select ao2.status
ERROR at line 5:
ORA-06550: line 5, column 22:
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 8, column 5:
PLS-00103: Encountered the symbol "INTO" when expecting one of the following:
; return returning and orWell, that didn't work too well. Let's try it with NDS (native dynamic SQL):
sql8i>declare
2 v_object_id all_objects.object_id%type;
3 v_status all_objects.status%type;
4 begin
5 execute immediate '
6 select object_id, (select ao2.status
7 from all_objects ao2
8 where ao2.object_id = ao1.object_id)
9 from all_objects ao1
10 where object_name = :object_name
11 and object_type = :object_type'
12 into v_object_id, v_status using 'DUAL', 'TABLE';
13 dbms_output.put_line( v_object_id || ' ' || v_status);
14 end;
15 /
195 VALID
PL/SQL procedure successfully completed.Here's an example showing the static SQL working in 9i:
sql9i>declare
2 v_object_id all_objects.object_id%type;
3 v_status all_objects.status%type;
4 begin
5 select object_id, (select ao2.status
6 from all_objects ao2
7 where ao2.object_id = ao1.object_id)
8 into v_object_id, v_status
9 from all_objects ao1
10 where object_name = 'DUAL'
11 and object_type = 'TABLE';
12 dbms_output.put_line( v_object_id || ' ' || v_status);
13 end;
14 /
222 VALID
PL/SQL procedure successfully completed.
Similar Messages
-
How to generate XML Publisher report from PLSQL Stored Procedure in APPS
Hi,
I have concurrent program of type PLSQL Stored procedure.I need to generate XML Publisher report from the same.I have changed the output of the concurrent program as "XML" but when I tried running it,the XML tags are not generated.Due to this I am unable to create the template.Its a urgent issue.
Please help me out .
Thanks in advance.
KaveriHi Kaveri
Sadly there is nothing magic about that output field. The only program type that you can flip it to XML and then magically get XML is for Oracle Reports. For plsql you will need to recode the plsql to generate XML rather than text that you have now.
You have some options, best option first:
1. Move the sql to a data template - check the user guide and blog for help or
2. Use SQL XML or XMLGEN (not great for large datasets) or
3. Use dbms_output.put_line and write the XML file manually - not performant at all
Regards, Tim -
Problem while calling webservice from a plsql stored procedure
Hi everybody,
I need to call a webservice from a plsql stored procedure.
I was following documentation published in the otn at the following link.
"http://www.oracle.com/technology/tech/webservices/htdocs/samples/dbwebservice/DBWebServices_PLSQL.html"
I am encountering the following error on my sql prompt-
SQL> exec dbms_output.put_line(time_service.get_local_time('94065'));
BEGIN dbms_output.put_line(time_service.get_local_time('94065')); END;
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1022
ORA-12545: Connect failed because target host or object does not exist
ORA-06512: at "APPS.DEMO_SOAP", line 65
ORA-06512: at "APPS.TIME_SERVICE", line 13
ORA-06512: at line 1
Has anybody worked on the same example. Please direct me.
Thanks & Regards
Kiran KumarKiran, were you able to solve this?
I am facing the same error.
Oracle Server is Unix and webservice is .NET.
I am able to connect to Java web service. -
Wrapped PLSQL Stored Procedure
Hi,
Referring to Oracle 9i Enterprise Edition.
PLSQL stored procedure that is wrapped, can it be unwrapped?
After it is wrapped, is the original source still store inside the database dictionary or somewhere hidden in the database?
Please advise.
Thanks.PLSQL stored procedure that is wrapped, can it be unwrapped?The primary use for wrapping PL/SQL is for ISVs distributing programs. It's to prevent customers prying into commercially sensitive code. It is also applicable in other security situations. Consequenmtly it doesn't make sense that there would be a clear version hanging around in the distributed app. The presumption is that the person doing the wrapping retains the original unwrapped source.
Cheers, APC -
Urgent: unable to call a plsql stored procedure with a struts data action
Hello ALL,
I'm trying to call a plsql stored procedure within a struts DataAction,
The scenario is:
When a user a click on a button, then it should call a specific stored procedure,,
I create struts data action a class to handle the event which is to call the procedure
Here is my code:
public class RequestAction extends DataForwardAction
public void onCall(DataActionContext ctx)
String amDef = "model.AppModule";
String config = "AppModuleLocal";
ApplicationModule am =
Configuration.createRootApplicationModule(amDef, config);
try{
AppModuleImpl myAm = (AppModuleImpl)am;
DBTransaction tr = (DBTransaction) myAm.getTransaction();
CallableStatement stmt = tr.createCallableStatement
("begin pkg_test.test; end;", DBTransaction.DEFAULT);
stmt.execute();
stmt.close();
tr.commit();
catch(Exception e){System.out.println(e.getMessage());}
Configuration.releaseRootApplicationModule(am,true);
but when I ran the application and click on the button, I got the following Exception:
04/07/08 00:45:50 ORA-06550: line 1, column 7:
PLS-00201: identifier 'PKG_TEST.TEST' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
It seems that the DBTransaction object unable to see the stored procedure,
Am I do something wrong or miss something???
I've checked the examples on the OTN HOW TO, and searched in the JDeveloper Forum but unable to find an answer,
Please anyone can help???
Thanks a lot
With Regards,
HayatHere's an example application that illustrates how to do this. I haven't had a chance to writeup a little paper to go with it yet, but will as soon as I have a chance.
http://otn.oracle.com/products/jdev/tips/muench/storedproc/CallStoredProc.zip
See the "callStoredProcedure" method in the application module in the Model project.
See the "callStoredProcedure" method binding in the binding container of the "CallStoredProcedure" data page.
Notice the name "event_callStoredProcedure" of the (Call Stored Procedure) button on the CallStoredProcedure.jsp page which triggers the declaratively invocation of the method.
You could also call the method from code in a custom data action.
The code example illustrates how to create your own JDBC prepared statement for invoking the stored procedure, and doing it in a way that is efficient by keeping the prepared statement around across invocations. -
Requirements for serving Web PLSQL stored procedures
Hi all,
Can someone tell me what I need to host Web based PLSQL stored procedures?
I was told by Oracle Corp that I only needed 9i but after looking through all the documentation and these message boards, I think I need 9iAS.
If I need 9iAS, do I also need 9i?
And if so, can they coexist on the same Sun Solaris box?
Any help would be greatly appreciated.
Thanks in advance
AaronYou'll need both - the Application Server to serve the pages, and the database to store the PL/SQL code. Yes, the two can co-exist - as long as they are installed in separate directories.
Hope this helps,
Ashesh Parekh
Oracle9iAS Product Management -
Calling SQL * LOADER in stored procedure
Hi Experts,
Can we call sql*loader in stored procedures? . If yes , please let me know the syntax.
Any help will be highly appreciated.
Thanks.You can also use dbms_schedular to execute any shell or batch file - i guess ->
BEGIN
-- UNIX
DBMS_SCHEDULER.create_job(
job_name => 'unix_command_job',
job_type => 'EXECUTABLE',
number_of_arguments => 1,
job_action => '/bin/ls',
auto_drop => FALSE,
enabled => FALSE);
DBMS_SCHEDULER.set_job_argument_value('unix_command_job',1,'/tmp');
DBMS_SCHEDULER.set_attribute('unix_command_job', 'credential_name', 'TIM_HALL_CREDENTIAL');
DBMS_SCHEDULER.set_attribute('unix_command_job', 'destination', 'marge.localdomain:65001');
DBMS_SCHEDULER.enable('unix_command_job');
END;For details ->
http://www.oracle-base.com/articles/11g/SchedulerEnhancements_11gR1.php
http://www.oradev.com/dbms_scheduler.jsp
http://www.psoug.org/reference/dbms_scheduler.html
Regards.
Satyaki De. -
How to execute .sql file in Stored Procedure?
Hi,
I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
This .sql file will have set of update statement. I need to pass value to this update statement.
Kindly please help me.
Regards,
IrfanThis is required as part of Data Migration where i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
How have you determined that it's "better" to have seperate scripts? I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
Question: Why do you have tables with different names that all need the same process doing to them?
Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
e.g.
create procedure update_table(tbl_name varchar2) is
begin
execute immediate 'update '||tbl_name||' set lastupdate = null';
end;
As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer. Please do take the time to read the FAQ and post appropriate details so people can help you. -
How to call PLSQL Stored procedure in ADF?
Hi!
I am using adf for our development. We have existing stored packages and I want to use them. The problem is how can I call those PLSQL stored procedure in ADF.
Thanks in advance
alvin.Hi,
a stored procedure is called by the business service. If e.g. your business service is ADF Business Components then you call a stored procedure from the Application Module's transaction. Call a PLSQL procedure using a prepared statement. Similar you call stored procedures from EJB or TopLink business services
For ADF Business Components see
http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html
Frank -
MS SQL Server system stored procedures can't be migrated into Oracle 11g
During database migration from MS SQL Server 2008 to Oracle 11g R2, if the application stored procedure invokes the MS SQL Server system stored procedures (for example: sp_getapplock, sp_releaseapplock ....), these SQL server system stored procedures can't be transferred. See following migrated Oracle application stored procedure for example:
create or replace
PROCEDURE spPwSysID_GetNextID
v_ID OUT NUMBER,
iv_SysType IN NVARCHAR2 DEFAULT NULL ,
iv_Cnt IN NUMBER DEFAULT NULL
AS
v_SysType NVARCHAR2(50) := iv_SysType;
v_Cnt NUMBER(10,0) := iv_Cnt;
v_result NUMBER(10,0);
BEGIN
--SQL Server BEGIN TRANSACTION;
utils.incrementTrancount;
v_Systype := UPPER(v_Systype) ;
IF v_Cnt < 1 THEN
v_Cnt := 1 ;
END IF;
v_result :=sp_getapplock(v_Resource => v_Systype,
v_LockMode => 'Exclusive') ;
IF v_result >= 0 THEN
BEGIN
SELECT ID
INTO v_ID
FROM PWSYSID
WHERE SysType = v_SysType;
IF SQL%ROWCOUNT = 1 THEN
UPDATE PwSysID
SET ID = ID + v_cnt
WHERE SysType = v_SysType;
ELSE
BEGIN
INSERT INTO PwSysID
( ID, SysType )
VALUES ( v_cnt + 1, v_SysType );
v_ID := 1 ;
END;
END IF;
v_result :=sp_releaseapplock(v_Resource => v_Systype) ;
END;
ELSE
BEGIN
raise_application_error( -20002, 'Lock failed to acquire to generate Cityworks Id.' );
END;
END IF;
utils.commit_transaction;
END;During database migration from MS SQL Server 2008 to Oracle 11g R2, if the application stored procedure invokes the MS SQL Server system stored procedures (for example: sp_getapplock, sp_releaseapplock ....), these SQL server system stored procedures can't be transferred. See following migrated Oracle application stored procedure for example:
create or replace
PROCEDURE spPwSysID_GetNextID
v_ID OUT NUMBER,
iv_SysType IN NVARCHAR2 DEFAULT NULL ,
iv_Cnt IN NUMBER DEFAULT NULL
AS
v_SysType NVARCHAR2(50) := iv_SysType;
v_Cnt NUMBER(10,0) := iv_Cnt;
v_result NUMBER(10,0);
BEGIN
--SQL Server BEGIN TRANSACTION;
utils.incrementTrancount;
v_Systype := UPPER(v_Systype) ;
IF v_Cnt < 1 THEN
v_Cnt := 1 ;
END IF;
v_result :=sp_getapplock(v_Resource => v_Systype,
v_LockMode => 'Exclusive') ;
IF v_result >= 0 THEN
BEGIN
SELECT ID
INTO v_ID
FROM PWSYSID
WHERE SysType = v_SysType;
IF SQL%ROWCOUNT = 1 THEN
UPDATE PwSysID
SET ID = ID + v_cnt
WHERE SysType = v_SysType;
ELSE
BEGIN
INSERT INTO PwSysID
( ID, SysType )
VALUES ( v_cnt + 1, v_SysType );
v_ID := 1 ;
END;
END IF;
v_result :=sp_releaseapplock(v_Resource => v_Systype) ;
END;
ELSE
BEGIN
raise_application_error( -20002, 'Lock failed to acquire to generate Cityworks Id.' );
END;
END IF;
utils.commit_transaction;
END; -
BI Publisher 11g - calling SQL Server 2005 stored procedure error
Hi experts
I have been calling succesfully an SQL server 2005 stored procedure for the data model of a BI publisher report in 10g, passing it a customerNo parameter.
EXEC [dbo].[usp_WelcomeLettersConsumerNo]
@CustomerNo = :sCustomerNo
However it does not work in 11g I get the error:
[Hyperion][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'is'.
which is frustrating as there is no 'is' in the statement (perhaps it is picking up :s?) - I wonder does anyone know if there has been a change in 11g that may be causing this?
cheers
TimHi experts
I have been calling succesfully an SQL server 2005 stored procedure for the data model of a BI publisher report in 10g, passing it a customerNo parameter.
EXEC [dbo].[usp_WelcomeLettersConsumerNo]
@CustomerNo = :sCustomerNo
However it does not work in 11g I get the error:
[Hyperion][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'is'.
which is frustrating as there is no 'is' in the statement (perhaps it is picking up :s?) - I wonder does anyone know if there has been a change in 11g that may be causing this?
cheers
Tim -
How to execute plsql stored procedure with DbAccess
sessionInfo object can give DbAccess .through
which u can use javax.infobus.DbAccess API to
execute sql satement and stored procedures according to infobus API .iam able to
execute simple query by using executeCommand() ,executeRetrival() ?. how to execute stored procedures with executeRetrieval() .
how to take in and out parameters
suggestions are welcome
waiting for your suggestionsI am also looking for the same.
Did you get any info on this
Thanks,
jagan
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by chandra sekhar ([email protected]):
sessionInfo object can give DbAccess .through
which u can use javax.infobus.DbAccess API to
execute sql satement and stored procedures according to infobus API .iam able to
execute simple query by using executeCommand() ,executeRetrival() ?. how to execute stored procedures with executeRetrieval() .
how to take in and out parameters
suggestions are welcome
waiting for your suggestions<HR></BLOCKQUOTE>
null -
Publish PLSQL stored procedure as web services
Is it true that PLSQL stored procedure can only be published as web services using JAVA?
I came across article that mention how to call other web services from within plsql, but not sure the vice versa.
So, please advise.
Thank you.True..I've done it once using J-Developer.
http://www.oracle.com/technology/obe/obe1013jdev/ws/wsandascontrol.htm#o
Good luck!!
Bhagat -
What is the data dictionary that stores the SQL text of stored procedures?
I am handling both Oracle 8i on IBM AIX 5L and Oracle9i on SUN Soliars 8 /9.
What is/are the data dictionary tables, or v$ views that store the SQL text of stored procedured and triggers?
Thank you in advance!If the procedures are not wrapped, you can view them in the dba/all/user_source view. Trigger bodies can be seen in dba/all/user_triggers view.
Message was edited by:
Daniel Fink -
Returning SQL cursor from Stored Procedure
Hi,
I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
assume both query returns equal number of rows.. however both are not related to each other..RP wrote:
Hi,
I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
assume both query returns equal number of rows.. however both are not related to each other..It sounds like what you need is a ref cursor.
First thing to remember though is that cursors do not hold any data (see: {thread:id=886365})
In it's simplest form you would be creating a procedure along these lines...
SQL> create or replace procedure get_data(p_sql in varchar2, p_rc out sys_refcursor) is
2 begin
3 open p_rc for p_sql;
4 end;
5 /
Procedure created.
SQL> var rc refcursor;
SQL> exec get_data('select empno, ename, deptno from emp', :rc);
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
14 rows selected.
SQL> exec get_data('select deptno, dname from dept', :rc);
PL/SQL procedure successfully completed.
SQL> print rc
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
50 IT SUPPORTWhich takes an SQL statement (as you said that both your queries were unrelated), and returns a ref cursor, and then your Java code would fetch the data using that cursor.
Now, as for getting your rows to columns and combining two queries that do that... something along these lines...
SQL> select * from x;
C
A
B
C
SQL> select * from y;
C
D
E
F
SQL> ed
Wrote file afiedt.buf
1 select x.col1, x.col2, x.col3
2 ,y.col1 as col4
3 ,y.col2 as col5
4 ,y.col3 as col6
5 from (
6 select max(decode(rn,1,col1)) as col1
7 ,max(decode(rn,2,col1)) as col2
8 ,max(decode(rn,3,col1)) as col3
9 from (select col1, rownum rn from (select * from x order by col1))
10 ) x
11 cross join
12 (
13 select max(decode(rn,1,col1)) as col1
14 ,max(decode(rn,2,col1)) as col2
15 ,max(decode(rn,3,col1)) as col3
16 from (select col1, rownum rn from (select * from y order by col1))
17* ) y
SQL> /
C C C C C C
A B C D E F... will do what you ask. For further information about turning rows to columns read the FAQ: {message:id=9360005}
Maybe you are looking for
-
I have 10.4 and a friend of mine has 10.5. We used to be able to do a video chat but lately, I can only see his audio icon. I don't understand why. I think he can see us but I can't see him. Any suggestions?
-
Changing LOV's table-field size
Hi, I'm using Jdeveloper 11g. Knowing that the tag below is used in LOV, Now I need to know how to change the LOV's table-field sizes? (I'm using the model-based LOV, and it's reading the attributes from the view object) <af:inputListOfValues model="
-
E-recruitment - Role based restrictions on Active Queries - High Priority
Requirement - Do we have an option to restrict the queries in recruiter 'active queries list' (work center) based on roles. for example: Restricted recriter should not be allowed to view Back ground checks query. and Talent Groups query. Version - E-
-
Weblogic 10.0 jbuilder 2007
hi, can someone guide me how to configure weblogic server 10 for jbuilder 2007? is it possible? i tried installing BEA WebLogic? Server Tools but no much help.. thanks in advance
-
Hi,all:: I would like to generate out put in pdf format from swing application or in HTML format plz help me regarding this thread. Plz suggest third party tool like "JFreeReport,RReports,.....i would like to do it with my self. Thanking you in antic