Anonymous Block Help
Hi all,
DECLARE
TYPE TEST_ARRAY IS TABLE OF EMPLOYEE%ROWTYPE;
V_DATA TEST_ARRAY;
CURSOR C1 IS
SELECT * FROM EMPLOYEE;
BEGIN
OPEN C1 ;
LOOP
FETCH C1 BULK COLLECT INTO V_DATA LIMIT 1000;
FORALL I IN 1..V_DATA.COUNT
NULL;--DBMS_OUT
EXIT WHEN C1%NOTFOUND ;
END LOOP;
CLOSE C1;
END;
Here i how can display the cursor value
Regards,
Fame
You cannot use FORALL for this.. Refer the documentation for FORALL
If you want to try BULK COLLECT you can use like below (for learning purpose), otherwise just loop through the table and print.
declare
type test_array is table of employee%rowtype;
v_data test_array;
cursor c1 is
select * from employee;
begin
open c1 ;
loop
fetch c1 bulk collect into v_data limit 1000;
for i in 1..v_data.count loop
dbms_output.put_line(v_data(i).EMPNO);
end loop;
exit when c1%notfound ;
end loop;
close c1;
end;
Similar Messages
-
hi friends
I am trying to develop anonymous block which display the message on screen like "hello world" "today is SYSDATE" and "Tommorow is SYSDATE+1".For that i try to develop anonymous block but it shows me error..so friends can you help me out with this...
set SERVEROUTPUT on
declare
p_text varchar2 DEFAULT 'hello world';
P_date date Default sysdate;
P_next_date date default sysdate+1;
begin
DBMS_OUTPUT.PUT_LINE (||P_text);
DBMS_OUTPUT.PUT_LINE ('today is:'||P_date);
DBMS_OUTPUT.PUT_LINE ('Tommorrow is:'||p_next_date);
end;
thanks in advance
rommyHi, Rommy,
Always format your code. Indent to show the major sections (DECLARE, BEGIN, etc.)
Type these 6 characters
{code}
(small letters only, inside curly brackets) before and after formatted text, to preserve spacing when posting on this site.
DECLARE
p_text VARCHAR2 (50) DEFAULT 'hello world';
P_date DATE DEFAULT SYSDATE;
P_next_date DATE DEFAULT SYSDATE + 1;
BEGIN
DBMS_OUTPUT.PUT_LINE (P_text);
DBMS_OUTPUT.PUT_LINE ('today is: ' || TO_CHAR (P_date, 'Dy DD-Mon-YYYY'));
DBMS_OUTPUT.PUT_LINE ('Tommorrow is: ' || TO_CHAR (p_next_date, 'Dy DD-Mon-YYYY'));
END;
/When you declare a VARCHAR2 variable, you have to specify the maximum length.
The || operator is used between two string expressions; it looks like you forgot the first operand in one place.
Using a DATE where a VARCHAR2 is expected (as an operand to ||, for example) is not technically an error, but it's bad practice. Use TO_CHAR to create a string in whatever format you want. -
Help!! how to call pl/sql anonymous block from java?
I know that jdbc can call a pl/sql package or procedure,but if i
want to call a pl/sql anonymous block, how can i do it? no procedure
name or package name will be offered.
Can u give me a sample code? thanks very muchthanks ,but do u make sure that it can work? i have tried to do like this ,but i can not get it. Or please give me a detail code, thanks very much
-
Need help displaying item based on pl/sql anonymous block
This is probably something really simple but I'm stuck.....
On purchase order, I want to show related parent project name and ID. What is the best way to do it? I have created a region based on pl/sql anonymous block, and that works, but the data is above where I want it. I want the project name and ID to show up in the region w/ all the other fields.
I have created an item in the region that has other form fields, item is based on pl/sql anonymous block, w/ same code as above region, and the item doesn't find the data. What's the difference? Is it because the item doesn't save state? In order to choose for the item to be based on pl/sql anon block, APEX made me choose Display as Text (based on PLSQL, does not save state).
Please see this picture:
http://farm3.static.flickr.com/2391/2658673285_04f157a3fa_o.png
thanks!
~Darbythis is weird.. Now it is working. I didn't change anything! What the heck?
http://farm3.static.flickr.com/2010/2659557520_73e54b67ea_o.png -
Getting value with an anonymous block using ODP
Hi all!
I have a problem I hope someone can help me with. I believe it to be a minor one. I am trying to imbed an anonymous block into my .net app and use it dynamically to get a value from the database depending on the values in a tables. Since my procedure is quite large I am displaying a small example proc for simplicity purposes. Basically I want to execute an anonymous block from my app that will return a value (not a row or rows) from the database. The code is below:
Private Sub test()
Dim cn As New OracleConnection(profileString)
Try
Dim sb As New System.Text.StringBuilder
sb.Append("Declare ")
sb.Append("v_maxnum varchar2(6); ")
sb.Append("Begin ")
sb.Append("Select max(to_number(email_address_id)) into ")
sb.Append("v_maxnum from CVWH14_CDRV_TEST.EMAIL_ADDRESS_TBL; ")
sb.Append("dbms_output.put_line(v_maxnum); ")
sb.Append("Exception ")
sb.Append("When Others ")
sb.Append("Then ")
sb.Append("dbms_output.put_line('Program run errors have occurred.'); ")
sb.Append("End; ")
Dim cmd As New OracleCommand(sb.ToString, cn)
With cmd
cmd.CommandType = CommandType.Text
Dim parm As New OracleParameter
parm.ParameterName = "v_maxnum"
parm.OracleType = OracleType.VarChar
parm.Direction = ParameterDirection.Output
parm.Size = 6
cmd.Connection.Open()
Dim ret As Object = cmd.ExecuteScalar()
Dim res As String = cmd.Parameters.Item(0).Value.ToString -- **Error is occuring here**
cmd.Connection.Close()
cmd.Dispose()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
'End If
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
The exception error reads "Invalid Index 0 for this OracleParameterCollection with Count=0."
If I can figure out how to get a parameter value from the database via the anonymous block, I can apply the logic to the real application. Any help or direction I could receive would be greatly appreciated. Thanks for reading this post!Thank you for responding. The code that I posted was just one of many ways I have tried. I retried the proc making just 2 changes:
Private Sub test()
Dim cn As New OracleConnection(profileString)
Try
Dim sb As New System.Text.StringBuilder
sb.Append("Declare ")
sb.Append("v_maxnum varchar2(6); ")
sb.Append("Begin ")
sb.Append("Select max(to_number(email_address_id)) into ")
sb.Append("v_maxnum from CVWH14_CDRV_TEST.EMAIL_ADDRESS_TBL; ")
sb.Append("dbms_output.put_line(:v_maxnum); ") -- !Changed this to a bind variable!
sb.Append("Exception ")
sb.Append("When Others ")
sb.Append("Then ")
sb.Append("dbms_output.put_line('Program run errors have occurred.'); ")
sb.Append("End; ")
Dim cmd As New OracleCommand(sb.ToString, cn)
With cmd
cmd.CommandType = CommandType.Text
Dim parm As New OracleParameter
parm.ParameterName = ":v_maxnum" -- !Changed this to a bind variable!
parm.OracleType = OracleType.VarChar
parm.Direction = ParameterDirection.Output
parm.Size = 6
cmd.Connection.Open()
Dim ret As Object = cmd.ExecuteScalar() -- !The error is now occuring here!
Dim res As String = cmd.Parameters.Item(0).Value.ToString
cmd.Connection.Close()
cmd.Dispose()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
I am now getting the error message "Not all variables bound". Any more help or direction that you could throw my way would be greatly appreciated. -
Performance problem due to anonymous blocks
Hi,
One of the users on our database has created a procedure consisting of many blocks like the one given below:
begin
select func1(var1,var2,var3)into vcompvalue from dual;
if vcompvalue < 0 then
vcompvalue := 0;
end if;
exception when no_data_found then
vcompvalue := 0;
end;
The procedure takes a long time to execute.Instead of writing a block, will writing SQL%NOTFOUND instead of the exception and merging the blocks with rest of the code improve performance?
Thanks for the help!
Vinayak ThatteI would guess it might; you'd be cutting down the number of PL/SQL clauses that have to be parsed, etc, so if you have enough anonymous blocks you may see a difference.
On a more specific note can I just ask why you're checking for NO_DATA_FOUND? If DUAL ever throws this exception you've got serious problems with your database. If it's being thrown by your FUNC1 you might be better off (from a performance point of view) handling that exception within the function.
rgds, APC -
How to use anonymous block in select statement
Hello Experts.
I have one requirement which i can resolve using anonymous block in plsql. But i want implement it in select query only.
Database: Oracle 11.2.0
select count(*) from emp where name='xyz' and sal=50
if count(*)>0
then
select dept,sector from emp where name='xyz' and sal=50
here i dont have any primary key.
How can i achieve above using sql query not plsql. Here is one sloution which i have got but its not satisfying above requiremnt as i dont have any primary key columns
select toll_number from toll_details
where toll_id =(select toll_id from toll_details where toll_new_id='5263655214' group by toll_id having count(*)>0)
here toll_id is primary key, so used group by. But how to do this in my above requirement as i dont have primary key.
Appreciate any help on this.
Thank you897112 wrote:
Hello Experts.
I have one requirement which i can resolve using anonymous block in plsql. But i want implement it in select query only.
Database: Oracle 11.2.0
select count(*) from emp where name='xyz' and sal=50
if count(*)>0
then
select dept,sector from emp where name='xyz' and sal=50
here i dont have any primary key.
How can i achieve above using sql query not plsql. Here is one sloution which i have got but its not satisfying above requiremnt as i dont have any primary key columns
select toll_number from toll_details
where toll_id =(select toll_id from toll_details where toll_new_id='5263655214' group by toll_id having count(*)>0)
here toll_id is primary key, so used group by. But how to do this in my above requirement as i dont have primary key.
Appreciate any help on this.
Thank youTry this
SQL> create table plch_test(id number,name varchar2(20),sal number);
Table created.
SQL> insert into plch_test values(1,'XYZ',50);
1 row created.
SQL> insert into plch_test values(2,'AAA',100);
1 row created.
SQL> insert into plch_test values(3,'BBB',200);
1 row created.
SQL> insert into plch_test values(4,'CCC',400);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from plch_test;
ID NAME SAL
1 XYZ 50
2 AAA 100
3 BBB 200
4 CCC 400
SQL> ed
Wrote file afiedt.buf
1 select id,name
2 from plch_test a
3 where 1=(select count(*) from plch_test b where a.id=b.id)
4* and id=&id
SQL> /
Enter value for id: 2
old 4: and id=&id
new 4: and id=2
ID NAME
2 AAA
SQL> /
Enter value for id: 0
old 4: and id=&id
new 4: and id=0
no rows selectedHope this helps!!!
Regards,
Achyut -
Autonomous Transactions usage in PL/SQL anonymous block coding
Hi,
I am trying to incorporate Autonomous Transaction for our work. I am using the tables provided below,
CREATE TABLE T1
F1 INTEGER,
F2 INTEGER
CREATE TABLE T2
F1 INTEGER,
F2 INTEGER
insert into t1(f1, f2)
values(20, 0)
insert into t2(f1, f2)
values(10, 0)
Now, when I use the code snippet given below, it is working as expected.
create or replace procedure p1 as
PRAGMA AUTONOMOUS_TRANSACTION;
begin
update t2
set f2 = 25
where f1 = 10;
commit;
end;
declare
PRAGMA AUTONOMOUS_TRANSACTION;
a integer;
begin
update t1
set f2 = 15
where f1 = 20;
p1();
rollback;
end;
Here, updation in t2 table is commited and t1 is rolled back, it is working as
expected. I would like to achieve the same functionality through PL/SQL
anonymous block coding, to do this, I use the following code snippet,
declare
PRAGMA AUTONOMOUS_TRANSACTION;
a integer;
begin
update t1
set f2 = 15
where f1 = 20;
begin
update t2
set f2 = 35
where f1 = 10;
commit;
end;
rollback;
end;
Here, data in both the tables are commited, how do I change it to work as I
mentioned above like committing t2 alone, please help, thank you.
Regards,
DevaCan you explain what you're trying to accomplish from a business perspective? This doesn't look like a particularly appropriate way to use autonomous transactions, so you may be causing yourself problems down the line.
That said, padders's solution does appear to work for me
SCOTT @ nx102 Local> CREATE TABLE T1
2 (
3 F1 INTEGER,
4 F2 INTEGER
5 )
6 /
Table created.
Elapsed: 00:00:01.03
SCOTT @ nx102 Local>
SCOTT @ nx102 Local>
SCOTT @ nx102 Local> CREATE TABLE T2
2 (
3 F1 INTEGER,
4 F2 INTEGER
5 )
6 /
Table created.
Elapsed: 00:00:00.00
SCOTT @ nx102 Local>
SCOTT @ nx102 Local> insert into t1(f1, f2)
2 values(20, 0)
3 /
1 row created.
Elapsed: 00:00:00.01
SCOTT @ nx102 Local>
SCOTT @ nx102 Local> insert into t2(f1, f2)
2 values(10, 0)
3 /
1 row created.
Elapsed: 00:00:00.01
SCOTT @ nx102 Local> commit;
Commit complete.
Elapsed: 00:00:00.01
SCOTT @ nx102 Local> DECLARE
2 a INTEGER;
3
4 PROCEDURE update_t2
5 IS
6 PRAGMA AUTONOMOUS_TRANSACTION;
7 BEGIN
8 UPDATE t2
9 SET f2 = 35
10 WHERE f1 = 10;
11
12 COMMIT;
13 END update_t2;
14 BEGIN
15 UPDATE t1
16 SET f2 = 15
17 WHERE f1 = 20;
18
19 update_t2;
20
21 ROLLBACK;
22 END;
23 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.04Have you done something else that would cause a deadlock?
Justin -
Calling a function which has a CLOB parameter via an anonymous block.
OK,
we are moving a lot of exports currently done by Crystal to just be done by stored procs.
So we have a load of existing, some extremely length SQL statements used for these exports.
IN the exports, we have meaningful column headings, so we have a 'lookup' file where all the column names are listed with the desired column name text listed against it.
So - to make our lives easier(i thought) , I have written a Oracle function to extract al;l of the column names as a list (see below).
It works fine except for when I am trying to pass in a SQL treatment that is longer than 4000 character.
What I want to be able to do is simply have an anonymous block that callls my function, I will be running this via SQL explorer.
Something like......
DECLARE
theSQL CLOB;
BEGFIN
theSQL := 'SELECT * FROM ORDERS WHERE 1=0';
SELECT GET_COLUNS_AS_LIST( theSQL, 0 ) FROM DUAL;
END;
However, when I run this I get the error................
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
If I hard code the SQL like this, SELECT GET_COLUNS_AS_LIST( 'SELECT * FROM ORDERS WHERE 1=0', 0 ) FROM DUAL; all is well.
Also, I am going to need to be able to pass in SQL ststement longer that 4000 characters as weel so please bear that in mind.
I am not an Oracle guy, so I guess I am missing something fundamental - Please enlighten me with regards to this.
Any help extremely appreciated.
CREATE OR REPLACE FUNCTION GET_COLUNS_AS_LIST( P_SQL IN VARCHAR2, Add_Equals_Sign Number := 0)
RETURN CLOB
IS
fResult VARCHAR2(32000);
HNDL NUMBER;
d NUMBER;
colCount INTEGER;
i INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
cCRLF VARCHAR(2) := CHR(13) || CHR(10);
LONG_SQL dbms_sql.varchar2s;
n INTEGER;
l INTEGER;
u INTEGER;
StartPos INTEGER;
BEGIN
--INITIIALISE RESULT
fResult := '';
HNDL := DBMS_SQL.OPEN_CURSOR;
l := Length( P_SQL );
u := ( l / 1000 ) + 1;
FOR n IN 1..u
LOOP
StartPos := ( n - 1 ) + 1;
LONG_SQL( n ) := SubStr( P_SQL, StartPos, 1000 );
END LOOP;
if HNDL <> 0 THEN
DBMS_SQL.PARSE ( c => HNDL,
statement => LONG_SQL,
lb => 1,
ub => u,
lfflg => false,
language_flag => DBMS_SQL.NATIVE );
--DBMS_SQL.PARSE( HNDL, P_SQL, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE( HNDL );
DBMS_SQL.DESCRIBE_COLUMNS( HNDL, colCount, rec_tab);
FOR i in 1..colCount
LOOP
IF Add_Equals_Sign > 0 AND i > 1 THEN
fResult := ltrim( fResult || '=' || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
ELSE
fResult := ltrim( fResult || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
END IF;
END LOOP;
IF Add_Equals_Sign > 0 THEN
fResult := fResult ||'=';
END IF;
ELSE
fResult := '!!COULD NOT OPEN CURSOR!!';
fResult := P_SQL;
END IF;
RETURN fResult;
--Tidy Up
DBMS_SQL.CLOSE_CURSOR(HNDL);
Return 'EGG';
END;
--EXAMPLE USAGE
--Select GET_COLUNS_AS_LIST
--Select * from SALES_TYPE
--', 1) FROM DUAL;So I have ended up with this.
When I next get some time, I'd like to be able to strip out the table and simply output the results to an SQL Developer script window without having to go through the table.
Now this works - but if you see that I am doing something wrong - please point it out.
Many thanks,
Ant
CREATE OR REPLACE FUNCTION GET_COLUNS_AS_LIST( P_SQL IN CLOB, Add_Equals_Sign Number := 0)
RETURN VARCHAR2
IS
fResult VARCHAR2(32000);
HNDL NUMBER;
d NUMBER;
colCount INTEGER;
i INTEGER;
ChunkSize INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
cCRLF VARCHAR(2) := CHR(13) || CHR(10);
LONG_SQL dbms_sql.varchar2s;
n INTEGER;
l INTEGER;
u INTEGER;
StartPos INTEGER;
BEGIN
--INITIIALISE RESULT
HNDL := 0;
ChunkSize := 4;
fResult := '';
--fResult := fResult|| 'A';
HNDL := DBMS_SQL.OPEN_CURSOR;
--l := Length( P_SQL );
l := dbms_lob.getLength( P_SQL );
--l := 50;
u := Round( l / ChunkSize ) + 1;
--fResult := fResult|| 'B';
FOR n IN 1..u
LOOP
StartPos := ( ( n - 1 ) * ChunkSize ) + 1;
IF StartPos = 0 THEN
StartPos := 1;
END IF;
--LONG_SQL( n ) := SubStr( P_SQL, StartPos, ChunkSize );
LONG_SQL( n ) := DBMS_LOB.SUBSTR( P_SQL, ChunkSize, StartPos );
END LOOP;
--fResult := fResult|| 'C';
if HNDL <> 0 THEN
DBMS_SQL.PARSE ( c => HNDL,
statement => LONG_SQL,
lb => 1,
ub => u,
lfflg => false,
language_flag => DBMS_SQL.NATIVE );
--DBMS_SQL.PARSE( HNDL, P_SQL, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE( HNDL );
DBMS_SQL.DESCRIBE_COLUMNS( HNDL, colCount, rec_tab);
--fResult := fResult|| 'D';
FOR i in 1..colCount
LOOP
IF Add_Equals_Sign > 0 AND i > 1 THEN
fResult := ltrim( fResult || '=' || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
ELSE
fResult := ltrim( fResult || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
END IF;
END LOOP;
IF Add_Equals_Sign > 0 THEN
fResult := fResult ||'=';
END IF;
ELSE
fResult := '!!COULD NOT OPEN CURSOR!!';
END IF;
RETURN fResult;
--Tidy Up
IF HNDL <> 0 THEN
DBMS_SQL.CLOSE_CURSOR(HNDL);
END IF;
END;
-- !!!!HOW TO USE THIS FUNCTION!!!!
BEGIN
EXECUTE IMMEDIATE ('DROP TABLE RPT_COLNAME_LOOKUPS;');
COMMIT;
EXECUTE IMMEDIATE ('CREATE TABLE RPT_COLNAME_LOOKUPS( COLUMN_NAME CLOB );');
COMMIT;
EXCEPTION WHEN OTHERS THEN NULL;
END;
DECLARE
theSQL Clob;
myresult CLOB;
BEGIN
--CLEAR OUT PREVIOUS RWS
DELETE FROM RPT_COLNAME_LOOKUPS; COMMIT;
--ASSIGN THE SQL TO RUN IT FOR
theSQL := '
SELECT
EVENT.EVENT_ID AS COCK_SUCKER,
EVENT.EVENT_CODE, BLAH, BLAH, VERY LONG SQL STATEMENT';
--CALL THE FUNCTION PASSING IN THE SQL AND IF I WANT THE = OR NOT
SELECT GET_COLUNS_AS_LIST( theSQL, 1 ) INTO myresult FROM DUAL;
--INSERT THE RESULTS INTO A TABLE SO WE CAN GRAB THEM
INSERT INTO RPT_COLNAME_LOOKUPS SELECT myresult FROM DUAL;
COMMIT;
END;
--THEN LOOK AT THE COLUMNS NAMES IN THIS TABLE
--SELECT * FROM RPT_COLNAME_LOOKUPS;
--############################################################################# -
Anonymous Block in SQL Developer
I am using SQL Developer 3.1x and trying to run a pretty simple Anonymous block and am having trouble declaring a variable. This block runs successfully:
set SERVEROUTPUT on
--declare
-- V_CRT := CHR(13);
begin
for t in (select owner, table_name from dba_tables where owner = 'ABC123)
LOOP
DBMS_STATS.GATHER_TABLE_STATS(t.owner, t.table_name);
end loop;
DBMS_OUTPUT.PUT_LINE('Statistics Calculations complete');
DBMS_OUTPUT.PUT_LINE('Begin Record Counts');
-- DBMS_OUTPUT.PUT_LINE(v_crt);
-- DBMS_OUTPUT.PUT_LINE(V_CRT);
end;
If I remove my comments in an effort to include my Declare statement, I receive: PLS-00103: Encountered the symbol "=" when expecting one of the following
How do I declare / initialize the variable "v_crt"? Admittedly this is a VERY basic Block but I just started to build out a more "robust" procedure and am getting stumped.
Thank you for your help!The symbol *:=* is for assignment, not variable declaration. Just give the variable name and then its type, like this:DECLARE
V_CRT VARCHAR2(13);You can give it a default value if you want to.DECLARE
V_CRT VARCHAR2(13) := 'Hello';Looks like you want it to be a carriage return character.DECLARE
V_CRT VARCHAR2(1) := CHR(13); -
Hey everyone. I'm fairly new to the SQL world and this is my first time posting on any forum for help with coding. I have an assignment and I'm supposed to construct an anonymous block. I am using sqldeveloper and I am trying to run the following:
--declare+
begin
if sysdate between to_date('05:00:00 PM', 'HH:MI:SS PM') and to_date('09:00:00 AM', 'HH:MI:SS AM') then
DBMS_OUTPUT.PUT_LINE ('Can only be used during normal office hours of 9-5.');
end if;
end;
When I run the entire script, there are no errors. However, I can't seem to get any output. Could someone perhaps give me some direction on what I'm doing wrong?
Cheers for any help.
-AslanWell that explains a whole lot. Is there some way to actually have it so that sysdate only concerns itself with time?No, in Oracle a DATE type always contains a date and time to the nearest second.
However, you can use to_char and extract what you need:
SQL> select sysdate, to_char(sysdate,'HH24:MI:SS') from dual;
SYSDATE TO_CHAR(
27-MAR-2009 20:42:08 20:42:08
SQL> select sysdate, to_char(sysdate,'HH24') from dual;
SYSDATE TO
27-MAR-2009 20:42:40 20The first one extracts the entire time portion, the second only extracts the hours. -
The output is always "anonymous block completed"
Hi ,
I have written a simple Stored Procedure as shown :
create or replace procedure display
ename out emp.ename%type
is
begin
select ename into ename from emp where empno='7369';
end;
I tried to execute the above using this block
declare
ename emp.ename%type;
begin
display(ename);
dbms_output.put_line(ename);
end;
I am always getting the Output as "anonymous block completed" and nothing else .
Please help . Thanks .Hi:
First type this to enable the output.
SET SERVEROUTPUT ON;Saad, -
Need an anonymous block for fake update,
I have a table called sk_a
create table sk_a (a number, b date, c varchar2(10));
and an audit table
create sk_a_audit (audit_id number, a number, b date, c varchar2(10),dml_action varchar2(4));
and sequence sk_a_audit_seq
create sequence sk_a_audit_seq
when any insert or update happens into sk_a table, respective data should insert into sk_a_audit table
and trigger is
CREATE OR REPLACE TRIGGER SK_A_TRG
AFTER INSERT OR UPDATE
ON SK_A
FOR EACH ROW
DECLARE
l_code NUMBER;
l_errm VARCHAR2 (64);
BEGIN
IF (INSERTING OR UPDATING)
THEN
INSERT INTO SK_A_audit
VALUES (sk_a_audit_seq.NEXTVAL, :NEW.a,
:NEW.B, :NEW.C ,'I');
END IF;
EXCEPTION
WHEN OTHERS
THEN
l_code := SQLCODE;
l_errm := SUBSTR (SQLERRM, 1, 64);
DBMS_OUTPUT.put_line ('DML Operation is failed ' || l_code || l_errm);
END;
sk_a may or maynot have primary or unique keys,
now my requirement is
audit table will be deleted by business users,,
and then I have to run an update on sk_a table (fake update) so that data will come and insert into audit table,,,,
so that audit table will be back with all the data of sk_a table again,
I need an anonymous block for this, can any one help on this,audit table will be deleted by business users,,
and then I have to run an update on sk_a table (fake update) so that data will come and insert into audit table,,,,
so that audit table will be back with all the data of sk_a table again,
I need an anonymous block for this, can any one help on this,Y? audit table was deleted by busineess users..? could u pls explain it..?
if u know that users going to delete the audit table, then take the back of the table. that is better instead of fake update.
U can use exp utility for taking that back up
Pls reply
S -
Customize the Anonymous Block.
Hi All,
DB - Oracle 9.2.0.1.0
With the help of you Guys , I am able to create the Anonymous block.But, In the following BLOCK, I need to add One more functionality, if someone needs to grant "create view" privilge inside the block , then the massage should be " No direct grant allowed, this should be assigned to role. Also, is there any alternate, where we can achieve the same effect without using Associative
DECLARE
v_need_to_assign VARCHAR2(30) := '&ENTER PRIVILEGE ASSIGN';
v_user varchar2(30) := '&USER';
TYPE t_list IS TABLE OF NUMBER INDEX BY VARCHAR2(30);
v_list t_list;
v_chk NUMBER;
e_fail_drop EXCEPTION;
BEGIN
v_list('SYSDBA') := 1;
v_list('CREATE SESSION') := 1;
BEGIN
v_chk := v_list(v_need_to_assign);
RAISE_APPLICATION_ERROR(-20001,'PRIVELEGE '||v_need_to_assign||' is not allowed to be grant');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Privilege ' || v_need_to_assign|| ' Granted');
EXECUTE IMMEDIATE 'GRANT '||v_need_to_assign || ' to ' || v_user;
DBMS_OUTPUT.PUT_LINE('THE PRIVELEGE '||v_need_to_assign || ' HAS BEEN GRANTED TO ' || v_user) ;
END;
END;
hare krishnaI would appriciate, if you could offer your suggestions on this.
hare krishna
Alok -
How to execute a anonymous block
hi all,
I want to execute a anonymous pl/sql block using dbms_sql.
Is it possible to use through dbms_sql. suppose i am having a 100 lines of code in an anonymous block will i be able to execute it through dbms_sql or plz tell me any other way to do it.
note: i will have this anonymous block code in a table. i should take the block from the table and execute it.
Please help me how to do it.
thanks
hari> we have a table driven approach for our project.
That does not make sense as a table driven approach implies a data driven approach.
Which means that the code is static/fixed and processes the data.
It is very complex to dynamically generate code to perform actions, instead of generating data to tell the code what actions to perform.
This is usually only done in the domains of artificial intelligence and experts systems - and one can debate just how effective that approach is...
Which raises the question as why you would choose such an approach in the first place?
Do you also realise that this dynamic code will likely trash the SQL Shared Pool due to a lack of bind variables? And trashing the Shared Pool that way is the #1 reason for poor performing applications using Oracle?
Maybe you are looking for
-
[b]Listener problem while configuring host string through NET config[/b]
Hi, I am unable to create host string through Net config. While testing with userid/password, the test does not succeed. The host string configured is known as PROCESS. Net config error message while testing the connection is as follows: "Connecting.
-
White screen of death? power/sleep button?
so my ipod is in what they call the white screen of death. I have found a way to fix it but that involves my power/sleep button to work... and it doesn't. it is jammed. I dont know how to fix it. also, when i connect the ipod to the computer it doesn
-
My iphone 6 camera quit working
My Iphone camera does not work with the app open. when I touch the screen circle to take a pic, the home screen returns
-
PS CS5 Write Acess Error saving to a windows 2008 server share
Hi Everyone, Our macs are running Snow Leopard 10.6.7 and we save/open files on a Windows 2008 Server via SMB, this particular problem, seems to be happening only with Photoshop: Sometime, when we try to save an image, photoshop returns a write acces
-
How do I delete a corrupted podcast?
2nd generation iPod Touch. Has had lots of issues since purchase. Touch froze playing a podcast, restarted itself, and now the podcast won't play and can't be deleted (and I can't sync the iPod). You can't draw your finger across the podcast & delete