SQL help with breaking down multiple values

Hi There – I have the Agile PLM PC module. Just recently I have gotten into the database and have started running some queries for info. Curious if anyone has any recommendations on how to get these listvalues separated and then inner joined to display actual values as the query results.

I’d like to make a SQL query which takes all of our open deviations and simply displays their #, originator, effective dates, description, reason, and affected product lines. Affected product lines is not on the affected items page, but just the cover page of a deviation. The user may enter one value from a list, or multiple values. On the backend, this column of data stores the information, as it is concatenated, separated with commas. I have a working query except for the last part [CHANGE].[PRODUCT_LINES]. If it was a single value, I assume I could inner join to the [LISTENTRY].[ENTRYID].

How do I separate these values and get them to display actuals?

SQL help with breaking down multiple values

– Nick

Add Comment
4 Answer(s)

Hi Nick,

You can create custom function like this one to retrieve the values for a multilist

CREATE OR REPLACE
FUNCTION “GET_MULTILIST_COUNTRIES”
( csv_string IN VARCHAR2
) RETURN VARCHAR2 AS
TYPE ListCurTyp IS REF CURSOR;
resultString VARCHAR2(2500);
sql_string VARCHAR2(2500);
csv_values VARCHAR2(2500);
list_cursor ListCurTyp;
list_value VARCHAR2(2500);
BEGIN
DBMS_OUTPUT.ENABLE(200000);
dbms_output.put_line(‘list value = ‘);
IF csv_string IS NOT NULL THEN
csv_values := LTRIM(csv_string,’,’);
csv_values := RTRIM(csv_values,’,’);
IF INSTR(csv_values,’,’)=0 THEN –only one value in csv string
SELECT LISTENTRY.ENTRYVALUE into resultstring FROM LISTENTRY
WHERE PARENTID = 365 AND LISTENTRY.ENTRYID = csv_values AND ROWNUM = 1;
resultString := substr(resultString,length(resultString)-2,2);
RETURN resultString;
ELSE –multiple csv values
sql_string := ‘select LISTENTRY.ENTRYVALUE from LISTENTRY
WHERE PARENTID = 365 AND ENTRYID in (SELECT TO_NUMBER(xt.column_value)
FROM XMLTABLE(”’||csv_values||”’) xt
)’;

OPEN list_cursor FOR sql_string;
LOOP
FETCH list_cursor INTO list_value;

EXIT WHEN list_cursor%NOTFOUND;
list_value := substr(list_value,length(list_value)-2,2); –extract the country code
IF LENGTH(resultstring)>0 THEN
resultstring := resultstring ||’, ‘|| list_value;
ELSE
resultstring := list_value;
END IF;
END LOOP;
CLOSE list_cursor;
RETURN resultstring;
END IF;
ELSE
RETURN NULL;
END IF;
END GET_MULTILIST_COUNTRIES;

You can get the exact value of a particular list, specifying in the inner query, another condition on PARENTID = XXX where XXX is the id of the list that you are looking for

Agile Angel Answered on April 28, 2016.

Hi Antonio – Thank you. This is what I was looking for.

Nick

on April 28, 2016.
Add Comment

Wrested with the same issue myself, I believe the only way would be to use pl/sql which have yet to explore how to code it. So I would too appreciate a model answer.

Conceptually I think you your product_lines result could be turned into an array, then you could iterate over the array querying the listentry table and substituting the list item text into the array.

Agile Angel Answered on April 28, 2016.
Add Comment

create functions and use in scripts,

Agile Angel Answered on May 2, 2016.
Add Comment

Agreed, a function is the only way to go in a query. Note that in general you will need to use the correct parent ID for the list you will be processing, and as such I would pass it in as an argument to the function. For most multi-lists, this will work just fine. But you also have to take into account when the attribute has too many ID values assigned to hold in the actual database attribute (they usually have a max length of 765, and so can hold somewhere around 100 values), and so the values are then stored in MSATT. Or when the string of values that is created from the list of ID values exceeds the max length for VARCHAR2 data. But in most cases, those things are not an issue.

Agile Angel Answered on May 12, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.