Pl/SQL block for BLOB
Hi,
I wrote a function to convert from blob to varcahr2 as like bellow.how can i test this function(give me any anonomous block for test.)
create or replace FUNCTION BLOBCONVERT
( var_gdtxft blob)
return varchar2 is
var_text VARCHAR2(6000);
BEGIN
SELECT REPLACE(REPLACE(substr(UTL_RAW.CAST_TO_varchar2(var_GDTXFT),321, LENGTH(UTL_RAW.CAST_TO_varchar2(var_GDTXFT))-5-321),
SUBSTR(substr(UTL_RAW.CAST_TO_varchar2(var_GDTXFT),321),2,1),''),'\par','\n') into var_text
FROM dual;
RETURN var_text;
EXCEPTION
When NO_DATA_FOUND then
RETURN 'No Data found';
END BLOBCONVERT;
I don't quite get what your function is supposed to do, but in any case in can simplified a bit (probably still more if you explained us what you'd like to achieve):
SQL> create or replace function blobconvert (var_gdtxft blob)
return varchar2
is
begin
return replace
(replace (substr (utl_raw.cast_to_varchar2 (var_gdtxft),
321,
length (utl_raw.cast_to_varchar2 (var_gdtxft))
- 5
- 321
substr (substr (utl_raw.cast_to_varchar2 (var_gdtxft),
321
2,
1
'\par',
'\n'
end blobconvert;
Function created.
SQL> declare
bl blob := utl_raw.cast_to_raw ('Hello \n World \par' || rpad ('World', 400, 'World'));
begin
dbms_output.put_line (blobconvert (bl));
end;
oldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWoldWol
PL/SQL procedure successfully completed.
Similar Messages
-
PL/SQL Block for Data Formatting
I have created a Report that will pull all times that a person clocks in and clocks out. It works great but now accounting wants me to do some "conditional formatting" that can't be done by Report's built in conditional formatting capabilities. I talked to tech support yesterday and they suggested a PL/SQL block to format my times to do what accounting needs. Here is the skinny: All times in the database are done in 100ths of an hour. I need to the times up or down to the next quarter hour depending on when they clocked in. If they clocked in one minute late, it rounds down the the previous quarter hour and anything later and it rounds up. Can someone help me? Thanks, Jeremy
In the data model, enter your query and create the groups you need.
Let's say you have the number column my_time in a group named g_times.
Then create a formula column in the group g_times and look at its
properties. Change the name to cf_time.
Click on the property PL/SQL-Formula, and in the pl/sql editor you can
write something like
function CF_TIMEFormula return Number is
begin
return trunc((:my_time + 0.23) * 4) / 4;
end;As you see, you can access query columns by using the colon.
Afterwards, you can display :cf_time in your Layout model. -
How can i make a pl/sql function for BLOB datatype
hi..anyone here who is very familiar about BLOB datatype. i have a COLUMN_ID, COLUMN_A in a certain TABLE_1. COLUMN_A is blob datatype that contains almost 250,000rows
SQL>select column_A from table_1 where column_id=1234567
column_A
00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
how can i make a user-defined function to compute and convert this blob datatype into decimal length value. this hex value are points in the map.. the function must contain
1.get the length of a blob then
2.convert blob to variable hexadecimal characters by parsing it into 8
3.to_number function or other function used to convert haxadecimal characters to decimal numbers
4.phythagorean formula to compute length between two points. this is the formula i think LENGTH =
SQRT(power((coordinate_x-prev_coordinate_x),2)+power((coordinate_y-prev_y),2));
after this when i type this
SQL>select user_function(column_A) from table_1 where column_id=1234567
user_functions(column_A)
--output length will be in decimal value already
the function will goes like this
step1 is to get the blob length
00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
step2 is parsing of data by eights
00000001 =>1
00000001 =>1
00000006 =>6 (number of coordinates)
06D4E833 => X1
074B69EC => Y1
06D4E91F => X2
074CO184 => Y2
06D50C58 => X3
074C031E => Y3
step3 to_number function used to convert hex char to decimal
step4 compute by phytagorean (NOTE ! when computing length the third parsed eight will tell how many coordinates are there..the number of coordinates is ranging from 2 up to E..above example shows 6 coordinates so it means
LENGTH1 =
SQRT(power((X2-X1),2)+power((Y2-Y1),2));
LENGTH2=
SQRT(power((X3-X2),2)+power((Y3-Y2),2));
TOTAL LENGTH=LENGTH1 + LENGTH2
thanksits my first time to use that.There's got to be a first tiem for anything. Be brave.
btw if theres more easy suggestion pls feel free..Well of course the easiest solution would be if the calling program passed in the parameters as separate arguments instead of glomming them together in a string that has to be parsed. This sort of kluj really ought not to have survived into C21.
Cheers, APC -
PL?SQL block for string concatenation
Hi,
I have written the following procedure for concatenating the strings from different tables. This is working fine if I run this is SQL commands. But If I put the same in HTMLDB report region, I am getting error "Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-06550: line 1, column 8: PLS-00103: Encountered the symbol "" when expecting one of the following: begin function package pragma procedure subtype type use form current cursor"
I am not able to resolve this.. Please help me..
DECLARE
CURSOR C_Lscape
IS
SELECT PL.pl_id pl_id,PL.partner_name partner_name,
PL.area area,PL.region region,PL.country country,
PL.tier tier,PL.type type,PL.category category,
PL.market_segment market_segment,PL.parent parent,
PL.geo_focus geo_focus,PL.opn_id opn_id,PL.opn_level opn_level,
PL.opn_status opn_status,PL.opn_expirydate opn_expirydate,
pd.types types,pd.apac apac,pd.region pd_region,
pd.country pd_country,pd.value value,pd.sub_value sub_value,
acc.acc_territory_assigned acc_territory_assigned,acc.industry industry,
acc.industry_segment industry_segment,acc.solution_segment solution_segment,
acc.product product,acc.solution_name solution_name,acc.apac acc_apac,
acc.region acc_region,acc.country acc_country,
ad.agreement_type agreement_type,ad.adreement_date adreement_date,ad.credithold_status credithold_status,
ad.agreement_number agreement_number
FROM PARTNER_LANDSCAPE_PL PL
,PARTNERLANDSCAPE_DETAILED PD
,AGREEMENT_DETAILS AD
,ACCELERATE_SOLUTION ACC
WHERE PL.pl_id=pd.pl_id
AND ACC.PL_ID=PL.PL_ID
AND AD.PL_ID=PL.PL_ID
AND (( PL.partner_name=:p18_partner
AND PL.partner_name!='%null%')
OR ( PL.country=:p18_country
AND PL.country!='%null%')
OR ( PL.region=:p18_region
AND PL.region!='%null%')
OR ( PL.area=:p18_area
AND PL.area!='%null%')
OR ( PL.category=:p18_category
AND PL.category!='%null%')
OR ( PL.market_segment=:p18_marketsegment
AND PL.market_segment!='%null')
OR ( PL.tier=:p18_tier
AND PL.tier!='%null%')
OR ( PL.GEO_FOCUS=:p18_geofocus
AND PL.GEO_FOCUS!='%null%')
OR ( pd.sub_value=:p18_industry
OR :p18_industry!='')
OR ( pd.value=:p18_gtmi
OR :p18_gtmi!='')
OR ( pd.value=:p18_productfamily
OR :p18_productfamily!='')
OR ( pd.sub_value=:p18_solutionarea
OR :p18_solutionarea!='')
l_lscape VARCHAR2(4000);
BEGIN
FOR i IN C_Lscape
LOOP
l_lscape := i.pl_id||' : '||i.partner_name||' : '||i.area||' : '||i.region||' : '||i.country||' : '||i.tier||' : '||i.type||' : '||i.category
||' : '||i.market_segment||' : '||i.parent||' : '||i.geo_focus||' : '||i.opn_id||' : '||i.opn_level||' : '||i.opn_status
||' : '||i.opn_expirydate||' : '||i.types||' : '||i.apac||' : '||i.region||' : '||i.pd_country
||' : '||i.value||' : '||i.sub_value||' : '||i.acc_territory_assigned||' : '||i.industry
||' : '||i.industry_segment||' : '||i.solution_segment||' : '||i.product||' : '||i.solution_name
||' : '||i.acc_apac||' : '||i.acc_region||' : '||i.acc_country||' : '||i.agreement_type||' : '||i.adreement_date
||' : '||i.credithold_status||' : '||i.agreement_number;
END LOOP;
dbms_output.put_line(l_lscape);
END;
Regards,
PaI'm doing something similar to what you want to accomplish.
First, I created a view that joins the master and detail tables together. The view uses the STRAGG function ahead of time to concatenate multiple details into one "column" (or field).
Next, in my report region, the SQL query lloks like :
SELECT dep_id, dev_st, oper_tp, sig, NAME,
commod, commod_group,
MIN (usgs_num) KEEP (DENSE_RANK FIRST ORDER BY mt_rec ASC) usgs_num,
MIN (model_name) KEEP (DENSE_RANK FIRST ORDER BY mt_rec ASC) model_name,
MIN (country) KEEP (DENSE_RANK FIRST ORDER BY l_line ASC) country,
MIN (state_prov) KEEP (DENSE_RANK FIRST ORDER BY l_line ASC) state_prov,
MIN (county) KEEP (DENSE_RANK FIRST ORDER BY l_line ASC) county,
MIN (lat_dec) KEEP (DENSE_RANK FIRST ORDER BY g_line ASC) lat_dec,
MIN (lon_dec) KEEP (DENSE_RANK FIRST ORDER BY g_line ASC) lon_dec,
mas_id, mrds_id
FROM NEW_MASTER_QUERY1
WHERE dep_id IN
(SELECT dep_id
FROM search_table where &P3_WHERE_CLAUSE. )
&P3_SEARCH_AREA.
GROUP BY dep_id, dev_st, oper_tp, sig, NAME, commod, commod_group, mas_id, mrds_idEach of the lines above with the MIN() function are "fields" which come from different child tables. My view is getting data from 6 tables, and I only display the data in one line.
Hope this helps some.
Bill Ferguson -
Resolved: Use value from select list in pl/sql block
Hello,
I have a form with a select list: P18_BONUSTYPE, the values of which come from a LOV.
When the user clicks a button, a page process is used to insert a row into a table.
When I use the :P18_BONUSTYPE bind variable in my insert statement I get an error "Invalid number" I get an "Invalid number" error. I assume that APEX is using the displayed text in that bind variable, not its actual (html option) value.
I checked the HTML of the page, and the correct values are in the select list.
Can someone tell me how to get the value into a bind variable that can be used in a pl/sql block for a page process?
Thanks
Message was edited by:
Neeko
Issue was a value in another item.Did you tried changing the value using "to_number"? (i.e. to_number(:P18_BONUSTYPE)).
Max. -
Not able to display javascript alert message from within a pl/sql block
Hello,
Can anyone please help me out with this issue. I wanted to display an javascript alert message from within a pl/sql block for an update button. Below is sample code which i am using. P1_ITEM is my hidden item on the report.
begin
if :P1_ITEM IS NOT NULL then
HTP.p ('<script type="text/javascript">');
HTP.p ('alert(''Please complete the item which is already assigned to you!'');');
HTP.p ('</script>');
end if;
end;
and I have made this code to be executed conditionally when request = Expression1
Expression1: SUBMIT
The thing is I am not able to display an alert message when the update button is clicked.
Can anyone please help me with this one.
Thanks,
Ortonvarad but I also have an update statement within that block for the update button something like this i want to achieve.
begin
if :P1_ITEM IS NULL THEN
update sample_tbl
set col1 =:APP_USER,
col2 = 'Y'
where pk_col = ---;
commit;
HTP.p ('<script type="text/javascript">');
HTP.p ('alert(''Successfully assigned an item!'');');
HTP.p ('</script>');
end if;
if :P1_ITEM IS NOT NULL then
HTP.p ('<script type="text/javascript">');
HTP.p ('alert(''Please complete the item which is already assigned to you!'');');
HTP.p ('</script>');
end if;
end;
thanks,
Orton -
Help in solving this pl/sql block
Hi
Could some one help me in solving my problem
i want some data to be extracted by a sql its not fetching it so i prefered to write a pl/sql block for it ...
the block is as follows
begin
cursor opunit is
select code from fmg_operating_units;
cursor pak_code is --- those are the 3 codes which i require
select 'BNL' from dual
union select 'HNA' from dual
union select 'HNL' from dual;
cursor data1(opunit,pak_code) is
select mas.name ,
cl.id ,
opup.oun_code ,
fmg_phone_no(mas.id),
clpk.pak_code ,
clpk.id
from fmg_op_unit_positions opup,
fmg_clients cl,
fmg_client_paks clpk,
fmg_masters mas,
fmg_policies po,
fmg_policy_items pi
where mas.id=cl.mas_id
and cl.id=clpk.cli_id
and clpk.oup_id=opup.id
and opup.oun_code = opunit
and clpk.id=po.ctp_id
and po.id=pi.pol_id
and pi.current_status='AC'
and clpk.pak_code = pak_code;
loop opunits
loop pak_code
open data1
fetch data1(opunit,pak_code) ;
end loop;
end loop;
could some one help me in extracting the data and put it on the CSV file ...
i would be very thank full to you if some one take some time to full fill this task..
thanks in advanceDeclare
cursor opunit is
select distinct code
from fmg_operating_units;
cursor pak_code is --- those are the 3 codes which i require
select 'BNL' codes from dual
union
select 'HNA' codes from dual
union
select 'HNL' codes from dual;
cursor data1(opunit,pak_code) is
select mas.name ,
cl.id ,
opup.oun_code ,
fmg_phone_no(mas.id),
clpk.pak_code ,
clpk.id
from fmg_op_unit_positions opup,
fmg_clients cl,
fmg_client_paks clpk,
fmg_masters mas,
fmg_policies po,
fmg_policy_items pi
where mas.id = cl.mas_id
and cl.id = clpk.cli_id
and clpk.oup_id = opup.id
and opup.oun_code = opunit
and clpk.id = po.ctp_id
and po.id = pi.pol_id
and pi.current_status= 'AC'
and clpk.pak_code = pak_code;
begin
FOR opunits IN opunit LOOP
FOR pak_codes IN pak_code LOOP
OPEN data1;
fetch data1(opunits.code,pak_codes.codes) ;
EXIT WHEN data1%NOTFOUND;
< Rest of your code here > -- You can insert processed data into a temp table &
-- extract data from that table afterwards via select statement
-- & saving the data in a .cvs file extension.
CLOSE data1;
END LOOP;
END LOOP;
<Some more code here if applicable>
EXCEPTION
<Exception handling code section here>
END; -
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 -
PL SQL block - Check for empty file
Hello,
I need help in writing pl sql code to check a file to verify if it has 0 records (file size = zero kb.) In a preceding pl sql block, I am performing a SELECT on data and writing it to a file. If that file is empty/has no records, then I would like to stop the process from continuing on to my next pl sql block which performs an update function.
Summary:
1) Create file from SELECT
2) Check file for zero data, if true, trigger error, if false, continue to next pl sql block.
3) Run update on records if data exists in the file.
Thanks in advance!Thanks John,
You've been of great help so far and a really appreciate it. I'm so close to getting this, I just need help with how to create an error when the file shows no data. I will be running this as an Oracle Apps Concurrent request. I'd like for the job to end in error when no data exists for the file. In unix, I can enter "EXIT 1" and it signals to the concurrent manager to put end the job with an error status. How can I do something similar using pl sql? Here is my code so far, with the missing piece. Thanks!
DECLARE
vFile UTL_FILE.FILE_TYPE;
vrecs BOOLEAN := FALSE;
vnodata EXCEPTION;
BEGIN
vFile := UTL_FILE.FOPEN('/devlop, 'norecs.txt', 'w', 32767);
FOR x IN (
SELECT
node_name AS txt
FROM
applsys.fnd_nodes
WHERE
node_name = 'blahblahblah'
LOOP
vrecs := TRUE;
UTL_FILE.PUT_LINE (vFile, x.txt);
END LOOP;
UTL_FILE.FCLOSE(vFile);
IF NOT vrecs THEN
RAISE vnodata;
END IF;
EXCEPTION
WHEN vnodata THEN
*<what can I put here to cause the pl sql block to error???>*
END;
/ -
Why do i have to init a VARCHAR for a SELECT in a Pro*C PL/SQL block?
Hi,
i use PL/SQL Block in a Embedded C Programm and compile with the PRO*C Compiler. Oracle 10gR2.
When i Select .. Into a VARCHAR bind variable, i have to initialize the variable before, otherwise i get an ORA-1458.
Same problem with assignments to VARCHAR variables.
Question: why do i need to initialize the variable?
Tnx for your help!
The following test program shows my issue:
#include <stdio.h>
#include <string.h>
#include "oraca.h"
#include "sqlca.h"
#define USER "scott"
#define PASSWORD "tiger"
int main()
EXEC SQL BEGIN DECLARE SECTION;
char *db_user = USER;
char *db_passw = PASSWORD;
VARCHAR sysdate_str[64];
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT :db_user identified by :db_passw;
/* this works */
sysdate_str.len = 1000; /* invalid length */
EXEC SQL SELECT
to_char( sysdate, 'dd.mm.yy hh24:mi:ss' )
into :sysdate_str
from DUAL
printf ("sqlca.sqlcode %d\n", sqlca.sqlcode);
/* following code does not work, sqlcode = - 1458 */
/* 01458, 00000, "invalid length inside variable character string" */
sysdate_str.len = 1000; /* invalid length */
EXEC SQL EXECUTE
BEGIN
select to_char( SYSDATE, 'dd.mm.yy hh24:mi:ss')
into :sysdate_str
from dual;
END;
END-EXEC;
printf ("sqlca.sqlcode %d\n", sqlca.sqlcode);
/* following code does not work, sqlcode = - 1458 */
/* 01458, 00000, "invalid length inside variable character string" */
sysdate_str.len = 1000; /* invalid length */
EXEC SQL EXECUTE
BEGIN
:sysdate_str := to_char( SYSDATE, 'dd.mm.yy hh24:mi:ss');
END;
END-EXEC;
printf ("sqlca.sqlcode %d\n", sqlca.sqlcode);
return(0);
Edited by: jjaeckel on May 5, 2010 8:37 PMjjaeckel wrote:
When i Select .. Into a VARCHAR bind variable, i have to initialize the variable before, otherwise i get an ORA-1458.A bind variable in a SQL is simply a place holder. The SQL engine has no idea what data type the value for that placeholder will be. When itself needs to return a value via that placeholder to the caller, it needs to know what the limits/size of the caller's variable is that will be receiving the value from it.
The way that the SQL engine knows what the data type and size are of a placeholder/bindvar, is by you the caller, telling it.. by binding the variable you will be using, to this placeholder.
This bind process "exposes" the data type and size of the variable that will be used for binding (sending/receiving data). -
Pass values to Guid collection/array parameter for anonymous pl/sql block
The following code pops the System.ArgumentException: Invalid parameter binding
Parameter name: p_userguids
at Oracle.DataAccess.Client.OracleParameter.GetBindingSize_Raw(Int32 idx)
at Oracle.DataAccess.Client.OracleParameter.PreBind_Raw()
at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
Any help or advice ?
anonymous pl/sql block text:
DECLARE
TYPE t_guidtable IS TABLE OF RAW(16);
p_userguids t_guidtable;
BEGIN
DELETE testTable where groupname=:groupname;
INSERT INTO testTable (userguid, groupname)
SELECT column_value, :groupname FROM TABLE(p_userguids);
END;
c# code:
public static void SetGroupUsers(string group, List<Guid> users)
OracleConnection conn = Database.ConnectionEssentus;
try
conn.Open();
OracleCommand sqlCmd = new OracleCommand();
sqlCmd.CommandText = sqls["SetGroupUsers"]; // above anonymous block
sqlCmd.Connection = conn;
sqlCmd.BindByName = true;
OracleParameter p_guidCollection = sqlCmd.Parameters.Add("p_userguids", OracleDbType.Raw);
p_guidCollection.Size = users.Count;
p_guidCollection.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p_guidCollection.UdtTypeName = "t_guidtable";
p_guidCollection.Value = users.ToArray();
sqlCmd.Parameters.Add("groupname", OracleDbType.Varchar2, 30).Value = group;
sqlCmd.ExecuteNonQuery();
catch(Exception ex)
System.Diagnostics.Debug.WriteLine(ex.ToString());
finally
conn.Close();
}New question,
How can I select records using "in" condition clause likes the following sentence?
SELECT userguid, firstname, lastname FROM UserTable WHERE userguid in (SELECT column_value FROM TABLE(p_userguids))
I tried using PIPE ROW like this, but ORACLE said "PLS-00629: PIPE statement cannot be used in non-pipelined functions"
FOR i in p_userguids.first .. p_userguids.last
LOOP
SELECT userguid, firstname, lastname INTO l_userrecord FROM UserTable WHERE userguid=p_userguids(i);
PIPE ROW(l_userrecord);
END LOOP; -
Create publicsynonyms for anonymous pl/sql block
Hi,
How do I create a public synonym for an anonymous PL/SQL block?
BEGIN
IF a IS NOT NULL
THEN
OPEN b;
LOOP
FETCH b INTO Func;
EXIT WHEN b%NOTFOUND;
c := c || Func || ',';
END LOOP;
CLOSE b;
c := SUBSTR(c, 1, LENGTH(TRIM(c))-1);
END IF;
return c;
END abc;
ERROR at line 2:
ORA-06550: line 2, column 5:
PLS-00201: identifier 'a' must be declared
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
ORA-06550: line 19, column 2:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 19, column 2:
PL/SQL: Statement ignoredHi,
CrackerJack wrote:
Hi,
How do I create a public synonym for an anonymous PL/SQL block?A synonym is an alternate name.
Anonymous bblocks, by definition, don't have names, so they can't have alternate names. Also, they're not stored, so what good would it do if you could have synonyms for them?
An anonymous block is just a quick and dirty alternative to a procedure, anyway. Why not make a procedure, or a function?
BEGIN
IF a IS NOT NULL
THEN
OPEN b;
LOOP
FETCH b INTO Func;
EXIT WHEN b%NOTFOUND;
c := c || Func || ',';
END LOOP;
CLOSE b;
c := SUBSTR(c, 1, LENGTH(TRIM(c))-1);
END IF;
return c;
END abc;
ERROR at line 2:
ORA-06550: line 2, column 5:
PLS-00201: identifier 'a' must be declared
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
ORA-06550: line 19, column 2:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 19, column 2:
PL/SQL: Statement ignoredThis code looks like part of a function, that was named abc. Where is the beginning part of that function? The errors are caused because it is missing the part where this was declared as a function, and the part where the local variables a, c and func, and the cursor b, were defined.
Does thsi function have something to do with the original question: "How do I create a public synonym for an anonymous PL/SQL block?"?
What are you trying to do? -
Anonymous PL SQL block runs in 2 minutes but runs for 4 hours in Applicatio
We are facing an issue with a custom code. When we run the custom code as anonymous pl/sql block , it completes in 2 minutes.
But when we run the same from Oracle Application as a concurrent program, it runs for more than 4 hours.
There is absolute no change in the code.
Anyone faced this issue?Does your code use context sensitive views such as po_headers?
Maybe you have not set the context in the pl/sql block so the view returns 0 records.
But when you run it in Apps, the context is automatically set and so it processes a large number of records.
Set the context if you have not and then try again.
begin
dbms_application_info.set_client_info('&org_id'); --
end;
Sandeep Gandhi -
Cell Offload will Happen for pl/sql Block with variables
Hello Experts,
i am working on procedures on exadata now. i was confused with cell offload in exadata. somehow offload is not happening when i ran the sql statement in in pl/sql block with variables.
here are my findings.
when i ran insert into from select with values at toad, my query response time is very good. the total process is completed in less than a minute.
i checked offload is happening.
same sql statement is placed in plsql block with variable, procedure is taking lot of time and it is not completing. this case offload is not happening.
is it true, if i use variables in pl/sql block will not use cell offload and smart scan?
if yes, what is the work around.
Thanks
#! PavanHello Marc,
Thanks for quick response.
when i ran the query with literals in toad session i am getting response.
when i run it with pl/sql block , block is not completing at all.
here is the plsql block:
My Apologies for sending big code,with out proper format.
DECLARE
P_BUSINESS_DATE DATE;
P_BATCH_ID NUMBER;
UTC_OFFSET NUMBER;
BEGIN
P_BUSINESS_DATE := to_date('02/01/2012', 'MM/DD/YYYY');
P_BATCH_ID := 1;
UTC_OFFSET := 0;
INSERT /*+ APPEND */ INTO UPL_CLIENT_tbl
( reportdate,
LastName,
FirstName,
MiddleInitial,
AccountNumber,
Address,
City,
State,
Zip,
HomePhone,
WorkPhone,
BirthDate,
Age,
Sex,
NumberOfChildren,
Occupation,
LeadSource,
Consultant,
ProgramDirector,
CallTaker,
LeadDate,
FirstVisitDate,
LastVisitDate,
BillType,
ClientType,
PreviousClientType,
AppointmentDate,
DoctorLetterRequired,
OneYearPermStabilizationDate,
UnlimitedPermStabilizationDate,
MaritalStatus,
ReferrerName,
ReferrerCentreID,
CentreID,
PaymentDateOne,
PaymentAmountOne,
PaymentDateTwo,
PaymentAmountTwo,
PaymentDateThree,
PaymentAmountThree,
PaymentDateFour,
PaymentAmountFour,
LibraryPurchased,
BalanceDue,
FoodNSFBalance,
ProductNSFBalance,
ProgramNSFBalance,
StartWeight,
CurrentWeight,
GoalWeight,
Height,
DateGoalWeightAchieved,
DateSuccessPlusPurchased,
ReturnToActiveDate,
VersionNumber,
HalfWayDate,
LastLSCDate,
LastUpdatedDate,
VitaminWaiverSigned,
LastSupplementPurchaseDate,
LastSupplementCodePurchased,
LastTotalSupplementSupplyCycle,
LastAddtlSupplPurchaseDate,
LastAddtlSupplCodePurchased,
LastAddtlSupplSupplyCycle,
DiabetesClient,
DietControlled,
TakingOralMed,
TakingInsulin,
EmailId,
CTADate,
RWLDate,
Address2)
(SELECT /*+ full(S_CONTACT) full(REFERRER) full(Consultant) full(ProgramDirector) full(CallTaker) full(S_CONTACT_X) full(a) full(a2) full (a3) */ distinct p_business_date reportdate,
SUBSTR(S_CONTACT.LAST_NAME,1,25) AS LastName,
SUBSTR(S_CONTACT.FST_NAME,1,25) AS FirstName,
SUBSTR(S_CONTACT.MID_NAME,1,1) AS MiddleInitial,
S_CONTACT.X_JC_ACNT_NUM + 900000000 AS AccountNumber,
SUBSTR(S_ADDR_PER.ADDR,1,40) AS ADDRESS,
SUBSTR(S_ADDR_PER.CITY,1,20) AS City,
S_ADDR_PER.STATE AS State,
SUBSTR(S_ADDR_PER.ZIPCODE,1,15) AS Zip,
SUBSTR(REPLACE(S_CONTACT.HOME_PH_NUM,'-',''),1,10) AS HomePhone,
SUBSTR(REPLACE(S_CONTACT.WORK_PH_NUM,'-',''),1,10) AS WorkPhone,
S_CONTACT.BIRTH_DT AS BirthDate,
CASE WHEN FLOOR((p_business_date - S_CONTACT.BIRTH_DT)/360) < 0 THEN NULL ELSE FLOOR((p_business_date - S_CONTACT.BIRTH_DT)/360) END AS AGE,
S_CONTACT.SEX_MF AS SEX,
NULL AS NumberOfChildren,
S_CONTACT_X.ATTRIB_34 AS OCCUPATION,
CASE WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Othe' THEN 'Othr'
WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Inte' THEN 'Intr'
WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Prin' THEN 'News'
WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Gues' THEN 'Gst'
ELSE SUBSTR(S_CONTACT_X.ATTRIB_37,1,4) END AS LeadSource,
SUBSTR(Consultant.EMP_NUM,1,10) AS CONSULTANT,
ProgramDirector.EMP_NUM AS ProgramDirector,
CallTaker.EMP_NUM CallTaker,
S_CONTACT.X_LEAD_DT AS LeadDate,
LEAST(nvl(S_CONTACT.X_LAST_CONSULTATION_DATE,O.FirstPurchaseDate ), nvl(O.FirstPurchaseDate,S_CONTACT.X_LAST_CONSULTATION_DATE+1) ) AS FirstVisitDate, --X_LAST_CONSULTATION_DATE stores the performed date or the legacy client firstvisitdate
GREATEST(nvl(S_CONTACT_XM.X_CONSULTATION_DT ,S_CONTACT_X.ATTRIB_29), nvl(S_CONTACT_X.ATTRIB_29, S_CONTACT_XM.X_CONSULTATION_DT-1) ) AS LastVisitDate,
CASE WHEN S_CONTACT.X_INSTALLMENT_BALANCE > 0 THEN 'B' ELSE NULL END AS BillType,
ct.current_client_type ClientType,
SUBSTR(ct.saved_client_type,1,1) PreviousClientType,
S_CONTACT.LAST_CREDIT_DT AS AppointmentDate,
CASE WHEN a.X_DR_LETTER_STATUS IS NOT NULL THEN 'Y' ELSE 'N' END AS DoctorLetterRequired,
NULL AS OneYearPermStabilizationDate,
DECODE(S_PROD_INT.X_PROGRAM_CLASSIFICATION,'Premium',a.START_DT ,NULL) AS UnlimitedPermStabilizationDate,
SUBSTR(S_CONTACT.MARITAL_STAT_CD,1,1) AS MaritalStatus,
SUBSTR(REFERRER.FST_NAME ||' '|| REFERRER.LAST_NAME,1,34) AS ReferrerName,
ORGEXT_REF.LOC AS ReferrerCentreID,
S_ORG_EXT.LOC AS CentreID,
NULL AS PaymentDateOne,
NULL AS PaymentAmountOne,
NULL AS PaymentDateTwo,
NULL AS PaymentAmountTwo,
NULL AS PaymentDateThree,
NULL AS PaymentAmountThree,
NULL AS PaymentDateFour,
NULL AS PaymentAmountFour,
NULL AS LibraryPurchased,
nvl(S_CONTACT.X_INSTALLMENT_BALANCE,0) + nvl(S_CONTACT.X_PREPAID_BALANCE,0) AS BalanceDue, -- Changed operation from (-) prepaid to (+) prepaid since the sign was flipped in OLTP.
NULL AS FoodNSFBalance,
NULL AS ProductNSFBalance,
NULL AS ProgramNSFBalance,
a2.X_START_WEIGHT AS StartWeight,
a2.X_CURRENT_WEIGHT AS CurrentWeight,
a2.X_GOAL_WEIGHT AS GoalWeight,
a3.X_HEIGHT AS Height,
a2.X_FAXSENT_DATETIME DateGoalWeightAchieved,
DECODE(S_PROD_INT.X_PROGRAM_CLASSIFICATION,'Premium',a.START_DT,NULL) AS DateSuccessPlusPurchased,
CASE WHEN A2.ARCHIVE_FLG = 'N' THEN a2.START_DT ELSE NULL END AS ReturnToActiveDate,
600 VersionNumber,
a2.X_FAXRECV_DATETIME AS HalfWayDate,
NULL AS LastLSCDate,
TRUNC(S_CONTACT.LAST_UPD-UTC_OFFSET/24) AS LastUpdatedDate,
NULL AS VitaminWaiverSigned,
LastSupplementPurchaseDate,
LastSupplementCodePurchased,
LastTotalSupplementSupplyCycle,
LastAddtlSupplPurchaseDate,
LastAddtlSupplCodePurchased,
LastAddtlSupplSupplyCycle,
CASE WHEN (a.X_DIABETES_NO_MEDS_FLG='Y' OR a.X_DIABETES_ORAL_MEDS_FLG = 'Y' OR a.X_DIABETES_ON_INSULIN_FLG = 'Y') THEN 'Y' ELSE 'N' END AS DiabetesClient,
DECODE(a.X_DIABETES_NO_MEDS_FLG,'Y','Y','N') AS DietControlled,
a.X_DIABETES_ORAL_MEDS_FLG AS TakingOralMed,
a.X_DIABETES_ON_INSULIN_FLG AS TakingInsulin,
S_CONTACT.EMAIL_ADDR AS EmailId,
NULL CTADATE,
NULL RWLDATE,
SUBSTR(S_ADDR_PER.ADDR_LINE_2,1,40) AS Address2
FROM S_CONTACT,
S_CONTACT REFERRER,
S_CONTACT Consultant,
S_CONTACT ProgramDirector,
S_CONTACT CallTaker,
S_CONTACT_X,
(SELECT /*+ parallel full(S_CONTACT_XM) */ PAR_ROW_ID, attrib_05, MAX(X_CONSULTATION_DT) AS X_CONSULTATION_DT FROM S_CONTACT_XM
WHERE (S_CONTACT_XM.last_upd_by < '1-14WD'
or S_CONTACT_XM.last_upd_by > '1-14WD')
AND S_CONTACT_XM.ATTRIB_05 IN (SELECT row_id FROM S_ORG_EXT WHERE S_ORG_EXT.ACCNT_TYPE_CD IN ('Corporate Centre','Franchise Centre')) LOC IN (SELECT centreid FROM UPL_LIVE_CENTRES WHERE LIVE = 'Y' AND BATCHID = p_batch_id)) where S_ORG_EXT.ACCNT_TYPE_CD IN ('Corporate Centre','Franchise Centre')) --
GROUP BY PAR_ROW_ID, attrib_05) S_CONTACT_XM,
(SELECT CONTACT_ID, ACCNT_ID,
MAX(LastSupplementPurchaseDate) AS LastSupplementPurchaseDate,
MAX(LastSupplementCodePurchased) AS LastSupplementCodePurchased,
MAX(LastTotalSupplementSupplyCycle) AS LastTotalSupplementSupplyCycle,
MAX(LastAddtlSupplPurchaseDate) AS LastAddtlSupplPurchaseDate,
MAX(LastAddtlSupplCodePurchased) AS LastAddtlSupplCodePurchased,
MAX(LastAddtlSupplSupplyCycle) AS LastAddtlSupplSupplyCycle,
MIN(FirstPurchaseDate) AS FirstPurchaseDate,
MAX(LastPurchaseDate) AS LastPurchaseDate
FROM (
SELECT /*+ parallel full(S_ORDER) full(S_ORDER_XM) */ S_ORDER.CONTACT_ID AS CONTACT_ID,S_ORDER.ACCNT_ID,
NULL AS LastSupplementPurchaseDate,
NULL AS LastSupplementCodePurchased,
NULL AS LastTotalSupplementSupplyCycle,
NULL AS LastAddtlSupplPurchaseDate,
NULL AS LastAddtlSupplCodePurchased,
NULL AS LastAddtlSupplSupplyCycle,
(S_ORDER_XM.X_BUSINESS_DATE) FirstPurchaseDate,
(S_ORDER_XM.X_BUSINESS_DATE) LastPurchaseDate
FROM S_ORDER,S_ORDER_XM
WHERE S_ORDER.ROW_ID = S_ORDER_XM.PAR_ROW_ID
AND S_ORDER.STATUS_CD IN ('Complete', 'Submitted', 'Ready')
AND TRUNC(S_ORDER_XM.X_BUSINESS_DATE - UTC_OFFSET/24) <= (p_business_date)
--GROUP BY S_ORDER.CONTACT_ID
UNION ALL
SELECT /*+ parallel full(S_ORDER) full (S_ORDER_ITEM) */ S_ORDER.CONTACT_ID AS CONTACT_ID,S_ORDER.ACCNT_ID,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN S_ORDER.CREATED ELSE NULL END) AS LastSupplementPurchaseDate,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN 931 ELSE NULL END) AS LastSupplementCodePurchased,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN 7 ELSE NULL END) AS LastTotalSupplementSupplyCycle,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN S_ORDER.CREATED ELSE NULL END) AS LastAddtlSupplPurchaseDate,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN 920 ELSE NULL END) AS LastAddtlSupplCodePurchased,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN 28 ELSE NULL END) AS LastAddtlSupplSupplyCycle,
NULL FirstPurchaseDate,
NULL LastPurchaseDate
FROM S_ORDER,S_ORDER_ITEM, S_PROD_INT
WHERE S_ORDER_ITEM.PROD_ID = S_PROD_INT.ROW_ID
AND S_ORDER.ROW_ID = S_ORDER_ITEM.ORDER_ID
AND S_ORDER_ITEM.qty_req <> 0
AND s_order.created_by <> '1-14WD'
AND S_ORDER_ITEM.PAR_ORDER_ITEM_ID is null
AND (S_ORDER_ITEM.PAR_ORDER_ITEM_ID is null
OR EXISTS (select 1 from S_ORDER_ITEM i2,s_prod_int p
where i2.row_id = S_ORDER_ITEM.PAR_ORDER_ITEM_ID
and SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) IN ('931','920')
and i2.prod_id = p.row_id
AND S_ORDER.status_cd in ('Complete', 'Submitted', 'Ready')
and SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) IN ('931','920')
GROUP BY CONTACT_ID,ACCNT_ID) O,
S_CONTACT_TNTX,
S_ORG_EXT,
S_ORG_EXT ORGEXT_REF,
S_ADDR_PER,
S_ASSET a,
S_PROD_INT,
S_ASSET a2,
S_ASSET a3,
UPL_CLIENT_TYPES ct,
(select /*+ parallel */ o.contact_id, o.accnt_id
from S_ORDER o, S_ORDER_XM oxm
where o.row_id = oxm.par_row_id
and trunc(oxm.X_BUSINESS_DATE - (UTC_OFFSET/24)) = trunc(p_business_date)
group by o.contact_id, o.accnt_id) oxm2
WHERE S_CONTACT.ROW_ID = S_CONTACT_X.PAR_ROW_ID
AND S_CONTACT_X.ROW_ID = S_CONTACT_XM.PAR_ROW_ID (+)
AND (S_ORG_EXT.ROW_ID = S_CONTACT.PR_DEPT_OU_ID
OR S_ORG_EXT.ROW_ID = oxm2.accnt_id
OR S_ORG_EXT.ROW_ID = S_CONTACT_XM.attrib_05)
AND ORGEXT_REF.ROW_ID(+) = REFERRER.PR_DEPT_OU_ID
AND S_CONTACT.CON_ASST_PER_ID = Consultant.ROW_ID
AND S_ORG_EXT.X_DIRECTOR_ID = ProgramDirector.ROW_ID (+)
AND S_CONTACT.CREATED_BY = CallTaker.ROW_ID
AND S_CONTACT.ROW_ID = a.PR_CON_ID (+)
AND S_CONTACT.PR_PER_ADDR_ID = S_ADDR_PER.ROW_ID (+)
AND S_CONTACT_TNTX.PAR_ROW_ID (+) = S_CONTACT.ROW_ID
AND REFERRER.ROW_ID(+) = S_CONTACT_TNTX.REFERRED_BY_ID
AND a.PROD_ID = S_PROD_INT.ROW_ID (+)
AND O.CONTACT_ID (+) = S_CONTACT.ROW_ID
AND a.STATUS_CD (+) = 'Active'
AND a.TYPE_CD (+) ='Program'
AND S_CONTACT.ROW_ID = a2.PR_CON_ID (+)
AND a2.STATUS_CD (+) = 'Active'
AND a2.TYPE_CD (+) = 'Lifecycle'
AND a3.PR_CON_ID(+) = S_CONTACT.ROW_ID
AND a3.STATUS_CD (+) = 'Active'
AND a3.TYPE_CD (+) = 'HealthSheet'
AND S_CONTACT.X_JC_ACNT_NUM = ct.CLIENT_NUMBER (+)
--AND S_ORG_EXT.LOC NOT LIKE 'F%'
AND S_ORG_EXT.ACCNT_TYPE_CD NOT IN 'Division'
--AND S_ORG_EXT.Loc in (select to_char(centreid) from UPL_LIVE_CENTRES where LIVE = 'Y')
AND (trunc(S_CONTACT.LAST_UPD - (UTC_OFFSET/24)) = trunc(p_business_date) or trunc(S_CONTACT_X.LAST_UPD - (UTC_OFFSET/24)) = trunc(p_business_date) OR (S_CONTACT_XM.X_CONSULTATION_DT = p_business_date) OR oxm2.CONTACT_ID IS NOT NULL)
AND S_CONTACT.last_upd_by not in ('1-14WD')
AND oxm2.CONTACT_ID (+) = o.CONTACT_ID
AND S_ORG_EXT.LOC <> 'CW_846'
AND (a.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a.pr_accnt_id is null)
AND (a2.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a2.pr_accnt_id is null)
AND (a3.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a3.pr_accnt_id is null));
rollback;
END;
-------------------------------------------------------------------------------------------------- -
Conditional where, or PL/SQL block as source for an interactive report?
I have this situation: The main screen of my application shows a list of documents. For now, there has to be a quick "security" built in, so administrators can see all documents, but other users can only see the documents they created (login of creator is stored in the documents table). In the future we'll probably use VPD's to enforce some rules, but for now we need a quick solution.
So i stored the administrators in a seperate table. Now i want the interactive report on the main page act as follows:
- If an admin is logged in, it has to have this query: select field 1, field 2, field 3 from documents
- For all other users: select field 1, field 2, field 3 from documents where creator = :app_user
Is this possible in one interactive report? I could make two reports with the different queries and make them conditional according to who is logged in, but this gives me two interactive reports to maintain. Is it possible to use a PL/SQL block as source for the report? I tried, but I get syntax errors. Is it possible to make the where clause conditional on some way?Hi,
Install Demonstration application to your workspace:
Home>Create Application and select Demonstration Application.
Check page 1 interactive report. That should give idea how you do it.
Br, Jari
Maybe you are looking for
-
Home Sharing on iPad gone wrong...please help!
Hi there, I recently found out about home sharing by a friend. So to save space on my iPad I simply download all my music and videos on my computer and then when I want to watch/listen I have the computer switched on and iTunes running and then it al
-
Simple, I need the file to put on a PC which currently does not have a browser.
-
Extreme with LaCie ED Mini Issues
I have a LaCie Ethernet Drive connected to my new AirPort Extreme. I have to MBP's and an HP Tablet connected to the network. No issues with the HP Tablet recognizing the ED Mini. The MBP's with connect to the ED Mini, but won't recognize any files.
-
How to override the dialog "Do you want to save" while closing the form?
HI I have two blocks on the form.Master block is based on a view wheres the detail block is populated by a procedure. Even if the user doesnot change any record and trying to close the form it is still showing the default "Do you want to save" with t
-
Why isn't My AirPrint printer recognized
My iPad 2 lost contact with my AirPrint printer when using the standard AirPrint command, but it will work with quick print pro. How do I get it to AirPrint again?