I have created a standard report page and selected the "cards" for the Report Template (in the Layout and Presentation).
The following is the code that loads the data
DECLARE
l_query VARCHAR2(4000);
l_app number := v('APP_ID');
l_session number := v('APP_SESSION');
//Bug happens on the ':11:' part, page 1 works fine
l_url VARCHAR2(500) := (APEX_UTIL.PREPARE_URL(
p_url => 'f?p=' || l_app || ':11:' || l_session || '::NO:::',
p_checksum_type => 'SESSION'));
BEGIN
l_query:=
'SELECT
post_id,
user_id CARD_SUBTEXT,
image CARD_IMAGE,
title CARD_TITLE,
''' || l_url || ''' CARD_LINK,
text CARD_TEXT
FROM posts';
IF v('P1_TEXT_SEARCH') IS NOT NULL THEN
l_query := l_query||' '||'
WHERE
(
CONTAINS(title, ''' || v('P10_TEXT_SEARCH') || ''') > 0
) OR
(
CONTAINS(text, ''$' || v('P10_TEXT_SEARCH') || ''') > 0
)
';
END IF;
htp.p(l_url || ': ' || l_query);
RETURN l_query;
END;
The l_url variable is my attempt to load the "Post" page which will eventually have the post_id sent in the URL. The page number for the Post page is 11.
When I use "1" (Home page) as the page number it worked fine. But when I used 11 an odd error occurs
Firstly the standard error
1 error has occurred
- 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-00911: invalid character
But the odd part is a line of text is spat out at the very top of the application that says the following:
javascript:apex.navigation.dialog('f?p=4000:11:15325469163221::NO:::\u0026p_dialog_cs=Q1H4HM_OXFo_ZS45s-NOciyBPvE0vUNqa7JH2d-wczZD8Yom-OFjYOrWO4XNE6ciYtHJ0MCQL8cbir4OVFGtUg',{title:'Create Master Detail',height:'480',width:'800',maxWidth:'1200',modal:true,dialog:null,resizable:true,minWidth:500,minHeight:400},'a-Dialog--wizard',this);: SELECT post_id, user_id CARD_SUBTEXT, image CARD_IMAGE, title CARD_TITLE, 'javascript:apex.navigation.dialog('f?p=4000:11:15325469163221::NO:::\u0026p_dialog_cs=Q1H4HM_OXFo_ZS45s-NOciyBPvE0vUNqa7JH2d-wczZD8Yom-OFjYOrWO4XNE6ciYtHJ0MCQL8cbir4OVFGtUg',{title:'Create Master Detail',height:'480',width:'800',maxWidth:'1200',modal:true,dialog:null,resizable:true,minWidth:500,minHeight:400},'a-Dialog--wizard',this);' CARD_LINK, text CARD_TEXT FROM posts Content-Type:text/html; charset=utf-8 Cache-Control:no-store Pragma:no-cache Expires:Sun, 27 Jul 1997 13:00:00 GMT X-Frame-Options:DENY
It's just plain and doesn't look like it's meant to happen.
I tried copying page 11 and trying it on page 12 but that didn't work.
The odd error looks like it could be fixed by allowing embed in frames.
http://www.danielmcghan.us/2011/08/new-browser-security-attributes-in-apex.html
The query parse may have failed if l_url contains quotes, so maybe try
replace(url,'''','"')
And I don't think there's no need to use v() in these locations
IF :P10_TEXT_SEARCH IS NOT NULL THEN -- this also referred to different page
l_app number := :APP_ID;
CONTAINS(title, '$'||:P10_TEXT_SEARCH) > 0
Related
I have a PL/SQL sproc which sends an email, with addressee and such as parameters. We recently migrated it, to a new environment, and switched it from using an internal mail server to using Office 365. In order to do this I needed to upgrade it to use TLS/SSL, which is now working. But it's getting a weird error now.
All of the authentication code works fine, I can transmit the auth, and all the message data, with no issue. But when i call UTL_SMTP.CLOSE_DATA, it throws ORA-06502: PL/SQL: numeric or value error: character string buffer too small.
This section of the code is unchanged from the old environment, where it was working without issue. By this point, I've already concatenated my variables, so I know it's not an issue with my variable sizes. It seems to be something inside the UTL_SMTP package, but that seems to be a compiled package, so I can't even view the stack source to try to figure out what or where the issue is.
Below is our sproc code...
CREATE OR REPLACE PROCEDURE ourschema.SENDMAILTLS
(
vSENDER IN VARCHAR2,
vSENDEE IN VARCHAR2,
vSUBJECT IN VARCHAR2,
vMESSAGE IN VARCHAR2
) AS
vMAILHOST VARCHAR2(255) := ourschema.GETOPTION('SMTPSRV');
oSMTP UTL_SMTP.connection;
vCRLF VARCHAR2(2) := chr(13) || chr(10);
vDATA VARCHAR2(32767);
BEGIN
vDATA := 'Subject:' || vSUBJECT || vCRLF;
vDATA := vDATA || 'Date:' || to_char(SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss') || vCRLF;
vDATA := vDATA || 'From:' || vSENDER || vCRLF;
vDATA := vDATA || 'Content-Type:text; charset=us-ascii' || vCRLF;
vDATA := vDATA || 'Reply-To:' || vSENDER || vCRLF;
vDATA := vDATA || 'Sender:' || vSENDER || vCRLF;
vDATA := vDATA || vCRLF;
vDATA := vDATA || vMESSAGE || vCRLF;
vDATA := vDATA || vCRLF;
ourschema.LOG('TLS Email sending from ' || vSENDER || ' to ' || vSENDEE || ' via ' || vMAILHOST || '.', vDATA);
utl_tcp.close_all_connections();
oSMTP := UTL_SMTP.open_connection(vMAILHOST, TO_NUMBER(ourschema.GETOPTION('SMTPPORT')), wallet_path => 'file:O:\ur\Wallet\Path', wallet_password => 'OurWalletPassword');
UTL_SMTP.EHLO(oSMTP, vMAILHOST);
UTL_SMTP.STARTTLS(oSMTP);
UTL_SMTP.EHLO(oSMTP, vMAILHOST);
UTL_SMTP.AUTH(oSMTP, 'U******', 'P******', UTL_SMTP.ALL_SCHEMES);
UTL_SMTP.mail(oSMTP, ourschema.GETOPTION('SMTPADDR'));
UTL_SMTP.rcpt(oSMTP, vSENDEE);
UTL_SMTP.open_data(oSMTP);
UTL_SMTP.write_data(oSMTP, vDATA);
UTL_SMTP.close_data(oSMTP);
UTL_SMTP.quit(oSMTP);
ourschema.LOG('TLS Email sent successfully from ' || vSENDER || ' to ' || vSENDEE || ' via ' || vMAILHOST || '.', vDATA);
END;
The line it is failing on is
UTL_SMTP.close_data(oSMTP);
And this is the test script I'm using. No massive amounts of data that would blow anything out.
begin
-- Call the procedure
idsystem.SENDMAILTLS(vSENDER => 'notifications#ourdomain.com',
vSENDEE => 'myemail#ourdomain.com',
vSUBJECT => 'Testing Oracle Email',
vMESSAGE => 'Did you get this yet?');
end;
And here's the error message... with the stack trace showing it's coming from somewhere deep in the UTL_SMTP package.
But if I say Yes to view the stack source, this is all that comes up for the UTL_SMTP package... so I can't even begin to make heads or tails of how I may be offending it.
Oracle version is 12c Standard, 12.2.0.1.0
Based on the stack trace it looks like the receiver end is sending data greater than 512 characters. This means basically the e-mail that you are sending might have some issue that generates huge data as a response.
The problem might be
recepeint email id is nonexistent
Email attachment is invalid etc
ourschema.GETOPTION('SMTPADDR') should be a valid sender
To understand the issue try sending the same email from your email application and if it success and doesn't generate a large response then please check your configuration.
I'm trying to create a pl/sql query that fetches certain data and from tables and outputs the data. Here is what I have tried but I keep getting an error and I cannot begin to see where the problem is.
SET SERVEROUTPUT ON
DECLARE
TEMP_CUSTNAME CUSTOMER.FIRST_NAME%TYPE;
TEMP_CUSTSURNAME CUSTOMER.SURNAME%TYPE;
TEMP_COINPUR COIN.PRODUCT%TYPE;
TEMP_CPRICE COIN.PRICE%TYPE;
TEMP_DNOTES COIN_DELIVERY.DELIVERY_NOTES%TYPE;
CURSOR CURSOR1 IS
SELECT C.FIRST_NAME,C.SURNAME FROM CUSTOMER C, COIN.PRODUCT, COIN.PRICE, COIN_DELIVERY.DELIVERY_NOTES
WHERE COIN.PRICE > 8000;
BEGIN
OPEN CURSOR1;
LOOP
FETCH CURSOR1 INTO TEMP_CUSTNAME, TEMP_CUSTSURNAME, TEMP_COINPUR, TEMP_CPRICE, TEMP_DNOTES;
EXIT WHEN CURSOR1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE ('CUSTOMER: ' || TEMP_CUSTNAME || ',' ||TEMP_CUSTSURNAME);
DBMS_OUTPUT.PUT_LINE ('COIN: ' || TEMP_COINPUR || );
DBMS_OUTPUT.PUT_LINE ('PRICE: ' || TEMP_CPRICE || );
DBMS_OUTPUT.PUT_LINE ('NOTES: ' || TEMP_DNOTES || );
DBMS_OUTPUT.PUT_LINE ('------------------------------------' );
END LOOP;
CLOSE CURSOR1;
END;
It would be helpful if you've provided us with the error you're facing.
So far I see number of fields in the cursor (2) is not the same as number of variables being fetched into (5).
In other words, you need to add more columns here:
SELECT C.FIRST_NAME,C.SURNAME FROM CUSTOMER C, COIN.PRODUCT, COIN.PRICE,
so there will be enough data to fetch to this variables here:
FETCH CURSOR1 INTO TEMP_CUSTNAME, TEMP_CUSTSURNAME, TEMP_COINPUR, TEMP_CPRICE, TEMP_DNOTES;
Or, probably, you need to reduce number of variable you're fetching into like this. It depends on result you're trying to achieve
FETCH CURSOR1 INTO TEMP_CUSTNAME, TEMP_CUSTSURNAME;
UPD. wrong concatenation. Based on the error message from comments I see now there are problems here too. Remove trailing "||" in lines below
DBMS_OUTPUT.PUT_LINE ('COIN: ' || TEMP_COINPUR || );
DBMS_OUTPUT.PUT_LINE ('PRICE: ' || TEMP_CPRICE || );
DBMS_OUTPUT.PUT_LINE ('NOTES: ' || TEMP_DNOTES || );
Impossible to get back the Query result for PL/SQL scripts. It was working fine earlier in the afternoon but something might have gone wrong and now results have vanished from screen. What should I do?
Thank you!
The dummy query is just an example even if I should also get DUMMY as column header and X as a unique record in a "Query result" tab. In fact my script is such as below and works but gives no viewable data because the "Query Result" has gone. Before to reinstall Oracle SQL Dev I am wondering if on trick exists to fix this point for which I have found no valuable fix so far.
declare
v_tab varchar( 30 ):= 'MD_ALL_DETAIL_';
v_date1 varchar( 30 ):= '0827D';
v_date2 varchar( 30 ):= '0830';
v_tab1 varchar( 30 );
v_tab2 varchar( 30 );
v_sql varchar( 2000 );
begin
v_tab1 := v_tab || v_date1;
v_tab2 := v_tab || v_date2;
v_sql := '
with tab as(
select ' || v_date1 || ' flag, md1.*
from ' || v_tab1 || ' md1
union all
select ' || v_date2 || ' flag, md2.*
from ' || v_tab2 || ' md2
), tab2 as (
select *
from(
select tab.flag, tab.cat_mk_code, tab.cat_mk_iden, tab.b_entity_code, tab.b_entity_iden, tab.cat_be_code, tab.cat_be_iden, tab.bucket_code, tab.
bucket_iden, tab.m_entity_code, tab.application_code, tab.indicator_code, tab.indicator_iden, tab.measure_value, tab.user_code, tab.lock_flag,
tab.alter_date, tab.table_name
from tab
)pivot(
sum( measure_value )
for flag
in( ' || v_date1 || ' as MEASURE_0, ' || v_date2 || ' as MEASURE_1 )
) )
select * from tab2 where MEASURE_0<>MEASURE_1';
execute immediate v_sql;
end;'
This code (at the screenshot) doesn't do anything, so message you got ("PL/SQL procedure successfully completed") is all you can expect.
Run e.g.
select * from dual;
and SQL Developer will automatically open the missing "Query Result" tab.
If you want to "display" the result of a dynamic SQL, you'll have to select it into something. A simple example:
See? I'm selecting from DUAL (as your initial query does) INTO a local variable. The result is displayed within the Script output tab.
Your "new" code uses a more complex query, possibly returning more than a single column/row so you can't select into a scalar variable. I presume you'll have to create a TYPE, declare a local variable (a collection, probably) and then do something with the result.
https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/executeimmediate_statement.htm#LNPLS01317
If dynamic_sql_statement is a SELECT statement, and you omit both into_clause and bulk_collect_into_clause, then execute_immediate_statement never executes.
For example, this statement never increments the sequence:
EXECUTE IMMEDIATE 'SELECT S.NEXTVAL FROM DUAL'
I faced with a situation where one the columns data to be uploaded exceeded 255 and it threw Error Field in data file exceeds maximum length error.
I found a way to fix it. Please find link here explaining the logic.
The question is that in a control file, is there any difference between
Comments CHAR(255) "TRIM(:Comments)" ,
and
Comments CHAR "TRIM(:Comments)" ,
when it comes to the internal workings of sqlldr or it means the same right ?
Also while uploading, because the integrity of the data file cannot be trusted, we create a table with all columns as 255 [which i will fix for columns > 255 length] and I never specify the CHAR length in the control file.
I would like to know if the difference between
using default 255 for all columns
vs
keeping little extra than expected length [actual target table column length values] eg. actual expected length [which might range from 10 to 150 etc.] + 50/100
is very significant if i use sqlldr atleast 2000 times a day on small data files with average of 250 records.
Thanks in advance for the clarification.
I think they are the same as internally that is what the buffer size is as well.
After dealing with this enough times I created a real rough utility script that generates a skeleton control file that uses the column's actual size. It gets me 90% of the way there and no column sizing issues. It may be better on memory as its not going to use the full 255 chars available if the column is smaller. Give it a try if you want. It may give you some ideas anyway.
/********************************************************************************************************
Name: GEN_CTL_FILE
Desc: Generates a skeleton control file for loading data via SQL*Loader.
Args: tablename_in IN VARCHAR2, delim_in IN VARCHAR2 DEFAULT '|'
Returns: None.
Usage: utilities.gen_ctl_file('tablename');
Notes: Prints a skeleton control file.
If a template for a fixed-length data file is desired, use 'FIXED' for the delim_in string.
FIXED needs more work to put actual lengths in. For now just placeholders.
Example usage:
set serveroutput on;
execute utilities.gen_ctl_file('test', utilities.TAB);
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.1 6/6/2013 gary_w - Created procedure.
1.2 10/8/2013 gary_w - Fixed decode statement.
- Added option to generate a fixed-length template.
************************************************************************************************************************/
PROCEDURE GEN_CTL_FILE(tablename_in IN VARCHAR2, delim_in VARCHAR2 DEFAULT '|') IS
ERRNULLTABLENAME CONSTANT NUMBER := -20103; -- User-defined error numbers and messages.
ERRNULLTABLENAMEMSG CONSTANT VARCHAR2(100) := 'A table name is required.';
USAGE CONSTANT VARCHAR2(100) := '* USAGE: UTILITIES.GEN_CTL_FILE(tablename_in IN VARCHAR2, fieldsep_in VARCHAR2 DEFAULT ''|'')';
v_delim VARCHAR2(20) := NVL(delim_in, '|');
CURSOR COL_CUR IS
SELECT COLUMN_NAME,
DECODE(COLUMN_ID, 1, ' ', ',') || RPAD(COLUMN_NAME, 32) || case upper(v_delim)
when 'FIXED' then 'POSITION(99:99) '
else NULL
end|| DECODE(DATA_TYPE,
'VARCHAR2', 'CHAR('||DATA_LENGTH||') NULLIF(' || COLUMN_NAME || '=BLANKS)',
'FLOAT', 'DECIMAL EXTERNAL NULLIF(' || COLUMN_NAME || '=BLANKS)',
'NUMBER', DECODE( DATA_PRECISION,
0, 'INTEGER EXTERNAL NULLIF (' || COLUMN_NAME || '=BLANKS)',
DECODE(DATA_SCALE, 0, 'INTEGER EXTERNAL NULLIF (' || COLUMN_NAME || '=BLANKS)', 'DECIMAL EXTERNAL NULLIF (' || COLUMN_NAME || '=BLANKS)')),
'DATE', 'DATE "MM/DD/YYYY" NULLIF (' || COLUMN_NAME || '=BLANKS)',
data_type)
AS COL_DATA
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = UPPER(tablename_in)
ORDER BY COLUMN_ID;
BEGIN
IF tablename_in IS NULL THEN
RAISE_APPLICATION_ERROR(ERRNULLTABLENAME, ERRNULLTABLENAMEMSG || CR || USAGE);
END IF;
DBMS_OUTPUT.PUT_LINE('--');
DBMS_OUTPUT.PUT_LINE('-- NOTE - When using DIRECT=TRUE to perform block inserts to a table,');
DBMS_OUTPUT.PUT_LINE('-- the table''s triggers will not be used! Plan accordingly to');
DBMS_OUTPUT.PUT_LINE('-- manually perform the trigger actions after loading, if needed.');
DBMS_OUTPUT.PUT_LINE('--');
DBMS_OUTPUT.PUT_LINE('OPTIONS (DIRECT=TRUE)');
DBMS_OUTPUT.PUT_LINE('UNRECOVERABLE');
DBMS_OUTPUT.PUT_LINE('LOAD DATA');
DBMS_OUTPUT.PUT_LINE('APPEND');
DBMS_OUTPUT.PUT_LINE('INTO TABLE ' || UPPER(tablename_in));
DBMS_OUTPUT.PUT_LINE('EVALUATE CHECK_CONSTRAINTS');
if upper(v_delim) != 'FIXED' then
DBMS_OUTPUT.PUT_LINE('FIELDS TERMINATED BY ' || '''' || v_delim || '''');
DBMS_OUTPUT.PUT_LINE('OPTIONALLY ENCLOSED BY ''"'' ');
DBMS_OUTPUT.PUT_LINE('TRAILING NULLCOLS');
end if;
DBMS_OUTPUT.PUT_LINE('(');
-- The cursor for loop construct implicitly opens and closes the cursor.
FOR COL IN COL_CUR
LOOP
IF COL.COLUMN_NAME != 'LOAD_DATE' THEN
IF COL.COLUMN_NAME = 'LOAD_SEQ_ID' THEN
dbms_output.put_line(','||RPAD('LOAD_SEQ_ID', 32)||'CONSTANT 0');
ELSE
DBMS_OUTPUT.PUT_LINE(COL.COL_DATA);
END IF;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE(')' || CHR(10));
EXCEPTION
WHEN OTHERS THEN
RASIE;
END; -- GEN_CTL_FILE
The output looks like this:
--
-- NOTE - When using DIRECT=TRUE to perform block inserts to a table,
-- the table's triggers will not be used! Plan accordingly to
-- manually perform the trigger actions after loading, if needed.
--
OPTIONS (DIRECT=TRUE)
UNRECOVERABLE
LOAD DATA
APPEND
INTO TABLE TEST
EVALUATE CHECK_CONSTRAINTS
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
COLA CHAR(200) NULLIF(COLA=BLANKS)
,COLB CHAR(100) NULLIF(COLB=BLANKS)
,COLC CHAR(500) NULLIF(COLC=BLANKS)
,COLD DECIMAL EXTERNAL NULLIF (COLD=BLANKS)
,COLE CLOB
)
If you tweak it, please share your changes.
I am building stacked column 3d Flash chart in Oracle Apex. it is based on the PL/SQL returning SQL query. PL/sql is required to capture all types of properties and count number of instances in database connected to those properties. The code is :
DECLARE
l_qry VARCHAR2(32767);
v_id NUMBER;
v_resort VARCHAR2(80);
BEGIN
l_qry := 'SELECT ''fp=&APP_ID.:802::app_session::::P5_SEARCH_MONTH:''||TO_CHAR(E.ENQUIRED_DATE,''MON-YY'')||'':'' link,';
l_qry := l_qry || ''' ''||TO_CHAR(E.ENQUIRED_DATE,''MON-YY'')||'':'' label,';
--Loop through the resorts and add a sum(decode...) column with column alias
FOR r1 IN (SELECT DISTINCT a.resort_id FROM enquiry a, resort b where a.resort_id IS NOT NULL and a.resort_id = b.id and b.active =1)
LOOP
select name into v_resort
from resort
where id = r1.resort_id;
What happens now PLSQL is loping through all resorts and counts them. this solution does work to certain degree however after value returned I want to have label with name of resort taken from v_resort. It is where main difficulty is
l_qry := l_qry || 'sum(decode(resort_id,''' || r1.resort_id ||''',1,0)) test,';
l_qry := l_qry || 'sum(decode(resort_id,''' || r1.resort_id ||''',1,0)) '|| v_resort||',';
First line will display 'test' label when you hover over the columns just fine. However the the second one with '|| v_resort ||' will cause issue with not displaying back any results... it is not giving #no_data_found# message but just blank field..
The rest of the code :
END LOOP;
--Trim off trailing comma
l_qry := rtrim(l_qry, ',');
--Append the rest of the query
l_qry := l_qry || ' from ENQUIRY E,resort r
where
e.enquiry_type=''AVAILR''
and e.enquiry_channel like '''||:P5_CHANNEL||'''
and trunc(e.created) >= '''||:P5_DATE_FROM||'''
and trunc(e.created) <= '''||:P5_DATE_TO||'''
and e.ENQUIRED_DATE > '''||:P5_DATE_FROM||'''
and ((NVL(:P5_AVAILABLE,''A'')=''A'') or ('''||:P5_AVAILABLE||'''=AVAILABLE))
and e.resort_id = r.id
and ((resort_id = '''||:P6_RESORT||''') or ('''||:P6_RESORT||''' like ''0''))
group by To_Char(ENQUIRED_DATE,''MON-YY''),TO_CHAR(ENQUIRED_DATE,''YYMM'')
Order By TO_CHAR(ENQUIRED_DATE,''YYMM'')';
return(l_qry);
END;
I tired '|| v_resort ||' , '''||v_resort||''' . Any other ideas how to create value of label to be taken from v_resort which holds resort name ?
Try "'||v_resort||'"
You have to use a quoted identifier since v_resort can be any string and there are many rules for unquoted names.