Generate a report from oracle forms into RTF format - oraclereports

I have a report that I called from Oracle Forms 6i. My issue is that when I run the report directly from Oracle Forms, it does not generate output file. I want to generate the report directly into a RTF format.
Below is the code I used to call and generate the report from Oracle forms (trigger WHEN_BUTTON_PRESSED):
/* Formatted on 2008/11/01 12:59 (Formatter Plus v4.8.0) */
DECLARE
v_org_id NUMBER;
l_res_create NUMBER;
v_cust_num VARCHAR2(10);
v_err NUMBER;
BEGIN
v_org_id := Fnd_Profile.VALUE ('ORG_ID');
v_err := 0;
BEGIN
SELECT CUSTOMER_NUM
INTO v_cust_num
FROM xx_org_parties
where header_id = :XXPARTYDET.HEADER_ID;
EXCEPTION
WHEN OTHERS
THEN
Fnd_Message.set_string ('Customer Not Created');
Fnd_Message.show;
RAISE form_trigger_failure;
v_err := 1;
END;
--------------------------------------------------------
BEGIN
IF v_err = 0
THEN
l_res_create :=
Fnd_Request.submit_request ('XXNIR',
'XX_WELCOME_LTR',
NULL,
NULL,
FALSE,
v_org_id,
v_cust_num,
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0),
CHR (0)
);
--,
--CHR(0));
:SYSTEM.message_level := 25;
COMMIT_FORM;
Fnd_Message.DEBUG ( 'Your request # '
|| l_res_create
|| ' has submitted'
);
:parameter.P_REQUEST_ID:= l_res_create;
END IF;
EXCEPTION
WHEN OTHERS
THEN
Fnd_Message.DEBUG ('Error ' || SQLCODE || ',' || SQLERRM);
-- exit;
END;
END;
Please guide me in this regard.
Thanks,
Shashikant

Related

update an existing row with new rows and data from another table

I have simply
CREATE table1
(
common INT,
var1 VARCHAR,
var2 VARCHAR,
var3 VARCHAR,
var4 VARCHAR,
var5 VARCHAR,
var6 VARCHAR
)
CREATE table2
(
common INT,
var4 VARCHAR,
var5 VARCHAR,
var6 VARCHAR
)
INSERT table1 VALUE(0,"test1","test2","test3",NULL,NULL,NULL)
INSERT table2 VALUE(0,"test4","test5","test6")
What I'm trying to get in table1's 1st row or where common = 0:
row1:
common = 0,
var1 = "test1",
var2 = "test2",
var3 = "test3",
var4 = "test4",
var5 = "test5",
var6 = "test6"
Instead I get:
row1:
common = 0,
var1 = "test1",
var2 = "test2",
var3 = "test3",
var4 = NULL,
var5 = NULL,
var6 = NULL
row2:
common = 0,
var1 = NULL,
var2 = NULL,
var3 = NULL,
var4 = "test4",
var5 = "test5",
var6 = "test6"
I've tried using an INSERT INTO.. SELECT statement but only get new rows not new data in table1's rows where common = 0
INSERT INTO table1 (table1.var4,table1.var5,table1.var6)
SELECT table2.var4, table2.var5, table2.var6
FROM table2
WHERE common = 0
I understand why this only adds a row but is there a way to update an existing row with new rows and data from another table in more or less the same fashion?
You could write an after INSERT trigger ON table2 and inside update table 1
Like
DELIMITER $$
CREATE TRIGGER after_members_insert
AFTER INSERT
ON table2 FOR EACH ROW
BEGIN
UPDATE table1 SET var4 = NEW.var4,var5 = NEW.var5,var6 = NEW.var6
WHERE common = NEw.common
END$$
DELIMITER ;
If the column in table1 doesn't exists, you will loose the insert.
If you want to insert a new row in table1, you wmust check with
IF EXISTS(SELECT 1 FROM table1 WHERE common = NEW.common) THEM
if a column already exists. and then deside what to do.
So often I find myself answering my own questions
UPDATE table1 a
INNER JOIN table2 b ON a.common = b.common
SET a.var4=b.var4,a.var5=b.var5,a.var6=b.var6
WHERE a.common=b.common
does exactly what I needed and follows suit with the simple syntax of the INSERT statement.

Alternate of IN operator or Replace IN operator from function in query?

i have a query and i need the same
without using the IN operator
here is query
create function registerStudent(
in s_id varchar(5),
in s_courseid varchar (8),
in s_secid varchar (8),
in semester varchar (6),
in s_year numeric (4,0),
out errorMsg varchar(100) returns integer
begin
declare currEnrol int;
select count(*) into currEnrol from takes
where course_id = s_courseid
and secid = s_secid
and semester = s_semester
and year = s_year;
declare limit int;
select capacity into limit
from classroom
natural join section
where course_id = s_courseid
and secid = s_secid
and semester = s_semester
and year = s_year;
if (currEnrol < limit) begin
insert into takes values (s_id, s_courseid, s_secid, s_semester, s_year, null);
return(0);
end
set errorMsg = 'Enrollment limit reached for course ' I I s_courseid II ' section ' I I s_secid;
return(-1);
end;
you list all parameters of the stored function inside the parentheses. By default, all parameters are IN parameters. You cannot specify IN , OUT or INOUT modifiers to the parameters.
create function registerStudent(
s_id varchar(5),
s_courseid varchar (8),
s_secid varchar (8),
semester varchar (6),
s_year numeric (4,0),
out errorMsg varchar(100)
) returns integer
begin
declare currEnrol int;
select count(*) into currEnrol from takes
where course_id = s_courseid
and secid = s_secid
and semester = s_semester
and year = s_year;
declare limit int;
select capacity into limit
from classroom
natural join section
where course_id = s_courseid
and secid = s_secid
and semester = s_semester
and year = s_year;
if (currEnrol < limit) begin
insert into takes values (s_id, s_courseid, s_secid, s_semester, s_year, null);
return(0);
end
set errorMsg = 'Enrollment limit reached for course ' I I s_courseid II ' section ' I I s_secid;
return(-1);
end;

Check for Invalid UPC in MySQL

I have a mysql table with a colummn of UPC codes.
How would I go about checking for invalid ones?
There is a site here http://www.ehow.com/how_6810204_verify-upc-number.html which shows the procedure for verifying a UPC, but how would one translate this into a mysql query or function.
Here is a MySQL function that calculates the check digit for a UPC aka GTIN code:
DELIMITER $$
CREATE DEFINER=`databasename`#`%` FUNCTION `gs1_checkdigit`(base VARCHAR(17)) RETURNS char(1) CHARSET utf8
DETERMINISTIC
BEGIN
##
## NAME
## gs1_checkdigit -- calculate checkdigit for barcode numbers
##
## SYNOPSIS
## check_digit = gs1_checkdigit("NUMBER_WITHOUT_CHECKDIGIT")
##
## DESCRIPTION
## Given a GS1 input identifier (company_prefix + product_id)
## without a check digit, returns the check digit that should
## be appended to the input to be a valid identifier.
##
## Can be used for inputs of any length. This is to accommodate
## various GS1 standards ranging from GTIN-8 (7 input digits) to
## SSCC (17 input digits). This function does NOT validate the
## input length -- i.e. there is no valid 15-digit input length
## in the GS1 standard, but this function will accept 15 digits.
##
## OPTIONS
## base Input digits as a VARCHAR
##
## RETURNS
## Check digit as a CHAR(1)
##
## EXAMPLES
## SELECT gs1_checkdigit("05042829526")
## --> 7
##
## NOTES
## Formula: http://www.gs1.org/how-calculate-check-digit-manually
##
## Test cases: https://www.gs1us.org/tools/build-a-sample-upc-barcode
##
##------------------------------------------------------------------------
##
## Local variables
DECLARE odds INTEGER DEFAULT 0; ## sum of odd positions
DECLARE evens INTEGER DEFAULT 0; ## sum of even positions
DECLARE total INTEGER DEFAULT 0; ## position-weighted sum
DECLARE len INTEGER; ## input string length
DECLARE pos INTEGER DEFAULT 0; ## current digit position
DECLARE digit INTEGER; ## current digit as INT
DECLARE cd INTEGER; ## check digit for output
##
## Main calculation
SET len = LENGTH(base);
mainloop: LOOP
##
## Get digits, from the right
SET digit = CAST(SUBSTRING(base, len-pos, 1) AS SIGNED INTEGER);
##
## Example:
##
## Input "12345678901" -- "X" is check digit placeholder
## +-+-+-+-+-+-+-+-+-+-+-+-+
## |1|2|3|4|5|6|7|8|9|0|1|X|
## +-+-+-+-+-+-+-+-+-+-+-+-+
## | |
## "pos" 10 position "pos" 0 position
##
## Weighting factor by position
## +-+-+-+-+-+-+-+-+-+-+-+-+
## |3|1|3|1|3|1|3|1|3|1|3|0|
## +-+-+-+-+-+-+-+-+-+-+-+-+
##
##
## Test cases:
##
## SELECT gs1_checkdigit('04210000526'); ## 4
## SELECT gs1_checkdigit('03600029145'); ## 2
## SELECT gs1_checkdigit('05042829526'); ## 7
## SELECT gs1_checkdigit('19147000000'); ## 0
## SELECT gs1_checkdigit('19147056187'); ## 7
## SELECT gs1_checkdigit('19147099999'); ## 1
## SELECT gs1_checkdigit('62910415002'); ## 4
##
IF (pos % 2 = 0)
THEN
SET evens = evens + digit;
ELSE
SET odds = odds + digit;
END IF;
##
## Bump the loop
SET pos = pos + 1;
IF (pos < LEN)
THEN
ITERATE mainloop;
END IF;
LEAVE mainloop;
END LOOP mainloop;
##
## GTIN formula
SET total = odds + (3 * evens);
SET cd = total % 10;
IF (cd <> 0)
THEN
SET cd = 10 - cd;
END IF;
##
RETURN (CAST(cd AS CHAR));
END$$
DELIMITER ;
You can find invalid UPCs aka GTINs with a query like this:
SELECT
upcfield as bad_upc
FROM
upctable
WHERE
RIGHT(upcfield, 1) <> gs1_checkdigit(LEFT(upcfield, LENGTH(upcfield)-1);

How to extract the first number of a data in mysql?

for example,
I have a dataset as below:
asdf1234asdf
1235asdfasdf
asdfasdfef489
How could I select such that I can get a result as below?
1234
1235
489
If your MySQL version supports it, create a function and use such as regex, to extract the first digits:
DELIMITER $$
CREATE FUNCTION first_digits(str TEXT)
RETURNS TEXT
BEGIN
DECLARE ret TEXT DEFAULT '';
DECLARE chr TEXT DEFAULT '';
DECLARE i INT DEFAULT 1;
WHILE i < (LENGTH(str) + 1) DO
SET chr = SUBSTRING(str, i, 1);
IF chr REGEXP '[0-9]'
THEN SET ret = CONCAT(ret, chr);
ELSEIF ret != ''
THEN RETURN ret;
END IF;
SET i = i + 1;
END WHILE;
RETURN ret;
END;
$$
DELIMITER ;
Then just SELECT desired column with newly created function first_digits();
SELECT first_digits('asdf1234asdf') num;
num
1234
To extract all digits (not only first), drop the ELSEIF part and rename the function such as digits.
To drop the function:
DROP FUNCTION IF EXISTS first_digits;
Hope this helps!
MySQL, unfortunately, doesn't have a good way of replacing regexes, but if you have only one numerical sequence, you could use trim:
SELECT TRIM(BOTH 'abcdefghijklmnopqrstuvwxyz' FROM word)
FROM (SELECT 'asdf1234asdf' AS word
UNION ALL
SELECT '1235asdfasdf'
UNION ALL
SELECT 'asdfasdfef489') t

MySql Pass value from a select to variables

In MySql, how can I load values from a select that's inside a function, into variables inside a function?
That select returns only a single row.
Table
"id" "type" "parent" "userName" "userId" "country"
"5" "1" "1" "norman" "1" "US"
"6" "2" "5" "norman" "1" "US"
"7" "3" "6" "norman" "1" "US"
"8" "10" "7" "norman" "1" "US"
"9" "1" "1" "james" "2" "UK"
Function
CREATE DEFINER=`root`#`localhost` FUNCTION `mainLinks`(`id` INT)
RETURNS varchar(1500)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
//Something like this:
DECLARE i INT(10);
SET i = id;
select id, type, parent, userName, userId, country from myTable where id=i;
//Load values from the above select into variables that can be used all over the function. Here's where I'm stuck.
SET nId = id;
SET nType = type;
//etc
//I'll then use concat to display the output.
return (select concat(nId,' ~ ',nType));
It's a lot more complicated than this and needs to go this way. I've kept it this way for this question.
END
I call the function this way SELECT id, mainLinks(id) from mytable;
Use SELECT ... INTO var_list
DELIMITER $$
CREATE FUNCTION mainLinks(nid INT)
RETURNS varchar(1500)
BEGIN
DECLARE aid INT;
DECLARE atype INT;
DECLARE aparent INT;
DECLARE ausername VARCHAR(32);
DECLARE auserid INT;
DECLARE aCOUNTRY VARCHAR(2);
SELECT id, type, parent, userName, userId, country
INTO aid, atype, aparent, auserName, auserId, acountry
FROM Table1
WHERE id = nid;
RETURN CONCAT(aid, atype, aparent, auserName, auserId, acountry);
END$$
DELIMITER ;
Use:
SELECT mainLinks(5);
Output:
| LINK |
----------------
| 511norman1US |
Here is SQLFiddle demo