Pass Datablock name to Procedure
Dear All,
Can I pass datablock name to procedure ? example as below,
PROCEDURE DEADLINE_DATE (DATABLOCK_NAME VARCHAR2) IS
BEGIN
IF DATABLOCK_NAME.TS_DEADLIN_DATE + DATABLOCK_NAME.TS_EXTEND_DAY < DATABLOCK_NAME.TS_TRANS_DATE THEN
MESSAGE ('Deadline date must be greater than transaction date.');
RAISE FORM_TRIGGER_FAILURE;
END IF;
END;
But it will have error when compile module.
Everybody have other solution ??
tks a lot
Boris
hello,
i have change the code as below : -
IF name_in(':'||DATABLOCK_NAME||'.TS_DEADLIN_DATE')
and the calling code of procedure as below : -
deadlin_date('ABC');
but still receive error ORA-06502.
how to do it ? the procedure of forms must request add ':' before datablock name.
boris
Similar Messages
-
hi
Can any one plz suggest me , how to pass
table name (that would be varchar) to a procedure,such that i
should be able to do DML and DDL on the table refered !!EXECUTE IMMEDIATE executes the SQL statement held in a specified
VARCHAR2. So, with a bit of string concatenation, you can make
the statement dynamic, thus:
EXECUTE IMMEDIATE 'DELETE * FROM emp' ;
could become:
EXECUTE IMMEDIATE 'DELETE * FROM '||p_table_name ;
where p_table_name is a VARCHAR2 parameter passed into your
procedure. Check out the PL/SQL User's Guide and Reference,
chapter 10, for full details. -
Passing the name of a table to a procedure
Can anyone tell me how you can pass the name of a table to a procedure ?
I am trying to write a generic procedure that will have the table name and the fieldname passed to it :-
as in :-
Select Fieldname FROM Tablename;
nullRefere to the documentation of
built in package dbms_sql. -
Passing Table Name to Stored Procedure for From Clause
Is it possible to pass a table name to a stored procedure to be used in the From clause? I have the same task to perform with numerous tables and I'd like to use the same SP and just pass the table name in. Something like this:
=======================================
CREATE OR REPLACE PROCEDURE SP_TEST(
in_TABLE IN VARCHAR2,
AS
V_TABLE VARCHAR2(10);
BEGIN
V_TABLE := 'st_' || in_TABLE; -- in_TABLE is 2-3 character string
SELECT some_columns
INTO some_variables
FROM V_TABLE
WHERE some_conditions...;
END;
=======================================
I'm also using the passed table name to assign to variables in the Select and Where clauses. What I'm getting is an error that V_TABLE must be declared. When I hard code the table name, I don't get any errors, even though I'm also using the same method to assign values in the Select and Where clauses.
Thanks,
Ed HollomanYou need to use dynamic SQL whenever you are swapping out object names (tables, columns).
create or replace procedure sp_test
(in_table in varchar2)
is
-- variables
begin
execute immediate 'select a, b, c from st_' || in_table || ' where x = :xval and y = :yval'
into v_a, v_b, v_c using v_x, v_y;
end; -
Passing table name to a procedure and then need to open a cursor ..
Hi All,
I have been out of touch in plsql for sometime and need to do something like :
passing table name to a procedure while calling(fp_table_old captures this value) and then need to open a cursor for this table in 'for i in (select * from fp_table_old )', one of the ways I tried is : for i in (execute immediate Lv_sql_query ) but its not working for me, please find the code below for reference, I know I am sounding stupid but I have been very out of touch, please help.
code :
create procedure p_table_compare(fp_table_old in varchar2, fp_table_new in varchar2)
as
Lv_sql_query varchar2(2000);
begin
Lv_sql_query := 'select * from '||fp_table_old;
for i in (Lv_sql_query)
loop
dbms_output.put_line(i.employee_id);
end loop;
end;
Regards
Rahulif I am doing something like this : for i in (execute immediate Lv_sql_query)
I am getting an error which is :
PLS-00103: Encountered the symbol "IMMEDIATE" when expecting one of the following:
. ( ) , * @ % & | = - + < / > at in is mod remainder not
range rem => .. <an exponent (**)> <> or != or ~= >=
My code:
create or replace procedure p_table_compare(fp_table_old in varchar2, fp_table_new in varchar2)
as
Lv_sql_query varchar2(2000);
begin
--dbms_output.put_line('Hello World');
Lv_sql_query := 'select * from '||fp_table_old;
for i in (execute immediate Lv_sql_query)
loop
dbms_output.put_line(i.employee_id);
end loop;
end;
Please help.
Regards
Rahul -
Pass table name as parameter in prepared Statement
Can I pass table name as parameter in prepared Statement
for example
select * from ? where name =?
when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
Thanks
Haroon Idrees.haroonob wrote:
I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
Well, I would say (ugly as it is) String concatenation, or stored procedures. -
Size limitation that can be passed to Java stored procedure
Hello!
I enjoy using Oracle8i these days. But I have some questions
about Java stored procedure. I want to pass the XML data to Java
stored procedure as IN parameter. But I got some errors when the
data size is long. Is there any limitation in the data size that
can be passed to Java stored procedure?
Would you please help me ?
This message is long, but would you please read my message?
Contents
1. Outline : I write what I want to do and the error message I
got
2. About the data size boundary: I write about the boundary
size. I found that it depend on which calling sequence I use.
3. The source code of the Java stored procedure
4. The source code of the Java code that call the Java stored
procedure
5. The call spec
6. Environment
1.Outline
I want to pass the XML data to Java stored procedure. But I got
some errors when the data size is long. The error message I got
is below.
[ Error messages and stack trace ]
java.sql.SQLException: ORA-01460: unimplemented or unreasonable
conversion reque
sted
java.sql.SQLException: ORA-01460: unimplemented or unreasonable
conversion reque
sted
at oracle.jdbc.ttc7.TTIoer.processError(Compiled Code)
at oracle.jdbc.ttc7.Oall7.receive(Compiled Code)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(Compiled Code)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch
(TTC7Protocol.java:721
at oracle.jdbc.driver.OracleStatement.doExecuteOther
(Compiled Code)
at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch
(Compiled Code)
at oracle.jdbc.driver.OracleStatement.doExecute(Compiled
Code)
at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(Compiled
Code
at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate
(OraclePrepar
edStatement.java:256)
at oracle.jdbc.driver.OraclePreparedStatement.execute
(OraclePreparedStat
ement.java:273)
at javaSp.javaSpTestMain.sample_test
(javaSpTestMain.java:37)
at javaSp.javaSpTestMain.main(javaSpTestMain.java:72)
2. About the data size boundary
I don|ft know the boundary that I got errors exactly, but I
found that the boundary will be changed if I use |gprepareCall("
CALL insertData(?)");|h or |gprepareCall ("begin insertData
(?); end ;")|h.
When I use |gprepareCall(" CALL insertData(?)".
The data size 3931 byte --- No Error
The data size 4045 byte --- Error
Whne I use prepareCall ("begin insertData(?); end ;")
The data size 32612 byte --No Error
The data size 32692 byte --- Error
3. The source code of the Java stored procedure
public class javaSpBytesSample {
public javaSpBytesSample() {
public static int insertData( byte[] xmlDataBytes ) throws
SQLException{
int oraCode =0;
String xmlData = new String(xmlDataBytes);
try{
Connection l_connection; //Database Connection Object
//parse XML Data
dits_parser dp = new dits_parser(xmlData);
//Get data num
int datanum = dp.getElementNum("name");
//insesrt the data
PreparedStatement l_stmt;
for( int i = 0; i < datanum; i++ ){
l_stmt = l_connection.prepareStatement("INSERT INTO test
" +
"(LPID, NAME, SEX) " +
"values(?, ?, ?)");
l_stmt.setString(1,"LIPD_null");
l_stmt.setString(2,dp.getElemntValueByTagName("name",i));
l_stmt.setString(3,dp.getElemntValueByTagName("sex",i));
l_stmt.execute();
l_stmt.close(); //Close the Statement
l_stmt = l_connection.prepareStatement("COMMIT"); //
Commit the changes
l_stmt.execute();
l_stmt.close(); //Close the Statement l_stmt.execute
(); // Execute the Statement
catch(SQLException e ){
System.out.println(e.toString());
return(e.getErrorCode());
return(oraCode);
4. The source code of the Java code that call the Java stored
procedure
public static void sample_test(int num) {
//make data
Patient p = new Patient();
byte[] xmlData = p.generateXMLData(num);
try{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
Connection m_connection = DriverManager.getConnection
("jdbc:oracle:thin:@max:1521:test",
"testuser", "testuser");
CallableStatement l_stmt =
// m_connection.prepareCall(" CALL insertData(?)");
m_connection.prepareCall("begin insertData(?); end
l_stmt.setBytes(1,xmlData);
l_stmt.execute();
l_stmt.close();
System.out.println("SUCCESS to insert data");
catch(SQLException e ){
System.out.println( e.toString());
e.printStackTrace();
5. The call spec
CREATE OR REPLACE PROCEDURE insertData( xmlData IN LONG RAW)
AS
LANGUAGE JAVA NAME 'javaSp.javaSpBytesSample.insertData(byte[])';
6. Environment
OS: Windows NT 4.0 SP3
RDBMS: Oracle 8i Enterprise Edition Release 8.1.5.0.0 for
Windows NT
JDBC Driver: Oracle JDBC Drivers 8.1.5.0.0.
JVM: Java1.1.6_Borland ( The test program that call Java stored
procedure run on this Java VM)
nullIam passing an array of objects from Java to the C
file. The total size of data that Iam sending is
around 1GB. I have to load this data into the Shared
memory after getting it in my C file. Iam working on
HP-UX (64-bit). Everything works fine for around 400MB
of data. When I try to send around 500MB of data, the
disk utilization becomes 100%, so does my memory
utilization and I get a "Not enough space" when I try
to access shared memory. I have allocated nearly 2.5GB
in my SHMMAX variable. Also, I have around 45GB of
disk free. The JVM heap size is also at 2048MB. Where did you get the 400/500 number from? Is that the size of the file?
What do you do with the data? Are you doing nothing but copying it byte for byte into shared memory?
If yes then a simple test is to write a C application that does the same thing. If it has problems then it means you have an environment problem.
If no then you are probably increasing the size of the data by creating a structure to hold it. How much overhead does that add to the size of the data? -
Simple question about using passing parameters in a procedure
I have a below stored procedure (part of a package) that I need to modify by removing hard coded declaration of "cutoffdays" and change it into a parameter passed from procedure. I am not sure how to do declare and pass values for delete from a table.
CREATE OR REPLACE PROCEDURE counttimes
IS
CutOffDays NUMBER := 14;
BEGIN
DELETE FROM timetable
WHERE timestamp_val < SYSDATE - CutOffDays;
COMMIT;
END counttimes;Hints
<li>never commit at the end of a procedure, if you didn't commit at the beginning. Do the transaction handling at a higher level.</li>
<li>Name the procedure so that it is clear what it does. If records are deleted, then the procedure name should reflect that.</li>
<li>Work with full days, i.e. use trunc(sysdate) instead of sysdate. </li>
CREATE OR REPLACE PROCEDURE removeTimes (CutOffDays in integer)
IS
BEGIN
DELETE FROM timetable
WHERE timestamp_val < trunc(SYSDATE) - CutOffDays;
END counttimes;Edited by: Sven W. on Feb 14, 2011 4:17 PM -
Pass DB Link in procedure as parameter.
Hi,
I am using ORACLE Database 11g .
I have a procedure in which i am already passing some parameters. The procedure contains few statements in which it has to refer to specific user for getting the data. So we use DB Link. As which user to connect is not sure so the DB LINK is also not constant. That is why i want to pass the DB link as a parameter to procedure. But if i don't give the db link name in procedure the procedure will not compile.
A sample of my code is as follows :-
create or replace procedure P_GET_TABLES(V_DBLINK in varchar2)
as
FOR I in (select s.TABLE_NAME
from user_tables@V_DBLINK s, dba_tables d --- Obviously it gives me error that table does not exists.Due to variable V_DBLINK
where d.table_name = s.TABLE_NAME
and s.TABLE_NAME != 'ERROR_LOG'
and d.owner = V_SOURCE_SCHEMA_NAME
union (select s.TABLE_NAME
from user_tables@V_DBLINK s
minus
select TABLE_NAME
from dba_tables d
where owner = V_SOURCE_SCHEMA_NAME)) Loop
-- other code for the process.....
END LOOP;
END;
/Is their any method that i can pass a compiled procedure DB LINK as parameter or at run-time. ??
Thanks in advance.VIRU wrote:
Its a request can you just do the same thing with the FOR LOOP given by me in the first post. It will look something like this:
create or replace procedure P_GET_TABLES
(V_DBLINK in varchar2
, V_SOURCE_SCHEMA_NAME in varchar2)
as
rc sys_refcursor;
l_table_name all_tables.table_name%type;
begin
open rc for 'select s.table_name
from user_tables@'||V_DBLINK||' s, dba_tables d
where d.table_name = s.table_name
and s.table_name != ''ERROR_LOG''
and d.owner = :1
union (select s.table_name
from user_tables@'||V_DBLINK||' s
minus
select table_name
from dba_tables d
where owner = :1)'
using V_SOURCE_SCHEMA_NAME, V_SOURCE_SCHEMA_NAME;
loop
fetch rc into l_table_name;
exit when rc%notfound;
-- do your processing here....
end loop;
close rc;
end P_GET_TABLES;
/The Oracle online documentation covers dynamic SQL quite comprehensively. [url http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/dynamic.htm#i14500]Find out more.
I think you have some confusion with the data dictionary views you're using, USER_TABLES@remote_db will look for tables in a schema with the same name as the current user in the local database. The current user in the local database has the privileges to read the DBA_ level views in te local data dictionary but apparently isn't the account owning the tables in the remote database.
Is that right? It sounds like a mess. I have to [url https://forums.oracle.com/forums/thread.jspa?messageID=10062119#10062119]agree with Billy that you might be trying to solve the wrong problem. Perhaps you need better configuration/release management processes?
Cheers, APC
Edited by: APC on Jan 2, 2012 9:52 AM -
Passing Column name(String) in setting CallableStatement
Is it possible to pass Column Name while setting the CallableStatement while using drivers for JDK 1.4, if yes how do I do it.
Thanks!You don't necessarily need to use dynamic SQL;
create or replace procedure p
p_a number default null,
p_b number default null,
p_c number default null
) is
begin
insert into t
values
(p_a, p_b, p_c);
end;
Procedure createdUsing named notation;
exec p(p_a =>1, p_c => 3);
PL/SQL procedure successfully completed
exec p(p_b =>20, p_c => 30);
PL/SQL procedure successfully completedPassing NULLs;
exec p(4, null, 6);
PL/SQL procedure successfully completed
exec p(40, 50, null);
PL/SQL procedure successfully completed
select * from t;
A B C
1 3
20 30
4 6
40 50 -
Passing field name into Cursor
I would like to pass the name of a field for the WHERE clause, into a cursor. In my application I need to change the field name for the where clause. I get an "Invalid Number" error when I try the following:
cursor l_sel2Cur (c_group varchar2)
is
select email from test_grp_tbl6 where c_group = 1;
select column_name
into l_colName
from listserv_grp_lk
where lg_id = v_listserv_grp;
open l_sel2Cur(l_colName);
I hope this is enough explanation. I have seen examples where the value for the where clause is passed in, but not where the field name itself is passed in. Is this possible?
Thanks in advance,
JohnSee the following example:
SQL> create or replace procedure print_enames(in_col in varchar, in_val in varchar2) is
2 c sys_refcursor;
3 v_name emp.ename%type;
4 begin
5 open c for 'select ename from emp where '||in_col||'='''||in_val||'''';
6 loop
7 fetch c into v_name;
8 exit when c%notfound;
9 dbms_output.put_line('ename='||v_name);
10 end loop;
11 end;
12 /
Procedure created.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> set serverout on
SQL> exec print_enames('mgr','7839')
ename=JONES
ename=BLAKE
ename=CLARK
PL/SQL procedure successfully completed.
SQL> exec print_enames('sal','1250')
ename=WARD
ename=MARTIN
PL/SQL procedure successfully completed.
SQL> exec print_enames('deptno','30')
ename=ALLEN
ename=WARD
ename=MARTIN
ename=BLAKE
ename=TURNER
ename=JAMES
PL/SQL procedure successfully completed. -
Error on passing paramter names longer than 16 char on portal import page
After created a transport set, we used portal import page to import it.
However, when we select that transport set and click "import", an 404 error occured right away. The url is:
/pls/portal/PORTAL.wwutl_ui_export_import.import_eds
When we check the Apache error logs, it seemed all parameter names that are longer than 16 characters in the page's html form were passed wrongly. Those characters
after the 16th character of the parameters' names were some unreadable or wrong
ones. For example, P_EXPLICIT_MODE_EDS was passed as P_EXPLICIT_MODE_ËâN to the
backend pl/sql procedure and that's why there was a "SIGNATURE (parameter names)
MISMATCH" error I think.
My question is actually why the internal portal pages couldn't pass parameter
names that are longer than 16 characters. Are there some settings wrong with
the portal metadata database or oracle portal itself, or even our linux system? Was it because maybe we set the multilanguage-support for our portal?
This error also happens in some other portal internal pages. Please help and you can also contact me at email: [email protected]
Thanks a lot!Hi,
Found a note explaining the significance of these errors.
It says:
"NZE-28862: SSL connection failed
Cause: This error occurred because the peer closed the connection.
Action: Enable Oracle Net tracing on both sides and examine the trace output. Contact Oracle Customer support with the trace output."
For further details you may refer the Note: 244527.1 - Explanation of "SSL call to NZ function nzos_Handshake failed" error codes
Thanks & Regards,
Sindhiya V. -
IN IPAD AIR How can i send an e-mail to several mail adress typing a group name, similar procedure used un gmail wich is very frendly
Before all these updates, one used to be able to create a Group (such as Buddy List), then send emails by clicking on that Group Name. Has not worked for a long time now, though. I wish they would bring it back.
-
Execute immediate with using clause to pass column name dynamically
Hai,
Is there any way using execute immeidate to pass the column name dynamically. I used to pass the column value as dynamic with the help of "Using clause" . But if i use to pass column name, it is giving numberic error at run time. Eg,. for testing has been given below.
1. Column value as dynamic, which is working correctly.
create or replace function testexeimm (acctnum char)
return number as
acctbal number;
begin
execute immediate 'select balance from acct_master where acct_no=:a' into acctbal using acctnum;
return acctbal;
end;
2. Column name as dynamic which is not working
create or replace function testexeimm (colnam char)
return char as
acctbal char;
begin
execute immediate 'select :a from ch_acct_mast where rownum=1' into acctbal using colnam;
return acctbal;
end;
Any help in this regard will be highly appericated.
Regards
SridharSo the variable has to be numeric too:
create or replace function testexeimm (colnam char)
return number as
acctbal number;
begin
execute immediate 'select '|||colnam||' from ch_acct_mast where rownum=1' into acctbal;
return acctbal;
end;Max
http://oracleitalia.wordpress.com -
Passing TABLE NAME as parameter is possible or not?
I want develop a small/simple report like this
TABLE NAME :
WHERE :
ORDER BY :
QUERY ROWS
In the above model i want to pass all the three (TABLE NAME,WHERE and ORDER BY) as a parameter.
My doubt, is that possible to pass TABLE NAME as a parameter? If so!
When i enter any TABLE NAME it has to fetch me out the records of that table (Based on WHERE condition and ORDER BY).
Is that possible to do?
Need some help!
Edited by: Muthukumar Seshadri on Aug 10, 2012 6:19 PMYes, it is possible with lexical parameters. Look in the help for examples:
SELECT Clause
SELECT &P_ENAME NAME, &P_EMPNO ENO, &P_JOB ROLE FROM EMP
P_ENAME, P_EMPNO, and P_JOB can be used to change the columns selected at runtime. For example, you could enter DEPTNO as the value for P_EMPNO on the Runtime Parameter Form.
Note that in this case, you should use aliases for your columns. Otherwise, if you change the columns selected at runtime, the column names in the SELECT list will not match the Report Builder columns and the report will not run.
FROM Clause
SELECT ORDID, TOTAL FROM &ATABLE
ATABLE can be used to change the table from which columns are selected at runtime. For example, you could enter ORD for ATABLE at runtime.
If you dynamically change the table name in this way, you may also want to use lexical references for the SELECT clause (look at the previous example) in case the column names differ between tables.
WHERE Clause
SELECT ORDID, TOTAL FROM ORD WHERE &CUST
ORDER BY Clause
SELECT ORDID, SHIPDATE, ORDERDATE, TOTAL FROM ORD ORDER BY &SORT You have to be really careful with this approach. Dynamic SQL may cause serious performance problems.
Edited by: InoL on Aug 10, 2012 10:06 AM
Maybe you are looking for
-
Downloaded song on ipad but can't find it on itunes on desktop
DOwnloaded a song on my ipad and went to my desktop to put song on my ipod but can not locate it.
-
Windows 7 Home Premium Administrator login problem
I have two user accounts on my PC (running Windows 7 Home Premium). My profile is set as "the administrators profile" and I work and save everything on this profile. It's been working great till 2 weeks ago. I switch on the PC, it was giving the opti
-
System creation error in System administration
Please find the below error when iam trying to create the System in System administration->system configuration-->portal content i have created one folder in that foder i made right click and system from template iam getting this below error Portal r
-
Can you marry a thunderbolt display to a early 2008 mac pro?
can you marry a thunderbolt display to an early 2008 mac pro?
-
Problem showing movies.
Why can I no longer show movies on my iPad 3? Netflix, YouTube, my own home movies? Opens to location. Picture shows, but freezes with no sound. Netflix works on my TV, so I know it's not Netflix problem. Also no longer have sounds (sending emails,