FETCHING OUTPUT VALUE FROM PL/SQL BLOCK
hI aLL,
I'm working on ODP.NET. I'm executing below pl/sql command. while executing this command in pl/sql it's showing the output which is an xml.
declare
xmloutput xmltype;
xmldata varchar(32767);
teid t_id := t_en_id( 'L','L',NULL,12121,'ABC','USER','N');
tgetinfo to_info := NULL;
RETVAL NUMBER;
begin
RETVAL := GET_DTLS(teid,tgetinfo);
dbms_output.put_line(RETVAL);
xmldata := tgetinfo.XML_info.getclobval();
dbms_output.put_line(xmldata);
end;
I passed above command in string variable for passing in code. like below
string StrQry = "";
StrQry += "declare \n";
StrQry += "xmloutput xmltype; \n";
StrQry += "xmldata varchar(32767); \n";
StrQry += "teid t_id := t_en_id( 'L','L',NULL,12121,'ABC','USER','N'); \n";
StrQry += "tgetinfo to_info := NULL; \n";
StrQry += "RETVAL NUMBER; \n";
StrQry += "begin \n";
StrQry += "RETVAL := GET_DTLS(teid,tgetinfo); \n";
StrQry += "dbms_output.put_line(RETVAL); \n";
StrQry += "xmldata := tgetinfo.XML_info.getclobval(); \n";
StrQry += "dbms_output.put_line(xmldata); \n";
StrQry += "end; \n";
I'm passing output parameter ":temp" for this command. I want to catch output xml in ":temp" variable
which is varchar2 type.
Added below line before printing xmldata;
StrQry += ":temp := xmldata; \n";
cn.Open();
OracleCommand cmd = new OracleCommand(StrQry, cn);
cmd.Parameters.Add(":temp", OracleDbType.Varchar2, 32767, ParameterDirection.Output);
cmd.ExecuteNonQuery();
But which executing through c# code it's showing the below error.
Oracle.DataAccess.Client.OracleException ORA-06502: PL/SQL: numeric or value err
or: character string buffer too small
ORA-06512: at line 11 at Oracle.DataAccess.Client.OracleException.HandleError
Helper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOp
oSqlValCtx, Object src, String procedure)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, Oracle
Connection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx
, Object src)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
at orclGetDetails.Program.DoProcess()
How can i get the output to output variable ":temp".
Pls help.
Ideas are appreciated.
Your PL/SQL block isn't returning anything. DBMS_OUTPUT is, at best, a way of debugging code, not passing data around. Assuming you configure and enable an appropriately sized buffer, I suppose your ODP.Net application could make DBMS_OUTPUT.GET_LINE calls to retrieve the XML. But that's not not a way to design an application.
If you want a PL/SQL block that returns XML, you'll need to create a function and have the function return the XML (you could also create a procedure with an OUT parameter in which you could return the XML).
Justin
Similar Messages
-
From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?
Hi,
Use NVL or COALESCE:
NVL (col_a, col_b)
Returns col_a if col_a is not NULL; otherwise, it returns col_b.
Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Script fails when passing values from pl/sql to unix variable
Script fails when passing values from pl/sql to unix variable
Dear All,
I am Automating STATSPACK reporting by modifying the sprepins.sql script.
Using DBMS_JOB I take the snap of the database and at the end of the day the cron job creates the statspack report and emails it to me.
I am storing the snapshot ids in the database and when running the report picking up the recent ids(begin snap and end snap).
From the sprepins.sql script
variable bid number;
variable eid number;
begin
select begin_snap into :bid from db_snap;
select end_snap into :eid from db_snap;
end;
This fails with the following error:
DB Name DB Id Instance Inst Num Release Cluster Host
RDMDEVL 3576140228 RDMDEVL 1 9.2.0.4.0 NO ibm-rdm
:ela := ;
ERROR at line 4:
ORA-06550: line 4, column 17:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
The symbol "null" was substituted for ";" to continue.
ORA-06550: line 6, column 16:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev su
But when I change the select statements below the report runs successfully.
variable bid number;
variable eid number;
begin
select '46' into :bid from db_snap;
select '47' into :eid from db_snap;
end;
Even changing the select statements to:
select TO_CHAR(begin_snap) into :bid from db_snap;
select TO_CHAR(end_snap) into :eid from db_snap;
Does not help.
Please Help.
TIA,
NischalHi,
could it be the begin_ and end_ Colums of your query?
Seems SQL*PLUS hs parsing problems?
try to fetch another column from that table
and see if the error raises again.
Karl -
Calling sql script from pl/sql block
Hi
I want to call a sql script from pl/sql block.
like
CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
as
begin
execute immediate '@ C:\Documents and Settings\umesh\emp.sql';
end DataBaseExport;
/Try something like this -
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host
public static void executeCommand(String command)
try {
String[] finalCommand;
if (isWindows())
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
else
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
new Thread(new Runnable()
public void run()
BufferedReader br_in = null;
try
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null)
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
catch (IOException ioe)
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
finally
try {
br_in.close();
} catch (Exception ex) {}
).start();
new Thread(new Runnable()
public void run()
BufferedReader br_err = null;
try
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null)
System.out.println("Process err :" + buff);
try
Thread.sleep(100);
} catch(Exception e) {}
br_err.close();
catch (IOException ioe)
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
finally
try
br_err.close();
catch (Exception ex) {}
).start();
catch (Exception ex)
System.out.println(ex.getLocalizedMessage());
public static boolean isWindows()
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
--- THE PERMISSIONS ---
call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
create or replace procedure call_sql_file(usr in varchar2,
pwd in varchar2,
host_str in varchar2)
is
begin
host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
exception
when others then
dbms_output.put_line(sqlerrm);
end;Now, you can pass all the argument in order to execute that file.
N.B.: Not Tested...
Regards.
Satyaki De. -
Fetching multiple values from XML node
Hi,
I have the below XML string / Data stored in one of a table column. I am trying to extract the values of ITEM_NAME node. using the query :
select extractvalue(xml_data, '/BILL/BILL_DTL/RECORD/ITEM_NAME') from XMLTable;
If i use this query i am getting the error as : ORA-19025 EXTRACTVALUE returns value of only one node
XML String / XML data
<BILL>
.....<BILL_NO>1000</BILL_NO>
.....<SRNO>3456</SRNO>
.....<BILL_DTL>
........<RECORD>
...........<LINE_NO>1</LINE_NO>
...........<ITEM_NAME>TOYOTA COROLLA</ITEM_NAME>
........</RECORD>
........<RECORD>
..........<LINE_NO>2</LINE_NO>
..........<ITEM_NAME>NISSAN CEDRIC</ITEM_NAME>
.......</RECORD>
.....</BILL_DTL>
</BILL>
The structure of the table is given below.
SQL> DESC XMLTABLE;
Column_Name ---------------Type
DOC_ID -------------------------NUMBER
XML_DATA --------------------XMLTYPE
What will be the query to fetch the values from the ITEM_NAME node.
Thanks & RegardsA late answer but just to show that it can be done with XMLTable (the built-in Oracle function) when you expect to return multiple rows from one input.
WITH XMLTable AS
(SELECT XMLTYPE('<BILL>
<BILL_NO>1000</BILL_NO>
<SRNO>3456</SRNO>
<BILL_DTL>
<RECORD>
<LINE_NO>1</LINE_NO>
<ITEM_NAME>TOYOTA COROLLA</ITEM_NAME>
</RECORD>
<RECORD>
<LINE_NO>2</LINE_NO>
<ITEM_NAME>NISSAN CEDRIC</ITEM_NAME>
</RECORD>
</BILL_DTL>
</BILL>') xml_data
FROM dual
SELECT item_name
FROM XMLTable,
XMLTable('/BILL/BILL_DTL/RECORD'
PASSING xml_data
COLUMNS
item_name VARCHAR2(25) PATH 'ITEM_NAME'
Returns
ITEM_NAME
TOYOTA COROLLA
NISSAN CEDRIC -
Fetch the values from internal table inside an internal table (urgent!!)
data : BEGIN OF PITB2_ZLINFO occurs 0,
BEGDA LIKE SY-DATUM,
ENDDA LIKE SY-DATUM,
PABRJ(4) TYPE N, "Payroll Year
PABRP(2) TYPE N, "Pay. Period
ZL LIKE PC2BF OCCURS 0,
END OF PITB2_ZLINFO.
I have a internal table like this,
How to Fetch the values from internal table inside an internal table.
Kindly Help me on this..
Regards,
Ram.Hi,
Try this....
Loop at PITB2_ZLINF0.
Loop at PITB2_ZLINF0-ZL.
endloop.
Endloop.
Thanks...
Preetham S -
How to retrieve the values from PL/SQL table types.
Hi Every one,
I have the following procedure:
DECLARE
TYPE t1 IS TABLE OF emp%ROWTYPE
INDEX BY BINARY_INTEGER;
t t1;
BEGIN
SELECT *
BULK COLLECT INTO t
FROM emp;
END;
This procedure works perfectly fine to store the rows of employee in a table type. I am not able to retrieve the values from Pl/SQL table and display it using dbms_output.put_line command.
Can anybody help me please!!!!!
Thanks
Ahmed.You mean, you can't add this
for i in t.first..t.last loop
dbms_output.put_line(t(i).empno||' '||t(i).ename||' '||t(i).job);
end loop;or you can't add this
set serveroutput onor maybe, you are working in third party application where dbms_output is not applicable at all?
You see, not able like very similar it is not working - both are too vague...
Best regards
Maxim -
Retreiving a value from and SQL query
If anyone can give me sample code or pointers to retreive a value from an sql query, I'd be greatful.
Source code I've muddled together so far:
Class seqNumType = Class.forName(nameOfClass);
Constructor theConstructor = seqNumType.getConstructor(null);
Object seqNumInstance = theConstructor.newInstance(null);
String theStatement = "SELECT value INTO v_seqnum FROM DUAL;";
OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall(theStatement);
ocs.registerOutParameter( 1, OracleTypes.NUMBER, 0);
Method method = seqNumInstance.getClass().getMethod("getORADataFactory", null);
seqNumInstance = ocs.getORAData(1, (ORADataFactory)method.invoke(null,null));
ocs.execute();
Problem with this seems to be the ORADataFactory isn't a method of the class, but as I'm thumbling around in the dark here a little, I've no idea where to go from here. Is this just generally overkill anyway?
Suggestions?
Cheers for any help.Like this:
ResultSet resultSet=statement.executeQuery("SELECT * FROM TEST");
while(resultSet.next())
for(int i=0;i<resultSet.getMetaData().getColumnCount();i++)
System.out.print(resultSet.getObject(i+1).toString()+" ");
System.out.println(); -
Is it possible to call a windows batch file from PL/SQL block ??
Hi gurus,
Would require your help.Is it possible to call a windows batch file from PL/SQL block ??If yes can you give an example for the same or any workaround for the same.
Regards
VijayYou didn't specify a database version, but if you are 10g or higher, it's quite straightforward using an external job type in DBMS_SCHEDULER. Funnily enough i'm looking at something similar myself at the moment.
Useful guide to some of the issues here Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files -
Running sqlldr command from PL/SQL Block
DECLARE
BEGIN
END;In SQL * plus we can run DOS commands using the following command
HOST DIR
HOST DIR/P
But When we can't run the HOST command in PL/SQL Block..
I have to Run sqlldr command from PL/SQL Block..
i tried as follows
DECLARE
BEGIN
EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
END;
By
BalaNagaRaju -
Exec SQLPLUS command from PL/SQL Block
Good Morning:
How I can execute a SQLPLUS command (like SPOOL or DESCRIBE) from PL/SQL Block Procedure?:
DECLARE
BEGIN
ls_command = 'DESCRIBE '||ls_table_name;
EXECUTE SQLPLUS(ls_command);
END;
Thanks a lot for any idea.That's correct.
However, in the case of the given example we can use DBMS_DESCRIBE package to get table descriptions. And we can use UTL_FILE to spool PL/SQL stuff to a file.
Cheers, APC -
Bind Variable in SELECT statement and get the value in PL/SQL block
Hi All,
I would like pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
Please seee below
I want to get the below value
Expected result:
select distinct empno ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
100, HR
select distinct ename ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
TEST, HR
select distinct loc ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
NYC, HR
Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
Please suggest
----- TABLE LIST
CREATE TABLE EMP(
EMPNO NUMBER,
ENAME VARCHAR2(255),
DEPT VARCHAR2(255),
LOC VARCHAR2(255)
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
COMMIT;
CREATE TABLE COLUMNAMES(
COLUMNAME VARCHAR2(255)
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
COMMIT;
CREATE TABLE DEPT(
DEPT VARCHAR2(255),
DNAME VARCHAR2(255)
INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
COMMIT;
PL/SQL BLOCK
DECLARE
TYPE EMPCurTyp IS REF CURSOR;
v_EMP_cursor EMPCurTyp;
l_col_val EMP.ENAME%type;
l_ENAME_val EMP.ENAME%type;
l_col_ddl varchar2(4000);
l_col_name varchar2(60);
l_tab_name varchar2(60);
l_empno number ;
b_l_col_name VARCHAR2(255);
b_l_empno NUMBER;
begin
for rec00 in (
select EMPNO aa from EMP
loop
l_empno := rec00.aa;
for rec in (select COLUMNAME as column_name from columnames
loop
l_col_name := rec.column_name;
begin
l_col_val :=null;
l_col_ddl := 'select distinct :b_l_col_name ,pr.dept ' ||' from emp pr, dept ps where ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
dbms_output.put_line('DDL ...'||l_col_ddl);
OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
LOOP
l_col_val :=null;
FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
EXIT WHEN v_EMP_cursor%NOTFOUND;
dbms_output.put_line('l_col_name='||l_col_name ||' empno ='||l_empno);
END LOOP;
CLOSE v_EMP_cursor;
END;
END LOOP;
END LOOP;
END;user1758353 wrote:
Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
However, the data structures are just that - structured. Logical.
Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model. -
PL/SQL 10g - Cannot Insert Values from PL/SQL
Hi People,
BACKGROUND (if required):
I'm trying to write a message threading algorithm for uni, I believe it works so far, it's just matching the subjects at the moment I want to expand it to include email addresses but that will be at a later date.
A brief run down, at the moment, a user can generate a list of email addresses to filter the corpus with, these are then inserted (via Java) into the table Sender. These addresses are then used in an IF statement, however they are only used if the table sender is populated. The messges that are identified as threads have their Message ID inserted into another table but they also have their values printed to the DBMS output.
QUESTION:
What I need help with is although the values print out to the DBMS Output after a great deal of time, normally after the DBMS buffer has maxed out (thus the statement ends in error). The values printed are not inserted into the table.
Any help on solving this or optimising if would be greatly appreciated, I'm new to PL/SQL i'm afraid so it's probably a really messy statement.
If this is a badly worded question and I need to supply more information then I gladly will, however i'm not 100% on what information is relevant at the moment.
Below is the statement in question.
Thanks and Regards,
K
LOOP
IF sender_cur1%FOUND THEN
IF sub_One = Sub_two and sub_One_MID != sub_Two_MID and Sub_One_Sender = send_user_cur THEN
INSERT INTO MATCHING_SUB (MID) VALUES (sub_Two_MID);
dbms_output.put_line('MID is: ' || sub_Two_MID);
END IF;
ELSE
IF sub_One = Sub_two and sub_One_MID != sub_Two_MID THEN
INSERT INTO MATCHING_SUB (MID) VALUES (sub_Two_MID);
dbms_output.put_line('MID is: ' || sub_Two_MID);
END IF;
END IF;
Edited by: user8967525 on 01-Mar-2010 07:27
Edited by: user8967525 on 01-Mar-2010 08:08cd,
I will most certainly try.
I have a table of emails that I am attempting to thread by means of comparing the subjects together (for now). However ultimately I want to be able to bring in the recipients as well. However this can be ignored for now.
The main variables from the Messages table are:
MID(number) - 0 - 245000
SENDER(VARCHAR) - Email Address
SUBJECT_CLN6 - VARCAHR - Cleaned email subject.
I am creating two instancs of a cursor that contains the subjects and MID's from Messages. I am then looping through cur1 comparing the value against all values in cur2, this continues until all values in cur1 have been compared against cur2. I use the MID to ensure that I am not comparing the same Message. Furthermore I am also filtering the Emails by Sender (if the table has been populated by the user, via a java applet, otherwise if just uses the subject). The variable Send_User_Cur takes takes its values from the Table called Sender, whilst sub_one_sender takes its values from the column Sender in Messages.
The proposed output of this at the moment is to just have the MID's (and later all the relevant columns, however just for now MID) of all the threaded emails, inserted into the table MATCH_THREAD, such that they can be called upon later for further processing and most likely called from a java applet at some point as well.
I've pasted the entire code below. I understand that it looks a bit messy on the preview and for that I apologise.
Thanks all!
Kev
DECLARE
CURSOR sub_cur1 IS
SELECT MID, Sender, trim(subject_cln6) from MESSAGES;
sub_One MESSAGES.subject_cln6%TYPE;
sub_One_MID MESSAGES.MID%type;
sub_One_Sender MESSAGES.SENDER%type;
CURSOR sub_cur2 IS
SELECT MID, trim(subject_cln6) from Messages;
sub_Two MESSAGES.subject_cln6%TYPE;
sub_Two_MID MESSAGES.MID%type;
CURSOR sender_cur1 IS
SELECT SENDER_ID FROM SENDER;
Send_User_Cur SENDER.SENDER_ID%type;
counter number := 0;
MID_t MESSAGES.MID%TYPE;
i number := 0;
j number := 0;
BEGIN
SELECT count(subject) INTO counter
FROM MESSAGES;
OPEN sub_cur1;
OPEN sub_cur2;
OPEN sender_cur1;
FETCH sub_cur1 INTO sub_One_MID, Sub_One_Sender, Sub_One;
FETCH sender_cur1 INTO Send_User_Cur;
WHILE sub_cur1%FOUND
LOOP
IF sub_cur2%ISOPEN THEN
FETCH sub_cur2 INTO sub_Two_MID, SUB_Two;
dbms_output.put_line('OPEN');
ELSE
OPEN sub_cur2;
FETCH sub_cur2 INTO sub_Two_MID, SUB_Two;
--dbms_output.put_line('OPENED and FETCHED');
END IF;
LOOP
IF sender_cur1%FOUND THEN
IF sub_One = Sub_two and sub_One_MID != sub_Two_MID and Sub_One_Sender = send_user_cur THEN
INSERT INTO MATCH_THREAD (MID) VALUES (sub_Two_MID);
commit;
END IF;
ELSE
IF sub_One = Sub_two and sub_One_MID != sub_Two_MID THEN
INSERT INTO MATCH_THREAD (MID) VALUES (sub_Two_MID);
commit;
END IF;
END IF;
FETCH sub_cur2 INTO sub_Two_MID, SUB_Two;
i := i + 1;
EXIT WHEN i = counter;
END LOOP;
CLOSE sub_cur2;
FETCH sub_cur1 INTO sub_One_MID, Sub_One_Sender, SUB_One;
i := 0;
dbms_output.put_line('sub_One_MID: ' || sub_one_mid);
END LOOP;
CLOSE sub_cur1;
CLOSE sub_cur2;
END; -
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 ==================================================== -
Display an Alert message from PL/SQL block in APEX
Hi,
we are getting an oracle exception while inserting a new row. As it is having the unique constaint on a coulumn.
Now the problem iis we need to Display an "Alert message" based on the input field validation. That java script code for alert has to be embeded nside a PL/SQL block in Oracle APEX Application.
we tried doing this with below code:
Begin
INSERT INTO <<table name>>(ID,NAME) VALUES (s1,:TXT_s2);
exception when others then
htp.p('<script language="javascript">');
htp.p('alert("Exception");');
htp.p('</script>');
end;
If anybody knows .... please reply.
Thanks,
SubarnaIf your end goal is showing a pretty error message instead of the message that the tables unique constraint raises try the following. This logic will show a nice message and not try to insert non-unique data.
(1) Create a validation of type "Function Returning Error Text".
(2) Place similar code like the following in your validation. Notice that if the unique name does not exist the no_data_found returns null allowing the validation to pass.
DECLARE
v_error varchar2(100);
BEGIN
SELECT 'A person by this name already exists.'
INTO v_error
FROM your_table
WHERE your_name = :P1_YOUR_NAME;
RETURN v_error;
EXCEPTION
WHEN no_data_found THEN
RETURN NULL;
END;
Maybe you are looking for
-
Whenever I have my shuffle on and I place my ipod on my waist, arm, backpack or whatever it may be, the song will change about 20-30 seconds into the song. It does this each and every song UNLESS I hold it in my hand practically still when I'm moving
-
The all new iBooks 2 has been released today, with quite a compelling array of features for students. I've watched a few videos, among those the introducory video from Apple, and one of the features that appealed to me most is the Study Cards feature
-
Grub2 can't see partition on a MBR drive but can on GPT drives
I have three hdds, the first two are formatted with GPT and the third MBR so as to boot windows when needed. I have grub2 installed on /dev/sda and I can boot my Arch partitions just fine. I can't however boot the windows partition (/dev/sdc1). I
-
Error code 1611 can anyone help
hi their just got my iphone 4 home then tried to sync with my hp laptop then get this error code 1611 can anyone help thanks
-
There is no iView available for system "SAP_SRM": object "po".
Hi, We are on SRM 7.0. We get the below mentioned error after selecting the PO in "Purcahsing view" and clicking on EDIT button to chnage the selected PO: There is no iView available for system "SAP_SRM": object "po". For more information, contact yo