I wonder whether a PL/SQL procedure can take an array of varchar parameters
i want to take an array as parameters of a PL/SQL procedure, the type of the array may be varchar. How to implement this idea?
Thanks for any suggestions.
create or replace
procedure c1 (p_array DBMS_SQL.VARCHAR2S) is
begin
dbms_output.enable (10000) ;
FOR i_rec in p_array.FIRST..p_array.LAST LOOP
dbms_output.put_line (p_array(i_rec)) ;
END LOOP ;
end ;
set serveroutput on
DECLARE
T_V2 DBMS_SQL.VARCHAR2S;
BEGIN
T_V2(1) := 'Alpha' ;
T_V2(2) := 'Beta' ;
T_V2(3) := 'Gamma' ;
C1 (T_V2) ;
END;
Alpha
Beta
Gamma
Similar Messages
-
How to send a java array to a pl/sql procedure
Hi,
This is similar to a post about 6 months ago on retrieving pl/sql tables from a java application but I can't seem to figure out how to use what I learned there to solve this.
In a java application I have a Long[] array, and in the database I have a pl/sql procedure which takes a numeric in parameter. I currently loop through the array in my java application and call the procedure multiple times. What I'd prefer to do is to be able to pass the entire array to a new procedure which performs the looping internally.
John
nullKathy,
Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
Good Luck,
Avi. -
How to pass variable to content area from a PL/SQL procedure
Hi,
Can somebody tell me how to create a(Content area) folder based on a PL/SQL procedure that takes a variable as a
parameter and returns data based on value of that parameter to the folder . Any help would be appreciated .
Thanks and regards.
Neeti.Somewhere, in one procedure, build a session identifier and save your variable there. If no session with that identifier is previously stored, it will create a new session instance with that ID for you.
declare
l_sess portal30.wwsto_api_session;
varvalue number;
begin
varvalue := 100;
l_sess := portal30.wwsto_api_session.load_session('MYSESSION','VARIABLES');
l_sess.set_attribute('VAR_NAME',varvalue);
l_sess.save_session;
end;
In your other procedure, or anywhere else needed within that same session, simply load the session and reference the variable. To reference the variable, use the following.
-- assuming new procedure, so re-defining session variable and reloading session into it
declare
my_session portal30.wwsto_api_session;
my_new_variable number;
begin
my_session := portal30.wwsto_api_session.load_session('MYSESSION','VARIABLES');
my_new_variable := my_session.get_attribute_as_number('VAR_NAME');
end;
This will let you reference parameters across multiple portal applications and indirect calls. -
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
-
How to call PL/SQL procedure from Jdeveloper
hai
i am using JDeveloper 10g version 10.1.3. i am working on Web Application[JSF,ADF BC]. i had commit button in one form. when i click that button a PL/SQL procedure can be invoked.( the procedure is to check for primary key)
how to do this
thanks in advance
C.RThere are already some threads about calling PL/SQL from Java. E.g.: adf bc jsf application and database stored procedure
Ronald -
How to call Pl/sql procedure from form ?
Hi all,
I need to call a procedure from form after the user has pressed the button to invoke the sql procedure, can anyone please advise me on how to do it ?
Thanks.
LimHi,
Thanks for your reply.
yes, I have include in when-button-pressed trigger as
AIC_PROC_AR_CCID_UPD;
Below is my procedure :-
CREATE OR REPLACE PROCEDURE AIC_PROC_AR_CCID_UPD(errbuf out Varchar2,
retcode out Number ) is
VAR_BUF VARCHAR2(240);
Cursor C1 is
SELECT CONCATENATED_SEGMENTS ACCT,
SEGMENT5 SEG5
FROM AIC_GL_COA AGC
WHERE AGC.CODE_COMBINATION_ID IS NULL;
Rec1 C1%RowType;
BEGIN
FOR Rec1 IN C1 LOOP
BEGIN
UPDATE AIC_GL_COA A SET ( DESCRIPTION, CODE_COMBINATION_ID, SEGMENT5 )=
( SELECT FFVT.DESCRIPTION, GLA.CODE_COMBINATION_ID, GLA.SEGMENT5
FROM GL_CODE_COMBINATIONS_KFV GLA,
FND_FLEX_VALUES_TL FFVT,
FND_FLEX_VALUES FFV
WHERE GLA.CONCATENATED_SEGMENTS = REC1.ACCT
AND FFV.FLEX_VALUE = REC1.SEG5
AND FFV.FLEX_VALUE_ID = FFVT.FLEX_VALUE_ID
AND FFV.FLEX_VALUE_SET_ID = 1002673 )
WHERE A.SEGMENT5 = REC1.SEG5 ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'NO RECORD UPDATE !!');
END;
END LOOP;
COMMIT;
RETURN;
END;
However, when I try to compile it, error prompt :-
Error 306 at line 1, column 1
wrong number or types of arguments in call to 'AIC_PROC_AR_CCID_UPD'
Error 0 at line 1, column 1
statement ignored.
By the way, my form 6i is running at client site and connection to procedure in unix server. Will this is ok ?
Thanks
Rgds
Lim -
Hi All,
I am working on a Data Warehousing Product and generating Web Reports.
These Web Reports are JSPs.
The basic architechture used for this is :
1. Get the inputs required for Report Generation through a Web GUI
2. Validate and Process (If Valid) the inputs so that it can be applied on the Data in the DB to fetch appropriate information.
3. The Data from the DB is retreived in the form of PL/SQL Procedures, which take the Processed information from Step 2 as Input and give the Output in the form of REF CURSORS.
Note: There are a many PL/SQL Procedures that are being executed, based on the configuration the Client has set. This configuration enables the Client to set the columns he wants to see in the Web Reports. This configuration is set before the Reports are run.
4. A call is made from Java to Oracle, each time a PL/SQL Procedure need to be executed. The REF CURSOR received as an Output from the PL/SQL Procedure is processed.
5. The next PL/SQL Procedure is called (if existing), else the Processed Data (from REF CURSOR Output) is displayed in the JSP as Web Reports.
The issue with above architechture is the PERFORMANCE.
I would like to know:
- The various ways in which data can be EFFICIENTLY & QUICKLY retrieved from PL/SQL Procedure in Java.
- Are there any APIs that improve the Java-Oracle Data Fetch Efficiency
- Is there any Java Framework available that can be used to increase the spped of Web Report generation.
- Do you suggest any changes in the above mentioned architechture, that make this work a Sweet Sixeen Year olg guy! ;)
- In general, any input that can increase the Speed of Web Report Generation.
Kindly let me know if I have not been clear at any point, so that I can re-explain the same more clearly.
And the most important thing, kindly scrap down your thoughts about the same.
Thanks a lot in advance for your VALUABLE INPUTS.
- VikasSpring
http://www.springframework.org/
http://static.springframework.org/spring/docs/2.0.x/reference/jdbc.html
http://static.springframework.org/spring/docs/2.0.x/reference/jdbc.html#jdbc-StoredProcedure -
Scripted JDBC and Oracle Stored Procedure with in/out Array
The com.waveset.util.pooledconnection used by Scripted JDBC Adapter extends java.sql.connection.
I need to pass an Varchar2 Array to the Stored Procedure. I tried using the oracle.sql.ARRAY and oracle.sql.ArrayDescriptor to pass the values, but get a casting exception,as the polledconnection implements only the java.sql.connection and not oracle.sql.connection.
What are my options of using java.sql.Array with a PL/SQL procedure that takes a varchar2 array as in out parameter?
Thanks
Venkii ran my procedure which is very similar syndra posted
create or replace procedure foo(p_dt in date, cv out sys_refcursor) as
begin
open cv for
select e.*
from table_xyz e
where start_dt = p_dt;
end;
/Here is how is executed
DECLARE
P_DT DATE;
CV SYS_REFCURSOR;
BEGIN
P_DT := '10-oct-2005';
-- CV := NULL; Modify the code to initialize this parameter
scott.foo ( P_DT, CV );
COMMIT;
END;
-- i get PL/SQL procedure successfully complted , But i dont see the result set Or output
- How do i see the output when i m using refcursor ?? i tried using print , but nothing didnt work
- Any idea ??
Thank you!!
Edited by: user642297 on Jun 24, 2010 1:35 PM -
How can I catch a resultset thrown out by PL/SQL procedure or function.
hi,
I want to write a program in java which receives a resultset
from PL/SQL , how can I do that.
I don't want to create the resultset by passing a simple sql
statement, I want the sql statement to be executed in the
procedure or function,
which in turn returns a PL/SQL table of records, or refcursor,
and capture it in the resultset.Here's a quick note on how I do it:
1. RETURN a REF CURSOR from your PL/SQL function.
2. In your Java program, you declare the return type from the
Statement as OracleTypes.CURSOR.
/* Prepare your PL/SQL function call here */
CallableStatement mystatement = myconnection.prepareCall
( "BEGIN ? := myfunction( p_param => ? ); END;" );
/* Register the Oracle REF CURSOR as the return type */
mystatement.registerOutParameter(1, OracleTypes.CURSOR);
/* Set any additional input parameters to your function */
mystatement.setString(2, "Param value");
3. When you fetch the cursor from your Statement, do getObject
() and then cast the Object as a ResultSet e.g.:
mystatement.execute);
ResultSet rs = (ResultSet) mystatement.getObject(1);
/* Now you can iterate through the ResultSet in the same way as
for any other JDBC ResultSet */
while (rset.next())
/* Fetch the values from your REF CURSOR here */
mystatement.close();
There may be better ways to do this, but it works for me.
Regards,
Chris I've put in a few more details above. Sorry I can't copy in a
whole chunk of code for you, but this should be enough to get
you started. I would recommend the Wrox Press book on
application programming with Oracle 8i, as it includes lots of
examples of many different tools for Oracle 8i e.g. JDBC, EJB,
BC4J, Portal, XML etc.
Good luck,
Chris -
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; -
How i can load excel sheet into a table in oracle through pl/sql procedure
Hi,
How i can load excel sheet into a table in oracle through pl/sql procedure or a pl/sql block. Excel sheet is saved on my c or d drive on my machine. In xls format.Depending on how big your spreadsheet is and how frequently you want to do this you might want to contruct insert statements in excel, then run these. I have done this to load a few hundred rows for a one off test on dev.
e.g. if you have values 1 and 'a' in you spread sheet and want to insert them in to table xxx col1 & 2:
| /| A | B | C
|1 |col1 |col2 |
|2 | 1|a |="insert into xxx ("&$A$1&","&B1&") values ("&A2&",'"&B2&"');"then paste the contents of colum C
insert into xxx (col1,col2) values (1,'a');into sqlplus or a script. -
How can i return object from oracle in my java code using pl/sql procedure?
How can i return object from oracle in my java code using pl/sql procedure?
And How can i returned varios rows fron a pl/sql store procedure
please send me a example....
Thank you
nullyes, i do
But i can't run this examples...
my problem is that i want recive a object from a PL/SQL
//procedure callObject(miObj out MyObject)
in my java code
public static EmployeeObj callObject(Connection lv_con,
String pv_idEmp)
EmployeeObj ret = new EmployeeObj();
try
CallableStatement cstmt =
lv_con.prepareCall("{call admin.callObject(?)}");
cstmt.registerOutParameter(1, OracleTypes.STRUCT); // line ocurr wrong
//registerOutParameter(int parameterIndex, int sqlType,String sql_name)
cstmt.execute();
ret = (EmployeeObj) cstmt.getObject(1);
}//try
catch (SQLException ex)
System.out.println("error SQL");
System.out.println ("\n*** SQLException caught ***\n");
while (ex != null)
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " + ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
catch (java.lang.Exception ex)
System.out.println("error Lenguaje");
return ret;
Do you have any idea? -
Can some selection conditions as PL/SQL procedure input parameters
Dear All,
I need to write a PL/SQL procedure so as to compute the different query only by changing the input parameters. But those input parameters need to be like a PL/SQL table selection conditions. Like:
one of the query I need two conditions:
customers.zip = 60606
customers.zip = employees.zipMy procedure can compute the query like:
select customers.cno, cname, employees.eno, ename
from customers, orders, employees
where customers.cno = orders.cno and
employees.eno = orders.eno and
C;
where C is the conjunction of the conditions in the input parameter.
Please help and thanks in advance!Well, it's easy enough to do what you want....
SQL> conn scott/tiger
Connected.
SQL> CREATE OR REPLACE FUNCTION flexi_q (pn_deptno IN NUMBER, pv_string IN VARCHAR2 := NULL)
2 RETURN sys_refcursor AS
3 return_value sys_refcursor;
4 BEGIN
5 IF pv_string IS NULL THEN
6 OPEN return_value FOR SELECT * FROM emp WHERE deptno = pn_deptno;
7 ELSE
8 OPEN return_value FOR 'SELECT * FROM emp WHERE deptno = :1 AND '
9 ||pv_string USING pn_deptno;
10 END IF;
11 RETURN return_value;
12 END;
13 /
Function created.
SQL> var rc refcursor
SQL> exec :rc := flexi_q(30)
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7900 JAMES CLERK 7698 03-DEC-81 950
30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
6 rows selected.
SQL> exec :rc := flexi_q(30, 'SAL > 1400')
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
SQL> The real question is: do you really want to do this? Fundamentally you are handing over control of your app to any nimrod who thinks they know how to write SQL. It's just about allowable for them to add simple restrictions but they could add in anything - correlated sub-queries, extravagant sorts, etc. Even if they don't deliberately exploit this hole you still have a fundamentally untunable part of your app.
It would be much better to have some additional parameters that allows the users to choose from several off-the-peg queries. If you have a user demanding the ability to write "any report I need" I recommend talking to them. The chances are they simply have a pet query, probably embodied in an Excel spreadsheet, they run once every month. Give them a view to meet that need and they'll be happy.
Cheers, APC -
Creating page items from pl/sql procedure and using them on a page
I have a page containing 2 select lists (P21_DEPARTMENTS and P21_DATE). Originally I added them as items that were "select list with submits". The problem is that based on the clearance level of the currently logged on user I only wanted the P21_DEPARTMENTS to be a select list if the user was an administrator. If however the user is not an admin then I want the page to have a hidden form field called P21_DEPARTMENTS that stores the user's department and has a label item that has the department name.
There is also a report region that generates a table based on the department selected from the select list (if the user is an admin) or the value stored in the hidden form field if the user is not.
My problem is that I cannot have both those items on the same page and use the HTML built-in authentication to determine which item should be rendered because I need to use the same ID for both items so that the stored procedure in my report region doesn't break. HTML does not permit items to share the same ID.
I tried to circumvent the problem by creating a stored procedure that performs all of the item rendering in the procedure and uses "htp.p()" to output all of my HTML code. This solution would allow me to pass a parameter into the procedure informing me as to whether or not the user is an administrator. If the user is an administrator the procedure would use a conditional statement and render a select list. If not, the hidden form field and label option would be used instead.
I finally got the stored procedure working perfectly. Now I am encountering the most bizarre thing. Since the "select list with submit" was not working (I used the same code that gets generated when I created other items using htmlDB's GUI) I decided to use a JavaScript function instead that gets triggered by the onChange event. I send along the value that is currently selected in the select list and in the function I set:
location.href='http://www.myoraclesite.com/pls/htmldb/f?p=111:21:729740000000000000::NO::P21_DEPARTMENTS:1';
In theory this should work. The problem is that it doesn't. The page reloads and the P21_DEPARTMENTS select list is not pre-selected.
The only thing I can think of is that when htmlDB generates page items that you've created with it's own admin tool it assigns some internal guid or something as opposed to when someone tries to generate dynamic page items of their own from a pl/sql procedure it's like the application doesn't even know they exist.
Any help would be GREATLY appreciated.
My only other solution would be to create a totally separate page (one for admin and another for non-admin). I would really like to avoid this.
Thanks in advance.I would love to be able to generate my menus and
various other items in my htmlDB applications in much
the same way I can using ASP, PHP and Cold Fusion.
Users should have the ability to write server-side
code wherever they feel like it. The way htmlDB works
right now I spend more time trying to figure out how
to create simple effects and generate simple
interfaces when I need to be building a portal. Ami - it's important to understand that HTML DB is not like other languages. Thus, trying to force concepts which are common in other languages into HTML DB will often result in more work.
It's definitely worth the time to go over the HTML DB 2-day Developer, which can be found here: http://www.oracle.com/technology/products/database/htmldb/pdf/B14377_01.pdf
I can build a portal using Classic ASP, C#, PHP or Cold
Fusion in like 1/10 of the time that it takes me to
build one using htmlDB. I understand that this is not
meant for the hard-core programmer but no web
programming application in today's day and age should
prevent experts from getting under the hood.And I can build a Portal in HTML DB in 1/10 the time it will take me to do it in any other language. It's like anything else - proficiency comes with practice and work.
As for getting under the hood, there is plenty of places you can do that with HTML DB. Keep in mind that HTML DB itself is an HTML DB application, so the limits on what you can build with HTML DB are virtually limitless.
Sorry for the vent there. After spending the last 2
days trying to figure out how to implement such a
straightforward thing and now being informed that it
can't be done kind of bugged me.I understand your frustration, as I've been there before. My rule for beginners is that if you are writing more than a line or two of code in the first week, you're doing something wrong. Stop, take a break, and then use the ample resources (including searching this forum) to help solve your problem. There are plenty of resources available for you to learn about HTML DB on the HTML DB home page: http://otn.oracle.com/htmldb
Good luck,
- Scott - -
Call PL/SQL procedure from htmldb_delete_message Javascript
Hi Guys,
I am a bit of a novice when it come to JavaScript; I have written a PL/SQL procedure that deletes multiple records based on a primary key:
PROCEDURE clear_alterations (p_eco IN VARCHAR2)
IS
BEGIN
DELETE FROM xxmel_apex_eco_alterations
WHERE eco = p_eco;
END clear_alterations;
I can run that straight from a normal button, but I want the htmldb_delete_message dialog box to pop up to confirm whether to delete or not. When the user clicks 'OK' I want the record to be deleted and if cancel, do nothing.
I have managed to get the confirmation box to appear but cant see how to call the PLSQL based on the 'OK' button being pressed.
Any help would be great,
Thanks
ChrisHi Cashy,
By using Ajax you can call that process. Create that process as a application process. If you are using ApEx4.0 you can create that process as page level.
This stuff you can call on the population of the delete message...check for the id through javascript then call the function.
Thanks and Regards
Maheswara
Maybe you are looking for
-
Unable to find field which i added to FB03
HI Experts, My requirement is to add field Amount and document line items field for particular document which i usually get by double clicking of document number in FB03 Is it possibel to add field Amount,. document line items which should be availab
-
How to not to display any line items for val flds values are zero in KE30?
Dear All, In KE30,in one of my reports, i do not want to display such line items for which all values are zero for all val flds, it should only display the line items for which there is any value, i have tried Zeros hide in KE35 in formatting menu>o
-
JDBC Connection Issue in Weblogic 10.3
Hi, We have upgrade from Weblogic 10.0 to Weblogic 10.3. We are having the ojdbc6.jar in the server classpath, the JDK being the 1.6. The DB is Oracle 10g. In an cluster environment, we are getting this error, while passing the connection to an Array
-
Tecra A4 , software upgrades problem!!!!
hi when i connect 2 the internet , software upgrades program connect ( auto) and notify me that a new upgrades available , and when i click that icon to get the new upgrades an error message shows up " Error ! could not start TBIOS driver " !!!! what
-
[urgent]sql plus 's user login
how do i know my sql plus login name and password? when i install...they never ask me to set my own login name and password...