Skip to main content

Attribute Generation Function for PL/SQL Scripts

  • December 26, 2024
  • 0 replies
  • 27 views

hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • 318 replies

 Hi Community,

While working on our ERP processes, I developed a PL/SQL function to simplify the creation of the attribute variable. Writing scripts can be time-consuming, especially when you creating an attribute like:

client_sys.add_to_attr('PART_NO', 'TM-SERVER', attr_);

Instead, in this way:

p3_ VARCHAR2(32000) := 'PART_NO' || chr(31) || 'TM-SERVER' || chr(30);

We can significantly reduce the time and effort required to prepare scripts with the function below. 

FUNCTION generate_attr_script(p3_ IN VARCHAR2) RETURN CLOB IS
	output_ CLOB := '';
	line_   VARCHAR2(32000);
	key_    VARCHAR2(200);
	value_  VARCHAR2(200);
	pos_    INTEGER;
	input_  VARCHAR2(32000);
BEGIN
	input_ := p3_;
	WHILE instr(input_, chr(30)) > 0
	LOOP
		line_   := substr(input_, 1, instr(input_, chr(30)) - 1);
		pos_    := instr(line_, chr(31));
		key_    := substr(line_, 1, pos_ - 1);
		value_  := substr(line_, pos_ + 1);
		output_ := output_ || 'client_sys.add_to_attr(''' || key_ || ''', ''' || value_ || ''', attr_);' || chr(10);
		input_  := substr(input_, instr(input_, chr(30)) + 1);
	END LOOP;
	RETURN output_;
END generate_attr_script;

 

Example Usage:

 

Output:

 

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings