Prompt in PL/SQL block
Hi,
I want to prompt procedure name and it's version during execution of procedure...?
I am new in PL/SQL part, not sure whether it's possible or not? dbms_output.put_line gives output after execution and after setting serveroutput 'ON'.. Is there any alternative?
you can use the dbms_output.enable(1000000); but this will only display the text you put on the dbms_output.put_line() after execution of the code at SQL*Plus. other third party development tools such as the PL/SQL Developer also supports it.
dbms_output.put_line() is limited to a max size of 1000000. alternatively you can build a code that capture your message and insert it into a log table. in that way you can query the same table for the info or data that you might need.
Similar Messages
-
No Data Found: Exception in SQL inside PL/SQL block
Hi Friends
I am trying to execute an SQL SELECT stmt inside a PL/SQL block. But when i execute the procedure, it gives me No Data Found Exception.
I know it is because no row is fetched in the query, but the condition of the SELECT query i have specified is being satisfied, i have checked it by running it on the SQL prompt.
But somehow, it is not running from inside the PL/SQL procedure.Can anybody help me out on this as to why is this happening?? I am giving my code for reference and have Highlighted the Query inside it:
CREATE OR REPLACE procedure insert_sfdc_account
as
--DECLARE
CURSOR C1 IS
SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
address, city, postal_code, country_key, zzcust_type, vat_code
FROM load_cust_general
WHERE account_group = 'ZSIT';
v_cust_cur c1%ROWTYPE;
-- type sales_tab is table of load_cust_sales_area%rowtype;
v_sales_area load_cust_sales_area%ROWTYPE;
-- v_sales_area sales_tab;
v_salesorg varchar2(10);
v_sales_district varchar2(10);
v_salesoff varchar2(10);
v_custgrp varchar2(10);
v_salesgrp varchar2(10);
v_type varchar2(20);
v_nature varchar2(10);
v_partner_code varchar2(10);
v_parent_cust varchar2(20);
v_credit_blk varchar2(20);
BEGIN
open c1;
loop
fetch c1 into v_cust_cur;
exit when c1%NOTFOUND;
for i in (SELECT customer_code, salesorg from load_cust_partner
where customer_code = v_cust_cur.customer_code ) LOOP
dbms_output.put_line(v_cust_cur.customer_code );
SELECT partner_code into v_partner_code from load_cust_partner
where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
dbms_output.put_line(v_partner_code||i.customer_code);
SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
WHERE customer_code = i.customer_code and salesorg = i.salesorg;
dbms_output.put_line(v_salesorg||i.salesorg);
SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G'; dbms_output.put_line(v_parent_cust);
SELECT credit_block INTO v_credit_blk from load_cust_company_cod
WHERE customer_code = i.customer_code;
dbms_output.put_line(v_credit_blk);
for j in (SELECT account_group, customer_type from load_cust_general
where customer_code IN (select customer_code from load_cust_partner
where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
LOOP
-- exit when j%NOTFOUND;
dbms_output.put_line(j.account_group);
if (j.account_group = 'ZDIS') THEN
v_type := 'DISAC';
v_nature := '06';
-- EXIT ;
else
v_type := 'SPACC';
v_nature := '01';
END IF;
dbms_output.put_line(v_type||' '||v_nature);
END LOOP;
INSERT INTO sfdc_account
(SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
v_salesgrp, v_nature, v_cust_cur.vat_code);
end loop;
end loop;
CLOSE c1;
-- Delete data from Load Table
-- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
/* truncate table load_cust_partner;
truncate table load_cust_hierarhy;
truncate table load_cust_sales_area;
truncate table load_cust_company_cod;
commit;
exception
when others then
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
END;
Kindly Help.....
Thanks and RegardsCreate the procedure again and execute it in SQL*Plus environment and paste the output:
CREATE OR REPLACE procedure insert_sfdc_account
as
--DECLARE
CURSOR C1 IS
SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
address, city, postal_code, country_key, zzcust_type, vat_code
FROM load_cust_general
WHERE account_group = 'ZSIT';
v_cust_cur c1%ROWTYPE;
-- type sales_tab is table of load_cust_sales_area%rowtype;
v_sales_area load_cust_sales_area%ROWTYPE;
-- v_sales_area sales_tab;
v_salesorg varchar2(10);
v_sales_district varchar2(10);
v_salesoff varchar2(10);
v_custgrp varchar2(10);
v_salesgrp varchar2(10);
v_type varchar2(20);
v_nature varchar2(10);
v_partner_code varchar2(10);
v_parent_cust varchar2(20);
v_credit_blk varchar2(20);
BEGIN
open c1;
loop
fetch c1 into v_cust_cur;
exit when c1%NOTFOUND;
for i in (SELECT customer_code, salesorg from load_cust_partner
where customer_code = v_cust_cur.customer_code ) LOOP
SELECT partner_code into v_partner_code from load_cust_partner
where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
WHERE customer_code = i.customer_code and salesorg = i.salesorg;
dbms_output.put_line('Customer_Code : '|| i.customer_code);
dbms_output.put_line('SalesOrg : '|| i.salesorg);
SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
SELECT credit_block INTO v_credit_blk from load_cust_company_cod
WHERE customer_code = i.customer_code;
for j in (SELECT account_group, customer_type from load_cust_general
where customer_code IN (select customer_code from load_cust_partner
where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
LOOP
-- exit when j%NOTFOUND;
if (j.account_group = 'ZDIS') THEN
v_type := 'DISAC';
v_nature := '06';
-- EXIT ;
else
v_type := 'SPACC';
v_nature := '01';
END IF;
END LOOP;
INSERT INTO sfdc_account
(SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
v_salesgrp, v_nature, v_cust_cur.vat_code);
end loop;
end loop;
CLOSE c1;
-- Delete data from Load Table
-- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
/* truncate table load_cust_partner;
truncate table load_cust_hierarhy;
truncate table load_cust_sales_area;
truncate table load_cust_company_cod;
commit;
exception
when others then
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
END;
SQL> set serveroutput on
SQL> exec insert_sfdc_account; -
Exception in declarative section to propagating in PL/SQL Block
Hi All, I have a requirement to send emails to some receipient whenever there is an error in a process. The is working untill the put a wrong database link in the parameter, the cursor is in declarative statement, hence when other exception does not work, create and enclosing block around the initial block so that the exception can propagate to the enclosing block, but this does not work either, please advice. Below is the a brief pseudo code. The bold is the initial block. Please advice.
DECLARE
Invalid_table EXCEPTION;
PRAGMA EXCEPTION_INIT(Invalid_table, -00942);
BEGIN
declare
c_test number;
cursor c1 is select 1 from tt@sro4link1 --- wrong databaselink sent as a parameter
where 1 =1;
*/*Because the error is in the cursor select, no email is been sent, that was the reason I put an enclosing block, but the exception is not propagate either */*
BEGIN
OPEN C1;
FETCH C1 into c_test;
CLOSE C1;
EXCEPTION
WHEN OTHERS THEN
--- Send email
END; EXCEPTION
WHEN Invalid_table THEN
--- send email
END;
/Ade2 wrote:
it is not a dynamic sql. Your description is not very clear about what is code and what is pseudo code, but if you are using substitution variables in sqlplus, then that is dynamic SQL.
sqlplus scans for substitution variables, prompts when needed, replaces the variable (substitutes) with the text input and passes the entire result to the database for validation.
If the substitution text input results in an invalid PL/SQL block then a compilation error is returned from the database. The PL/SQL cannot be compiled, it never runs, no run time exceptions are possible.
So you cannot use exceptions to detect errors in values input to substitution variables.
SQL> declare
2 l_dummy number;
3 begin
4 select 1 into l_dummy from dual;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> declare
2 l_dummy number;
3 begin
4 &5
5 end;
6 /
Enter value for 5: select 1 into l_dummy from dual;
old 4: &5
new 4: select 1 into l_dummy from dual;
PL/SQL procedure successfully completed.
SQL> /
Enter value for 5: this will not compile
old 4: &5
new 4: this will not compile
this will not compile
ERROR at line 4:
ORA-06550: line 4, column 8:
PLS-00103: Encountered the symbol "WILL" when expecting one of the following:
:= . ( @ % ; -
How to search source of pl/sql block in database?
Hi Guys,
We have an issue in database, there is PL/SQL block running in my database as below which deleting very important historical data.
begin
loop
delete from tabl_name where created_date<sysdate -100 and ronum<10000;
EXIT WHEN SQL%NOTFOUND;
commit;
end loop;
end;
I tried following,
1) I found this block in v$sqlarea
2) I searched in dba_source,user_source,all_source but no luck.
3) I checked all the triggeres but no luck.
4) I checked all the cron entries for oracle/root/app owner in os but no luck.
5 I checked all the jobs in dba_jobs but no lcuk
would appreciated if anyone can assist on this.
I want to disable/remove this query to be executed.
Regards,
RikkiFor ASH,
I am trying to confirure the OEM and not able to access the OEM from remotely. However any idea from commad prompt.
I believe there is a script ashrpt.sql but while running this script format is not supporting.
any idea if you have run it before.
I agree for log miner utilities, but I need to configure the UTL dir and need to bounce it and its a critical production environment so looking for alternatives. if not possible I would go for this option.
It seems ASH report is being geneated lets see how does it go.
Regards,
Pradeep
Edited by: user13049723 on Jul 26, 2010 8:07 PM -
Using PL/SQL Block how do you check if the character string value is aA-zZ
I have a pl/sql block that I prompt the user for password and I load the string into an array and interrogate each index(entry) to see if it is "aA-zZ".
How can I check if the value entered is Alpha.
I need to do the same for number and Special character. Please advise. ThanksThanks to All of you. The desired solution to verify complex password that enforces desired security policies. An example that I am using is the following:
IF NOT (regexp_like(sz_complex_pw,'[[:digit:]]') AND regexp_like(sz_complex_pw,'[[:alpha:]]') AND regexp_like(sz_complex_pw,'[[:punct:]]') AND regexp_like(sz_complex_pw,'[[:upper:]]'))
THEN
--dbms_output.put_line('Password is not complex...');
RAISE sz_err_pw_complex; -- Complex Password is not compliant
END IF;
DBMS_OUTPUT.PUT_LINE('Complex Password is in Compliance...');
EXCEPTION
This was helpful to me and I trust others will find helpful.
Edited by: yakub21 on Oct 16, 2010 9:05 PM -
Running a anonymous PL/SQL block
Hi,
I have created an anonymous PL/SQL block and saved it in a file. And I am now trying to run it from the sql prompt using @.
But this doesn't seem to be working. I get a wierd number as output and then it hangs.
This is not the case if I copy paste the anonymous block. In this case I get the correct output.
Please assist as to whether it is possible to run it using @ as it is important for me to do so..Hi,
You forgot the slash after the anonymous block:
USER is "YJAM"
TEST>-- Create anonymous Block
TEST>BEGIN
2 NULL;
3 END;
4 /
PL/SQL procedure successfully completed.
TEST>-- save as script
TEST>save ab.sql
Created file ab.sql
TEST>get ab
1 BEGIN
2 NULL;
3* END;
TEST>@ab
PL/SQL procedure successfully completed.
TEST>ed ab Here, I delete line 4. hence the Block won't run.
TEST>@ab
4
5
6
7
8 . a dot to exit input mode. a slash would run the block
TEST>Regards,
Yoann. -
Use Chains, or PL/SQL Block of calls.
I currently have a half dozen cron jobs that kick off different batches of processing. Originally, these were generally a sequence of C programs that did different operations (fetch student info from student record system and load into IdM system, process directory changes, etc). Over the years, most of the program logic has been rewritten as PL/SQL packages and the cron jobs basically drop into SQL*PLUS and do things like:
prompt "Do Spbpers delta"
execute simon.employee_maint.Spbpers_Delta;
commit;
prompt "Do People.Update_From_Employees"
execute simon.People_Maint.Update_From_Employees;
commit;
prompt "Do SGBSTDN_Full"
execute Simon.Bstudent_Maint.Sgbstdn_Full;
commit;
prompt "Do SPRIDEN_Full (Student)"
execute Simon.Bstudent_Maint.Spriden_Full;
These procedures generally connect to other Oracle databases and get or push data around, and are hitting a number of different databases. The biggest of these scripts has 45 execute statements in it. (This script started in 1992.....)
Anyway, we are getting some issues with and it is time to clean things up. This is my first foray into Scheduler and I am hoping to get some philosophical guidance on how best I should restructure things. One obvious thing, is to break up the big script into a couple of smaller ones. In some cases, order matters and in other, it doesn't - although I would prefer not to have several jobs hitting the admin system at the same time.
I have been playing a bit with the scheduler, mostly via the EM web interface, and have come up with a few questions - some pretty specific, others more stylistic.
1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....Hi,
I can try to answer some of these questions
1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
False. The EM interface does have this restriction, but if you use dbms_scheduler directly there is no such restrisction. Even in the EM interface you can workaround this by using a PL/SQL block which calls the package procedure (although argument handling is a little less flexible this way).
2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
The answer to this depends on what you are doing. If the 5 steps run serially one after the other, using one pl/sql block may be easier. If you want some pieces to run in parallel, then creating a simple chain is better. A bit more effort spent setting up the chain will result in much faster execution times if you can run pieces in parallel.
3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
This has come up on the forum a few times and there are basically two different approaches. One is to use dbms_lock to ensure that only one runs at a time. This is the easiest way and the way that I recommend.
The other way is to set up a job class with a resource consumer group and put into effect a resource consumer plan that specifies that only one session from that resource consumer group can run at a time. This is easily extensible to cases where you want 2 or more running at a time from a certain job class (which dbms_lock doesn't support).
Code on how to set this up and more discussion is located here
Run Jobs One After Another
4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
Jobs and programs can be disabled. But if a job or chain tries to run a disabled program it will result in a failure (though it will be retried if you say that the job can be restarted).
[ 5) ] The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....
The Scheduler was intended to accommodate a wide range of usage from simple one-off background tasks to complex sequences of interrelated tasks. As with any other software development you should use it in the simplest way possible that does what you need it to do.
Hope this helps. Feel free to post any further questions.
-Ravi -
Pl/sql block to count no of vowels and consonents in a given string
hi,
I need a pl/sql block to count no of vowels and consonants in a given string.
Program should prompt user to enter string and should print no of vowels and consonants in the given string.
Regards
KrishnaEdit, correction to my above post which was wrong
SQL> ed
Wrote file afiedt.buf
1 with t as (select '&required_string' as txt from dual)
2 --
3 select length(regexp_replace(txt,'([bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ])|.','\1')) as cons_count
4 ,length(regexp_replace(txt,'([aeiouAEIOU])|.','\1')) as vowel_count
5* from t
SQL> /
Enter value for required_string: This is my text string with vowels and consonants
old 1: with t as (select '&required_string' as txt from dual)
new 1: with t as (select 'This is my text string with vowels and consonants' as txt from dual)
CONS_COUNT VOWEL_COUNT
30 11
SQL> -
Accepting user input and executing a PL/SQL block using it
Hi All,
I am working on a requirement wherein I have to accept values from the user for the various arguments to be supplied to a PL/SQL block and then execute it using these values. For now, I am using the following logic:
PROMPT Enter value for the Category
ACCEPT cCategory CHAR PROMPT 'Category:'
DECLARE
cCategry CHAR(1) := '&cCategory';
BEGIN
DBMS_OUTPUT.PUT_LINE('The value of the Category as entered by you is' || cCategory);
END;
PROMPT Press y if you want to proceed with the current values, or press n if you want to re-enter the values
ACCEPT cChoice CHAR Prompt 'Enter y or n:'
DECLARE
cCategry CHAR(1) := '&cCategory';
sErrorCd VARCHAR2(256);
sErrorDsc VARCHAR2(256);
BEGIN
IF '&cChoice' = 'y'
THEN
DBMS_OUTPUT.PUT_LINE('Starting with the process to execute the stored proc');
--- schema1.package1.sp1(cCategry, sErrorCd, sErrorDsc);
--- DBMS_OUTPUT.PUT_LINE('Error Code :' || sErrorCd);
--- DBMS_OUTPUT.PUT_LINE(' Error Description :' || sErrorDsc);
ELSIF '&cChoice' = 'n'
THEN
Now I want that the proc again start executing in the loop from the 1st line i.e. PROMPT Enter value for the Category. However i see that this is not possible to do that PROMPT statements and accepting user inputs execute only on the SQL prompt and not inside a PL/SQL block.
Is there an alternate method to establish this?
Thanks in advance.Hi,
You can write a genric procedure to achive the desired output. Pass 'Y' or 'N' in the procedure.
Call that procedure in simple pl/sql block during runtime using substituton operator.
For ex
create or replace procedure p1(category_in in varchar2)
IS
BEGIN
if (category_in='Y')
then
prcdr1()
/** Write your logic here ***/
elsif(category_in='N') then
prcdr2()
/** write your logic here***/
end if;
exception
/***write the exception logic ***/
end p1;
Begin
p1('&cat');
end;Regards,
Achyut K
Edited by: Achyut K on Aug 6, 2010 5:20 AM -
hi,
i created a pl/sql block using ed <filename.sql> and tried to execut it useing @<filena.sql> or run <filename.sql>.for the 2nd command the message i got is "nothing
in buffer to run" and for the 1st comm i got nothing. i dint event get prompt.
i am totally new to oracle. please solve my probs.
thanqTo execute the PL/SQL block make sure that you have a "/" at the end of your PL/SQL block and then an <Return character>. Once you have that then you can type C:\..\..\@filename.sql. If you don't put the "/" and "return character" it in your script then after typing C:\..\..\@filename.sql press enter and then type in "/" and then press enter again.
Soji. -
Using accept command within PL/SQL block
Hi all i have a following Pl/SQL block which ia =as follows :-
declare
begin
...certain statements using while
end;
i need to take the user input using accept
if i put the accept stmt betweeen begin and end i am getting following error :-
accept myv number default 10 prompt 'Enter a number: '
ERROR at line 48:
ORA-06550: line 48, column 8:
PLS-00103: Encountered the symbol "MYV" when expecting one of the following:
:= . ( @ % ;
ORA-06550: line 48, column 30:
PLS-00103: Encountered the symbol "PROMPT" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between || multiset member SUBMULTISET_
Let me know how can i include accept stmt in Pl/SQL block
ThanksYou're missing a fundamental concept here.
PL/SQL = embedded 4GL programming language in the Oracle database.
SQL*Plus = CLI (Command Line Interface) client for an Oracle database.
The ACCEPT command is a SQL*Plus command. Not a PL/SQL command.
The PL/SQL engine sits inside the Oracle Server Process that services your client (SQL*Plus) session. That server process does not know who/what/where you are as a physical client. It does not know what platform and o/s you are using. It does not know what client you are using. It is after all a server process and should not and need not to know that.
Nor can that Oracle Server Process running on the Data Server Platform access you client's hard drive, keyboard, mouse, screen, printer and so on.
PL/SQL running in this Oracle Server Process therefore cannot read your keyboard to accept end-user input. PL/SQL therefore cannot write data to your screen.
You need to make a clear distinction between SQL*Plus (a client) and Oracle PL/SQL (the server). -
Display an Alert message in 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,
Subarna
Edited by: user9955252 on Apr 21, 2010 1:47 AMHello,
APEX Forum is here : Oracle Application Express (APEX)
Regards -
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; -
Performance: Operations in Cursor vs. Operations in PL/SQL block
Why does I have a better performance when I program operations in complex cursors instead of programming the same statement in a pl/sql block in a stored procedure?
Operation in a Cursor:
CURSOR c IS
DECODE(name,'Peter','dog','cat') animal
...The same Operation in a PL/SQL block:
begin
if name = 'Peter'
then
animal = 'dog';
else
animal = 'cat';
end if;
end;
...I know that a parsed cursor is placed in the Shared Pool and reference
a context area in the PGA.
Does anybody have an idea?
Message was edited by:
madMaybe because if you can write only a SQL query, it is faster than to write PL/SQL code that will do the same job. See following thread for a analog discussion: Re: pl/sql table
-
How to test for différent Select into a single PL/SQL block ?
Hi,
I am relatively new to PL/SQL and I am trying to do multiple selects int a single PL/SQL block. I am confronted to the fact that if a single select returns no data, I have to go to the WHEN DATA_NOT_FOUND exception.
Or, I would like to test for different selects.
In an authentification script, I am searching in a table for a USER ID (USERID) and an application ID, to check if a user is registered under this USERID for this APPLICATION.
There are different possibilities : 4 possibilities :
- USERID Existing or not Existing and
- Aplication ID found or not found for this particular USERID.
I would like to test for thes 4 possibilities to get the status of this partiular user regardin this application.
The problem is that if one select returns no row, I go to the exception data not found.
In the example below you see that if no row returned, go to the exception
DECLARE
P_USERID VARCHAR2(400) DEFAULT NULL;
P_APPLICATION_ID NUMBER DEFAULT NULL;
P_REGISTERED VARCHAR2(400) DEFAULT NULL;
BEGIN
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
:P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
EXCEPTION
WHEN NO_DATA_FOUND THEN
:P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
END;I would like to do first this statement :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID Then to do this one if the user is found :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;etc...
I basically don't want to go to the not found exception before having tested the 4 possibilities.
Do you have a suggestion ?
Thank you for your kind help !
ChristianSurely there are only 3 conditions to check?
1. The user exists and has that app
2. The user exists and doesn't have that app
3. The user doesn't exist
You could do this in one sql statement like:
with mimic_data_table as (select 1 userid, 1 appid from dual union all
select 1 userid, 2 appid from dual union all
select 2 userid, 1 appid from dual),
-- end of mimicking your table
params_table as (select :p_userid userid, :p_appid appid from dual)
select pt.userid,
pt.appid,
decode(min(case when dt.userid = pt.userid and dt.appid = pt.appid then 1
when dt.userid = pt.userid then 2
else 3
end), 1, 'User and app exist',
2, 'User exists but not for this app',
3, 'User doesn''t exist') user_app_check
from mimic_data_table dt,
params_table pt
where pt.userid = dt.userid (+)
group by pt.userid, pt.appid;
:p_userid = 1
:p_appid = 2
USERID APPID USER_APP_CHECK
1 2 User and app exist
:p_userid = 1
:p_appid = 3
USERID APPID USER_APP_CHECK
1 3 User exists but not for this app
:p_userid = 3
:p_appid = 2
USERID APPID USER_APP_CHECK
3 2 User doesn't exist
Maybe you are looking for
-
Hello Guyz, I have a scenario where I have to filter values of one text characteristic based on the other text characteristic. i.e I have text char whose values are either yes or no and there is a date characteristic. As per the requirement when the
-
BAPI_ACC_DOCUMENT_POST. Why tax account is replaced ?
The code as follow: REPORT YC_BAPI_ACC_DOCUMENT_POST. * bapi CLEAR:BAPI_HEADER, BAPI_ACCOUNTGL, BAPI_ACCOUNTRECEIVABLE, BAPI_ACCOUNTPAYABLE, BAPI_ACCOUNTTAX, BAPI_CURRENCYAMOUNT, BAPI_RETURN, BAPI_EXTENSION2
-
Error loading XML content, returned by PHP script
JavaScript function loadXMLDoc(fname) var xmlDoc; // code for IE if (window.ActiveXObject) xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocum
-
Defeat denialof service attack: New feature in WLS 5.1 SP9
Hi all, SP 9 for WLS 5.1 provides 2 new properties to prevent denial of service attacks (ISSUE 31269). The properties are weblogic.httpd.maxPostSize and weblogic.httpd.maxPostTimeSecs. However I miss more detailed information about the use of the pro
-
Just got a mac with aperture and want to print photos like a photoshop package with 4 different pics on an 8.5x11 photo paper or 2 5x7 etc. How can this be done in aperture if it can or do I need to get photoshop for mac. Hope I did not waste my mone