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,
Pa
I'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
Similar Messages
-
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. -
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. -
Using sql command, how do I get rid of the 'to' in my string
Factoryto_510 ->> Factory_510
Thank you very much!REPLACE
-
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; -
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 -
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). -
Comma delimeted string in IN clause of PL/SQL block
Hi,
I am using string having comma separted string in IN clause of PL/SQL block.
But it does not give me right result.
If i m using sql query then give me result.
I m using oracl 10g and following code. DEPT table having 'miller' and 'cleark' ename rows.
Can you please suggest the other way to get proper result.
declare
cnt number:=0;
strin varchar2(40);
begin
strin:='miller,cleark';
select count(*)
into cnt
from dept
where ename in (strin);
dbms_output.put_line('cnt:-'||cnt);
end;Thanks.Apart from the solutions you've already been given, let's be clear...
user548963 wrote:
I am using string having comma separted string in IN clause of PL/SQL block.
But it does not give me right result.Yes it does, it's giving exactly the expected result for what you have provided. It may not be what you're desiring, but it's absolutely correct.
The IN Clause is expecting multiple arguments to be in the set of data. You are providing it with a single argument... a single string. Just because your string has got commas in it does not make that string into multiple arguments. -
Connect by - sql help : getting error ORA-01489: result of string concatena
here is an sql query and I am trying to cook a decode but since there are many columns invloved when I am trying to run this I am getting the following error:
ORA-01489: result of string concatenation is too long
Any kind of help is appreciated, I need to get this going otherwise I am dead :(
Regards
Rahul
SQL:
select sys_connect_by_path(c.decode_prep,'-') decode_prep
from (select 'DECODE(BIAPPS_11.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||','||'RAHULKALRA.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||',''1'',''0'')' decode_prep, rownum curr, rownum -1 prev
from (select rownum rn
from dual connect by rownum <=
(select (length('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM')
- length(replace('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM',',')))+1 total_cols
from dual)) a, (select ','||'ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM'||',' all_cols from dual) b) c
start with curr = 1
connect by prior curr = prev
order by length(sys_connect_by_path(c.decode_prep,'-')) desc
same as above sql only difference is here I am pulling the first record from the result set which above query returns :
select ltrim(replace(decode_prep,'-','||'),'||') decode_prep
from (select sys_connect_by_path(c.decode_prep,'-') decode_prep
from (select 'DECODE(BIAPPS_11.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||','||'RAHULKALRA.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||',''1'',''0'')' decode_prep, rownum curr, rownum -1 prev
from (select rownum rn
from dual connect by rownum <=
(select (length('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM')
- length(replace('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM',',')))+1 total_cols
from dual)) a, (select ','||'ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM'||',' all_cols from dual) b) c
start with curr = 1
connect by prior curr = prev
order by length(sys_connect_by_path(c.decode_prep,'-')) desc)
where rownum = 1
Edited by: Mac_Freak_Rahul on Nov 28, 2012 1:31 AM : in the first sql ')'
removed after desc in the last line so now this query will run and throw an error.Clearly your error is because the string concatenation you are doing with sys_connect_by_path is exceeding the 4000 bytes permitted by SQL.
In that case you need to concatenate your data into a CLOB datatype, for which you'll need a CLOB aggregation function...
create or replace type clobagg_type as object
text clob,
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number
create or replace type body clobagg_type is
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
begin
sctx := clobagg_type(null) ;
return ODCIConst.Success ;
end;
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
begin
self.text := self.text || value ;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
begin
returnValue := self.text;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number is
begin
self.text := self.text || ctx2.text;
return ODCIConst.Success;
end;
end;
create or replace function clobagg(input clob) return clob
deterministic
parallel_enable
aggregate using clobagg_type;
SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
ENAMES
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 'PFL' c1, 0 c2,110 c3 from dual union all
3 select 'LHL', 0 ,111 from dual union all
4 select 'PHL', 1, 111 from dual union all
5 select 'CHL', 2, 111 from dual union all
6 select 'DHL', 0, 112 from dual union all
7 select 'VHL', 1, 112 from dual union all
8 select 'CPHL', 0, 114 from dual union all
9 select 'WDCL', 1, 114 from dual union all
10 select 'AHL' ,2 ,114 from dual union all
11 select 'NFDL', 3, 114 from dual)
12 --
13 -- end of test data
14 --
15 select trim(clobagg(c1||' ')) as c1, c3
16 from (select * from t order by c3, c2)
17 group by c3
18* order by c3
SQL> /
C1 C3
PFL 110
LHL CHL PHL 111
DHL VHL 112
CPHL AHL NFDL WDCL 114 -
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; -
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> -
Execute a string containing a PL/SQL block
Hi,
I would like to build a string containing a PL/SQL block and execute it dynamically. Is there way to do this.
Note - The reason I want to this is because, based on certain table data dictionary views the declaration section of the PL/SQL block that I am building might vary
I tried to use EXECUTE IMMEDIATE, it didn't work, pls let me know if I am missing something.
DECLARE
v_str VARCHAR2(1000);
BEGIN
v_str := 'BEGIN NULL; END';
EXECUTE IMMEDIATE v_str;
END;
/Hi,
Just happened to find it. EXECUTE IMMEDIATE can be used, the bug with my code was I didn't have a ; after the END statement. Corrected code is below, thanks for your time
DECLARE
v_str VARCHAR2(1000);
BEGIN
v_str := 'BEGIN NULL; END;';
EXECUTE IMMEDIATE v_str;
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
Maybe you are looking for
-
Down payment request to the purchase order as a whole
Hi Gurus I want to post vender down payments request and make the relation with the purchase order. Up to now the systems ask for the purchase order number (mandatory) and the line item number (mandatory) As we have with our customer PO's with someti
-
Profit center assignment for Tax Component value in MIRO
Dear SAP Gurus, As per our clents requirement the Tax component has to be posted to a Profit Center while doing MIRO. How to deal with this. Profit center default assign during MM transaction Account Assigned PO: 1. The Cost center/Asset and GL
-
Hp pavilion zx5180us drivers for hp usb digial drive
I am fixing up a zx5180us that has one device driver missing in windows xp. sm bus controller... I have installed all drivers listed on web site but there is nothing listed for a hp usb digital drive that is above the cd rom... this is the first unit
-
File Dialog's using Remote Panels (via web server)
I am aware that the web server remote panel access will not allow us to open a file dialog box on a remote computer. I have read people comment that you should create your own file dialog box, using LabVIEW to use instead of the file dialog box. Has
-
Issue Exporting TIFF Files in Lightroom 3
When exporting files from Lightroom in a TIFF Format Lightroom is applying specific dimensions to my photos. How do I make this stop so my files maintain the original image size? For example. Original Photo - 4256 x 2832, 10.8MB .NEF File shot on D7