Use of Run_product in Pl/sql block written in forms 5.0
I am using Run_product built-in in forms 5.0 to make a call to reports runtime. This built-in is being called in a loop to make Payslip report for nearly 2000 employees.
First of all on running the report for 9 or 10 th employee , the error was given 'MAX OPEN CURSORS EXCEEDED'. to remove this error, settings were changed in init.ora to increase Open_cursors parameter. Now the above error is not coming but after creating 8-9 reports it gives error Numeric or Value error. This error keeps coming for all the reports after that. However this error is coming in an inconsitent manner. One time it gives error for some employees but doesn't gives that error for the same employees next time.
thanks !
I could find out few postings on the same topic in the same forum. that answers my question.
best regards,
--meghanad
Similar Messages
-
Why named parameter can't be used multiple times in PL/SQL block in JDBC
with the following PL/SQL block, when I run int in JDBC, I get an error,
it says, The number of parameter names does not match the number of registered parameters.
if all named parameters are used only once, then my program works fine.
My old program uses Oracle Forms to run the attached PL/SQL block correctly, I just want to run them in JDBC without more efforts, I don't want to rewrite all PL/SQL blocks.
Does oracle driver support this case? why the PL/SQL block can work in Oracle Forms but failed in JDBC?
Can we have an another solutions to avoid rewriting the PL/SQL block to stored procedure?
if I use following SQL:
BEGIN if :q is null then :q := 'X'; else :q := 'Y'; end if; END;
, Using java program:
import java.sql.*; public class RunPLSQLBlock { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL = "BEGIN if :q is null then :q := 'X'; else :q := 'Y'; end if; END;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter("q", Types.VARCHAR); stmt.setString("q", "A"); stmt.execute(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
in the coding, only "q" registered, I got:
java.sql.SQLException: The number of parameter names does not match the number of registered praremeters at oracle.jdbc.driver.OracleSql.setNamedParameters(OracleSql.java:314) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10096) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693) at RunPLSQLBlock.main(RunPLSQLBlock.java:28)
now, tried to register 3 indexes, changed fragments are below.
import java.sql.*; public class RunPLSQLBlock { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL = "BEGIN if :q is null then :q := 'X'; else :q := 'Y'; end if; END;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter(1, Types.VARCHAR); stmt.registerOutParameter(2, Types.VARCHAR); stmt.registerOutParameter(3, Types.VARCHAR); stmt.setString(1, "A"); stmt.execute(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
now error changed to:
java.sql.SQLException: ORA-01006: bind variable does not exist at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:400) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:926) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:200) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:543) at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:208) at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1416) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1757) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4372) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:4595) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10100) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693) at RunPLSQLBlock.main(RunPLSQLBlock.java:26)
, now tried register only 1 position like below,
CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter(1, Types.VARCHAR); stmt.setString(1, "A"); stmt.execute();
, it says:
java.sql.SQLException: Missing IN or OUT parameter at index:: 2 at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2177) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4356) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:4595) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10100) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693) at RunPLSQLBlock.main(RunPLSQLBlock.java:26)
, now let try a OK case, which use all named parameters only once. coding like below, SQL and Java listed below.
BEGIN if :q is null then :r := 'X'; else :s := 'Y'; end if; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; END;
import java.sql.*; public class RunPLSQLBlock { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL = "BEGIN if :q is null then :r := 'X'; else :s := 'Y'; end if; END;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter("q", Types.VARCHAR); stmt.registerOutParameter("r", Types.VARCHAR); stmt.registerOutParameter("s", Types.VARCHAR); stmt.setString("q", "A"); stmt.execute(); System.out.println("Q :" + stmt.getString("q")); System.out.println("R :" + stmt.getString("r")); System.out.println("S :" + stmt.getString("s")); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
, the case give us the following output:
Q :A R :null S :Y
2nd part, I also tried another scheme, to use 'execute immediate', test code attached below, it also have errors.
begin execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out :q, out :r; end;
, Java Code:
import java.sql.*; public class RunDynamicSQL { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL ="begin execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out :q, out :r; end;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter("q", Types.VARCHAR); stmt.registerOutParameter("r", Types.VARCHAR); stmt.setString("q", "A"); stmt.execute(); System.out.println("Q :" + stmt.getString("q")); System.out.println("R :" + stmt.getString("r")); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
, the output is, we can find when parameter 'q' is IN OUT mode, we can't get its final value:
Q :null R :Z
, now I tried my workaround, it works fine by using a temporary variable, now my named parameter is split to 2 roles, one is for IN, another is for OUT, now I can get final out value.
declare q clob; r clob; begin q := ?; r := ?; execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out q, out r; ? := q; ? := r; end;
, my test java code,
import java.sql.*; public class RunDynamicSQL { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL ="declare q clob;r clob; begin q := ?; r := ?; execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out q, out r; ? := q; ? := r; end;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter(3, Types.VARCHAR); stmt.registerOutParameter(4, Types.VARCHAR); stmt.setString(1, "A"); stmt.setString(2, "A"); stmt.execute(); System.out.println("Q :" + stmt.getString(3)); System.out.println("R :" + stmt.getString(4)); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
, the output is expected,
Q :Y R :Z
Database:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
JDBC Driver, extracted from ojdbc6_g.jar/META-INF/MANIFEST.MF :
Created-By: 1.5.0_30-b03 (Sun Microsystems Inc.)
Implementation-Vendor: Oracle Corporation
Implementation-Title: JDBC debug
Implementation-Version: 11.2.0.3.0
Repository-Id: JAVAVM_11.2.0.3.0_LINUX_110823
Specification-Vendor: Sun Microsystems Inc.
Specification-Title: JDBC
Specification-Version: 4.0
Main-Class: oracle.jdbc.OracleDriver
JDK:
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
Edited by: jamxval on 2013-3-22 2:01PM (UTC+08:00), Give full test java program and SQL, added environment/API level; Attached another problem.
Edited by: jamxval on 2013-3-26 17:57 (UTC +08), Adjust code styleHi, thanks for your response, now I see, the named parameter is for stored procedure only, for PL/SQL block we name it placeholder name.
After cast my java.sql.CallableStatement to oracle.jdbc.OracleCallableStatement, I can find setStringAtName,
now, I have only one question:I can't find corresponding methods for registerOutputParameter, how we fetch output value?
I tried to callableStatement.getString("q"); it reports errors, but there are no ordinal binding in my source code, does placeholder names doesn't support OUT mode?
Java:
CallableStatement stmt = con.prepareCall("BEGIN if :q is null then :r := 'X'; else :s := 'Y'; end if; END;");
oracle.jdbc.OracleCallableStatement call = (oracle.jdbc.OracleCallableStatement) stmt;
call.registerOutParameter("q", Types.VARCHAR);
call.registerOutParameter("r", Types.VARCHAR);
call.registerOutParameter("s", Types.VARCHAR);
call.setStringAtName("q", "A");
call.setStringAtName("r", "A");
call.setStringAtName("s", "A");
call.execute();
System.out.println("Q :" + call.getString("q"));
</Java>
<output>
java.sql.SQLException: 不允许的操作: Ordinal binding and Named binding cannot be combined!
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.OracleCallableStatement.getString(OracleCallableStatement.java:2834)
at RunPLSQLBlock.main(RunPLSQLBlock.java:33)
</output>by the way, in my below-mentioned SQL 'problematic', when my code uses 'execute immediate' and use placeholder names in IN OUT mode, we always get NULL value (i.e. ':q'), but we can get final value of ':r' when ':r' is OUT mode only; now I get a workaround attached in below-mentioned 'my workaround' block, which split the IN OUT roles to 2 parts, it can work now;
It seems that the difference between 'problematic' and 'my workaround' imply that there are something work unexpectedly when the driver process the placeholder names, because 'my workaround' and ':r in problematic case' make sure the 'execute immediate' returned output values correctly, unluckly driver layer can't get return values.
<SQL name = 'problematic'>
begin
execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;'
using in out :q, out :r;
end;
</SQL>
<SQL name='my workaround'>
declare
q clob;
r clob;
begin
q := ?;
r := ?;
execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out q, out r;
? := q;
? := r;
end;Edited by: EJP on 26/03/2013 14:14 -
Using accept command within PL/SQL block
Hi all i have a following Pl/SQL block which ia =as follows :-
declare
begin
...certain statements using while
end;
i need to take the user input using accept
if i put the accept stmt betweeen begin and end i am getting following error :-
accept myv number default 10 prompt 'Enter a number: '
ERROR at line 48:
ORA-06550: line 48, column 8:
PLS-00103: Encountered the symbol "MYV" when expecting one of the following:
:= . ( @ % ;
ORA-06550: line 48, column 30:
PLS-00103: Encountered the symbol "PROMPT" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between || multiset member SUBMULTISET_
Let me know how can i include accept stmt in Pl/SQL block
ThanksYou're missing a fundamental concept here.
PL/SQL = embedded 4GL programming language in the Oracle database.
SQL*Plus = CLI (Command Line Interface) client for an Oracle database.
The ACCEPT command is a SQL*Plus command. Not a PL/SQL command.
The PL/SQL engine sits inside the Oracle Server Process that services your client (SQL*Plus) session. That server process does not know who/what/where you are as a physical client. It does not know what platform and o/s you are using. It does not know what client you are using. It is after all a server process and should not and need not to know that.
Nor can that Oracle Server Process running on the Data Server Platform access you client's hard drive, keyboard, mouse, screen, printer and so on.
PL/SQL running in this Oracle Server Process therefore cannot read your keyboard to accept end-user input. PL/SQL therefore cannot write data to your screen.
You need to make a clear distinction between SQL*Plus (a client) and Oracle PL/SQL (the server). -
Error in using external procedure in PL/SQL Block
After setting up the configuration : Respective entries in
tnsnames.ora
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
(CONNECT_DATA = (SID = PLSExtProc)(SERVER=DEDICATED))
and listner.ora :
(SID_LIST = (SID_DESC = (GLOBAL_DBNAME = mymachine )(SID_NAME = mysid)) (SID_DESC = (GLOBAL_DBNAME = mymachine )(SID_NAME = myid1))
(SID_DESC = (GLOBAL_DBNAME = mymachine )(SID_NAME = myid2))
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle9i)
(PROGRAM = extproc)
(ENVS="EXTPROC_DLLS = ANY" // Added this entry
(SID_DESC =
(GLOBAL_DBNAME = oracle9i)
(ORACLE_HOME = /oracle9i)
(SID_NAME = oracle9i)
(ENVS="EXTPROC_DLLS= ANY") // Added this entry
Wrote the program as :
===========================================================
#include <stdio.h>
#include<stdlib.h>
void sh(char *command) {
int num;
num = system(command);
===========================================================
Compiled the file (above ) shell.c as :
gcc -c shell.c
Made the library as :
ld -r -o shell.so shell.o
chmod 777shell.so
copied the file to respective Home directories. Made one link to /usr/lib :
which is in LD_LIBRARY_PATH
created the Library as :
CREATE OR REPLACE PROCEDURE shell(command IN char)
AS EXTERNAL
NAME "sh"
LIBRARY shell_lib
LANGUAGE C
PARAMETERS (command string);
So my problem is
when executing the procedure from SQL prompt:
SQL> exec shell('any command');
it throws the following errors :
BEGIN shell('ls'); END;
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: /opt/sotas/bin/shell.so: only ET_DYN and ET_EXEC can be loaded
ORA-06512: at "CDR_ADMIN.SHELL", line 0
ORA-06512: at line 1
Any help or suggestions would be appreciated
Thanks in advance......
Made one Link to /usr/libNikolai,
I have created a simple process flow which only calls the external process. The script is on the same host as the process flow is deployed to.
I have used two diffent values for the command parameter.
1. I placed the full path of the file in the command parameter and left the script parameter blank:
COMMAND: /edwftp/ppas/scripts/ClearPPAS.sh
PARAMETER_LIST:
SUCCESS_THRESHOLD: 0
SCRIPT:
2.I placed the bash command in the command parameter and the full path in the script parameter.
COMMAND: /usr/bin/sh
PARAMETER_LIST:
SUCCESS_THRESHOLD: 0
SCRIPT: /edwftp/ppas/scripts/ClearPPAS.sh
Both of these appear to work as they print out the statements inside the script but the files that are supposed to be removed still remain.
Starting Execution EXTER_FILE
Starting Task EXTER_FILE
Starting Task EXTER_FILE:EXTERNALPROCESS
Removing ActivatedAudit.dat...
Removing ActivatedCustomers.dat...
Removing ActiveAudit.dat...
Removing ActiveCustomers.dat...
Done!
Create the Activated Customers data file...
Create the Active Customers data file...
Done!
WARNING: Log file truncated - see RAB for further information.
/edwftp/ppas/scripts/ActivatedCustomers.sh: /edwftp/ppas/log/ActivatedCustomers.log: cannot create
/edwftp/ppas/scripts/ActiveCustomers.sh: /edwftp/ppas/log/ActiveCustomers.log: cannot create
WARNING: Log file truncated - see RAB for further information.
Completing Task EXTER_FILE:EXTERNALPROCESS
Completing Task EXTER_FILE
Completing Execution EXTER_FILE
The permissions on the /log direcotry are 775. The user I register the file location with owns this directory.
Can't think of anything else I have missed. I really appreciate your help :)
Ryan -
Using Connect within a PL/SQL block
Hi,
I have a package, inside that i have many procedures & functions, in one of my procedure, i want to use [connect username/password] within a procedure.
This procedure is called by our client program (in VC++), they will just call the procedure name with parameters, but the procedure should internally connect to one more user & perform some dba related operations, all these things are done in the procedure only, clint will not be aware of the internal operations.
I tried to give connect within the procedure,
it gives an error Invalid SQL stmt while compiling the package. Is there any way to do this.
Pls. reply me back.
Bye
null<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by pratibha:
Hi,
I have a package, inside that i have many procedures & functions, in one of my procedure, i want to use [connect username/password] within a procedure.
This procedure is called by our client program (in VC++), they will just call the procedure name with parameters, but the procedure should internally connect to one more user & perform some dba related operations, all these things are done in the procedure only, clint will not be aware of the internal operations.
I tried to give connect within the procedure,
it gives an error Invalid SQL stmt while compiling the package. Is there any way to do this.
Pls. reply me back.
Bye
<HR></BLOCKQUOTE>
null -
Write an UPdate statement using the logic used in PL/SQL block (oracle 10g)
Hi All,
I have written the following PL/SQL block. I want to write an UPDATE statement using the logic used in the following PL/SQL block. can any one please help me out in this regards.
DECLARE
v_hoov_fag gor_gold_post.hoov_flg%TYPE;
v_b49n gor_gold_post.b49n%TYPE;
CURSOR c
IS
SELECT bs_id, loyalty_date, loyalty_period, contract_date
FROM gor_gold_post
WHERE tariff_code IN (169, 135, 136);
BEGIN
FOR rec IN c
LOOP
IF (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE) < 304
OR ( TRUNC ( ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE
) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2
THEN
v_hoov_flg := 1;
ELSE
v_hoover_flag := 99;
END IF;
IF (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE) < 121.6
OR ( TRUNC ( ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE
) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2
THEN
v_b49n := 1;
ELSE
v_b49n := 99;
END IF;
UPDATE gor_gold_post
SET hoov_flg = v_hoov_flg,
b49n = v_b49n
WHERE bs_id = rec.bs_id AND tariff_code IN (169, 135, 136);
COMMIT;
END LOOP;
END;Thank you,Using case statement.
UPDATE gor_gold_post
SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END,
b49n = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END
WHERE tariff_code IN (169, 135, 136);Note: Code not tested. -
Spooling from PL/SQL Block
Hi,
Is it possible to do spooling from a pl/sql block.The spool cannot be the first command because I want to give the spool file name in a loop and each time the spool name should change based on the value.
I tried all possiblities,but I couldn't can anyone give me some idea on how to do this.
I cannot use UTL_FILE option ,because the client agreed only for spooling.
Is it possible to write the spool data is excel format..
Please find below an example of my requirement..
DECLARE
CurSor Cur_Designation IS
Select Designation from tbl_Designation;
N_Desig Cur_Designation%RowType;
Cursor Cur_Emp(Desig Number) IS
Select Emp_no,Emp_name
From Employee Where Emp_Designation = Desig;
N_Emp Cur_Emp%RowType;
BEGIN
Open Cur_Designation ;
Loop
Fetch Cur_Designation INTO N_Desig;
EXIT WHEN Cur_Designation %NOTFOUND;
--Here I want to give the spool file name
Spool --Should be designation name
Open Cur_Emp(N_Desig.Designation);
Loop
Fetch Cur_Emp INTO N_Emp ;
EXIT WHEN Cur_Emp %NOTFOUND;
-- All employee details I need to come to log file
End Loop;
Close Cur_Emp;
End Loop;
Close Cur_Desingnation;
End;
Please advice me how to do this..
Thanks,
Bindu<< I cannot use UTL_FILE option ,because the client agreed only for spooling. >>
<< I want to use it in a PL/SQL Block.I have some variables to declare and some cursors to be used.
So where should I use the spool command.
I tried to given after a fetch command ,but it is not working. >>
you can't use SPOOL inside PLSQL
you may use dbms_output calls in PLSQL
so create a procedure test2 instead of sqlscript test2 and you will be fine
rem =========== procedure test2 ================
create or replace
procedure test2 (p_param number) is
begin
dbms_output.enable (1000000);
dbms_output.put_line('A' || chr(9) || 'B' || chr(9) || 'C' ) ;
FOR i_rec in (select a,b.c from xyz where a = p_param) LOOP
dbms_output.put_line (to_char(a) || chr(9) || b || chr(9) || c ) ;
END LOOP ;
end ;
REM ==================================================== -
Reading old values in a forms pl/sql block
In a pl/sql block, in a form.
Lets say I want to loop through...
cursor c1 is
select description
from students
where student_id = 1000;
loop
open c1;
fetch c1 into v_description
--step1
update students
set description = new description
where student_id = 1000
--step2
select description into v_old_description where student_id = 1000;
end loop;
In step2 when I am reading the record I am getting the new description which is expected.
My question is how can I get the old description. i-s the value of description which was before step1.
ThanksNo, you perform an update, so the old value is overwritten in the database.
If you really want to use sql, and I don't see why in your example, you can try [flashback query|http://www.oracle.com/technology/deploy/availability/htdocs/Flashback_Overview.htm] . -
Stored Procedure Vs PL-SQL Block
Hi,
I came across an interesting problem last week. Fortunately, I was able to solve it or find an acceptable workaround for myself. But wanted to get some clarification from the experts. So posting it here.
Also, I am new to Orcle, so please excuse any shortcomings in the post.
My data model has following tables-
TABLE_PARENT (ID, other columns)
TABLE_CHILD (ID, other columns, PARENT_ID_FK)
Here, ID is the primary key column for the respective tables; PARENT_ID_FK is the foreign key referencing the ID column from the TABLE_PARENT.
I created a stored procedure programmatically (using MS Excel) to insert records in the two tables. The stored procedure has insert statements for an indefinite number of records in the parent table and for every such record, there's a corresponding record inserted in the child table. Here's the sample code.
BEGIN
/*first record*/
parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
INSERT INTO TABLE_CHILD(ID, other values,parent_id );
/*second record*/
parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
INSERT INTO TABLE_CHILD(ID, other values,parent_id );
/*third record*/
parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
INSERT INTO TABLE_CHILD(ID, other values,parent_id );
/*and so on*/
END
When I run this stored procedure, I keep getting following exception intermittently-
ORA-02291: integrity constraint violated-parent key not found tips.
My thinking is that it comes because the insert statements are executing ahead of turn of the parent_id assignment statement. And this is happening possibly because of some parallelism that is taking place during the execution of the stored procedure, or, some sort of optmization that the DB server does (though erroneously) when it compiles the stored procedure.
I tried out everything that I could think of but it didn't go away. Finally, when I executed the same set of statements as a PL-SQL block, it worked fine.
To understand it better, I am looking for clarification on the following questions.
1) Why does the exception come with stored procedure but not with PL-SQL block? Is my reasoning given above correct (parallelism or some sort of optimization coming into play)?
2) If it is due to parallelism, how to run a Oracle stored procedure with defree of prallelism set to 1?
3) If it is due to optimization done by the compiler, how to instruct the compiler to not do any such optimization. Also, in any case, isn't it an error to optimize but lose program semantics?
4) Another question related to the same piece of work I have is to use transactions in the PL-SQL block, I had to explicitly COMMIT/ROLLBACK it in the code. In whatever references I had read, it was said that by default the transaction begins with BEGIN statement and commits with END. Also, it seems to work with a Stored Proedure though. So is it that a PL_SQL block needs explicity call to COMMIT/ROLLBACK to achive transactions but stored procedures do not?
Any inputs/clarifications will be much appreciated.
Thank you
NeeleshOk, your last couple of paragraphs were helpful. Here're the details that were missing in my earlier post.
- I am on Oracle 10.2.0.
- Table definitions-
CREATE TABLE "MYUSER"."TABLE_PARENT"
*( "ID" NUMBER(19,0) NOT NULL ENABLE,*
* "NAME" VARCHAR2(30),*
* "DESCRIPTION" VARCHAR2(80),*
* "RULETYPE" NUMBER(10,0) NOT NULL ENABLE,*
* "OPERATOR" NUMBER(10,0),*
* "MININTERCEPT" FLOAT(126),*
* "PRIORITY" NUMBER(10,0),*
* "PENALTY" NUMBER(10,0),*
* "STATUS" NUMBER(10,0),*
* PRIMARY KEY ("ID")*
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
*) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
CREATE TABLE "MYUSER"."TABLE_CHILD"
*( "ID" NUMBER(19,0) NOT NULL ENABLE,*
* "WEIGHT" NUMBER(19,0),*
* "PARENTID_FK" NUMBER(19,0),*
* PRIMARY KEY ("ID")*
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
* CONSTRAINT "FK3A78BF1E6A9DCE51" FOREIGN KEY ("PARENTID_FK")*
* REFERENCES "MYUSER"."TABLE_PARENT" ("ID") ENABLE*
*) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
- The Stored procedure definition is-
CREATE OR REPLACE PROCEDURE LOAD_RULES_SP AS
ruleid NUMBER(19,0);
tempid NUMBER(19,0);
BEGIN
*/* First parent record */*
SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
*/* Corresponding child records */*
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.2, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.5, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.3, ruleid);
*/* First parent record */*
SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
*/* Corresponding child records */*
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.2, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.5, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.3, ruleid);
*/* And so on for a few parent records more */*
END;
Can you throw some light on the exception I was seeing now? Note that when I changed from stored procedure to an anonymous block, it worked fine.
One correction in my earlier post is that as the code snippet shows, there are multiple inserts in the child table for every record inserted in the parent one. -
Creating temporary table in pl/sql block problem
hello
i have a problem in creating and using temporary table in pl/sql block
please verify below block
begin
execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
insert into alitemp1 (co_t,color) values ('001','red');
execute immediate 'DROP TABLE alitemp1';
end;
when i execute that block i will receive this error
insert into alitemp1 (co_t,color) values ('001','red');
ERROR at line 3:
ORA-06550: line 3, column 14:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 3, column 2:
PL/SQL: SQL Statement ignored
i think it because that alitemp1 table don't create
but two below block run fine
begin
execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
execute immediate 'DROP TABLE alitemp1';
end;
begin
execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
end;
select table_name from user_tables where table_name='ALITEMP1';
TABLE_NAME
ALITEMP1
it means that problem is when the below line exists in block
insert into alitemp1 (co_t,color) values ('001','red');
if may please guide meIn addition to the comments by Justin and 3360, you cannot do what you want the way you are doing it.
All objects referred to in a PL/SQL block must exist at the time the block is compiled. In your case, since it is an anonomous block, that is run time. Since you are dynamically creating the temporary table you need to refer to it dynamically as well. More like:
BEGIN
EXECUTE IMMEDIATE 'create global temporary table alitemp1 (co_t varchar2(10),
color varchar2(10))';
EXECUTE IMMEDIATE 'insert into alitemp1 (co_t,color) values (:b1,:b2)' USING '001', 'red';
EXECUTE IMMEDIATE 'DROP TABLE alitemp1';
END;However, don't do that it is a really bad idea. Just create the temporary table, if you really need it, once and use it in your processing.
In most cases, things that SQL Server needs temporary tables for can be done easily in Oracle with a single SQL statement,
John -
Run SQL cmd from PL/SQL block
Is it possible to run SQL command Eg. "ALTER SESSION SET PLSQL_DEBUG=TRUE"
within PL/SQL block in a form
thax
shabarDear shabar!
Yes, it is!
BEGIN
--Here as some PL/SQL-Commands
--And here is the SQL-Command
EXECUTE IMMEDIATE 'ALTER SESSION SET PLSQL_DEBUG=TRUE';
--And here are some more PL/SQL-Commands
END;I hope this will help you along!
Yours sincerely
Florian W. -
How to use the WHENEVER SQLERROR EXIT statement in a PL/SQL block.
Hi,
I am getting the following error when trying to add the following statement in an PL/SQL block.
WHENEVER SQLERROR EXIT SQL.SQLCODE
[exec] ERROR at line 23:
[exec] ORA-06550: line 23, column 12:
[exec] PLS-00103: Encountered the symbol "SQLERROR" when expecting one of the
[exec] following:
[exec] := . ( @ % ;
How can i use the above statement in the PL/SQL Block? I have only IF statement in that block( between BEGIN and END).
ThanksHi,
Usually there's always more than one solution.
Can you post an example of what you're trying to accomplish?
That would be useful.
(Place the tag before and after your example to maintain formatting en spacing, see the [fac|http://forums.oracle.com/forums/help.jspa] regarding available tags) -
Error while invoking webservice using UTL_HTTP from PL/SQL Block
Hi All,
I am invoking a webservice (SOAP Request) from a PL/SQL block using UTL_HTTP package.
I am able to send the complete request and am getting the required instance on the BPEL Console, but the process is erroring out while getting response back.
and the PL/SQL Block is ending in error mentioned below:
ERROR at line 1:
ORA-29266: end-of-body reached
ORA-06512: at "SYS.UTL_HTTP", line 1321
ORA-06512: at "APPS.CSM_BPEL_TEST_PKG", line 34
ORA-06512: at line 1
Package is completing successfully if i test in local DB and local BPEL.
But giving above error in client's.
Can anyone let me know what is the cause of this.
Thanks in advanceI got it working by making process Synchronous.
But with asynchronous process it is still same error.
Thanks... -
Resolved: Use value from select list in pl/sql block
Hello,
I have a form with a select list: P18_BONUSTYPE, the values of which come from a LOV.
When the user clicks a button, a page process is used to insert a row into a table.
When I use the :P18_BONUSTYPE bind variable in my insert statement I get an error "Invalid number" I get an "Invalid number" error. I assume that APEX is using the displayed text in that bind variable, not its actual (html option) value.
I checked the HTML of the page, and the correct values are in the select list.
Can someone tell me how to get the value into a bind variable that can be used in a pl/sql block for a page process?
Thanks
Message was edited by:
Neeko
Issue was a value in another item.Did you tried changing the value using "to_number"? (i.e. to_number(:P18_BONUSTYPE)).
Max. -
Using PL/SQL Block how do you check if the character string value is aA-zZ
I have a pl/sql block that I prompt the user for password and I load the string into an array and interrogate each index(entry) to see if it is "aA-zZ".
How can I check if the value entered is Alpha.
I need to do the same for number and Special character. Please advise. ThanksThanks to All of you. The desired solution to verify complex password that enforces desired security policies. An example that I am using is the following:
IF NOT (regexp_like(sz_complex_pw,'[[:digit:]]') AND regexp_like(sz_complex_pw,'[[:alpha:]]') AND regexp_like(sz_complex_pw,'[[:punct:]]') AND regexp_like(sz_complex_pw,'[[:upper:]]'))
THEN
--dbms_output.put_line('Password is not complex...');
RAISE sz_err_pw_complex; -- Complex Password is not compliant
END IF;
DBMS_OUTPUT.PUT_LINE('Complex Password is in Compliance...');
EXCEPTION
This was helpful to me and I trust others will find helpful.
Edited by: yakub21 on Oct 16, 2010 9:05 PM
Maybe you are looking for
-
Dear Experts, I have come across a strange scenarion where in the "Export to Excel" functionality from an ALV grid behaves differently for different layout selections. for eg: I have my output list with 10 fields displayed. If I export the list to th
-
I'm running Solaris 9 x86 09/04. The only patch I've applied is: 112786-32 X11 6.6.1_x86: Xsun patch as recommended by the J2SE 1.5 release notes. After installing J2SE 1.5, the Solaris Management Console is broken. If I try to start it from the comm
-
Hi, I am working on SRM Extended classic scenario. Front end BBPCRM 4.0 SAPKU40007 Back end 4.6C SAPKH46C47 I have a material A which has the base unit of measurement Package and this material exists in many of the plant so whenever I order this mat
-
How can I print from Firefox using my Epson Workforce 610 printer?
I call technical support at Epson regarding my Workforce 610 printer because I'd tried to print out an e-mail using my Mozilla FireFox web browser. During the conversation with Epson technical support I learned that my printer does in fact work and w
-
How to limit CPU usage on webcam stream handling?
Hi, I am working on a robotics project where I use Java and JMF for image processing which is passed through JNI to OpenCV. My project pages are at: http://robot.lonningdal.net I am having problems with performance - the VIA CN13000 board is not exac