A difficult dynamic SQL query problem

Hi all

I have a very interesting problem to work:

We have this special table defined as follows:

CREATE TABLE sales_data)
sales_id NUMBER,
NUMBER of sales_m01
NUMBER of sales_m02
NUMBER of sales_m03
NUMBER of sales_m04
NUMBER of sales_m05
NUMBER of sales_m06
NUMBER of sales_m07
NUMBER of sales_m08
NUMBER of sales_m09
NUMBER of sales_m10
NUMBER of sales_m11
NUMBER of sales_m12
sales_prior_yr NUMBER);
/

Columns ' sales_m01... sales_m12' represents aggregated monthly sales, what "sales_m01" is translated by "sales for the month of January, January is the first month,"sales_m02"in sales for the month of February and so on.»

The problem I encounter is that we have a project that requires that a parameter is passed to a stored procedure that represents the number of months which is then used to create a SQL query with aggregations of next mandatory field, which depends on the parameter passed:

Example 1: entry of parameter: 4
Should be built dynamically to SQL query:

SELECT
Sum (sales_m04) as CURRENT_SALES,
Sum (sales_m01 + sales_m02 + sales_m03 + sales_m04) SALES_YTD
Of
sales_data
WHERE
sales_id = '0599768';

Example 2: input parameter: 8
Should be built dynamically to SQL query:

SELECT
Sum (sales_m08) as CURRENT_SALES,
SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04 +)
sales_m05 + sales_m06 + sales_m07 + sales_m08) SALES_YTD
Of
sales_data
WHERE
sales_id = '0599768';


So in a sense, the contents of SUM(sales_m01...n) would vary according to the parameter, which must be a number between 1... 12 what is a month, which in turn corresponds to a range of real field on the table itself. The resulting dynamic query should include only those columns/fields in the table that is within the range given by the input parameter and does not account for all the other columns/fields.

Any solution is greatly appreciated.

Thank you.
SQL> declare
  cols long;
  param integer := 6;
  sales_id integer := 0599768;
begin
  for i in 1..param loop
    cols := cols || 'sales_m' || to_char(i, 'fm00') || '+';
  end loop;

  dbms_output.put_line('select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,'+') || ') sales_ytd from sales_data WHERE sales_id = :1');
end;
/
select sum(sales_m06) current_sales, sum(sales_m01+sales_m02+sales_m03+sales_m04+sales_m05+sales_m06) sales_ytd from sales_data WHERE sales_id = :1
PL/SQL procedure successfully completed.

Now it should be obvious:
Instead of dbms_output OPEN a refcursor:

SQL> declare
  cols long;
  param integer := 6;
  sales_id integer := 0599768;
  cur sys_refcursor;
begin
  for i in 1..param loop
    cols := cols || 'sales_m' || to_char(i, 'fm00') || ',';
  end loop;

  open cur for 'select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,',') || ') sales_ytd from sales_data WHERE sales_id = :1' using sales_id;
  .....
end;
/

Published by: michaels2 on July 26, 2009 09:49

replaced ',' with ' + '.

Tags: Database

Similar Questions

  • Dynamic recovery for the dynamic sql query

    Hi all

    I want to create a query dynamically and to fetch it in a dynamic cursor record... The structure of the record should be the same as that of the query...
    Can you suggest any method to do this.

    for example

    OPEN < dynamic news > TO < dynamic stmt >;
    LOOP
    FETCH < dynamic news > < DYNAMIC rec >;
    ---
    END LOOP;
    CLOSE < dynamic news >;

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Thank you
    Merz

    Published by: merz Sep 12, 2011 17:02

    Published by: merz Sep 12, 2011 17:03

    Merz says:

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Is not possible. What you describe is called four dynamic sql type. For this type of synamic SQL, you use the DBMS_SQL package.

    SY.

  • Dynamic SQL query in the DB adapter

    Hello
    I want to use the following custom SQL query in the DB adapter:

    SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)

    the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case

    Thank you
    Sunil

    Use the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)

    Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)

    Thank you
    -Sreeny

  • cache of SQL query problem

    I'm seeing the log file to manage the sql query sessions in the responses. I see that if we run the same report multiple times, the sql query is displayed only the first time. Second time if I run it is not displayed. If I make a new report with diff columns selected, it gives me the sql code then. Where can I put this option to display the sql query whenever I run a report, even if it's the same report executed several times. Is this caching problem?

    It should not... You have disabled the "Cache" on the physical layer for this table? If you go to the Advanced tab, is the option "ignore the cache Oracle BI" checked?

  • SQL query problem - (internal has not managed to the outer query)

    Hi all:

    Here is my SQL query:
    SELECT RD.SITE,
      ROUND(
      (SELECT COUNT (DISTINCT PB.EMP_ID)
      FROM BOOK PB
      WHERE PB.EMP_ID IN
        (SELECT PB.EMP_ID FROM BOOK PB
        )
      ) /
      (SELECT COUNT (DISTINCT PB.EMP_ID)
      FROM BOOK PB
      WHERE PB.EMP_ID IN
        (SELECT PB.EMP_ID FROM BOOK PB
    WHERE MO.QUALIFIER > 4
        )
      )* 100, 2) AS PERCENTAGE
    FROM BOOK PB
    LEFT JOIN POSITION MO
    ON PB.EMP_ID = PO.EMP_ID
    INNER JOIN PHYS_LOCATION RD
    ON MO.HOUSED         = RD.SITE_ID
    WHERE MO.ACTUAL_END IS NULL
    GROUP BY RD.SITE;
    Why am I the overall percentage of all Sites as opposed to each percentage calculation for each site. I've grouped by Rd. SITE, so I assume he would calculate the percentages for each site. What I've done wrong?

    Thank you for your help.

    AquaNX4 wrote:
    Hi all:

    Here is my SQL query:

    SELECT RD.SITE,
    ROUND(
    (SELECT COUNT (DISTINCT PB.EMP_ID)
    FROM BOOK PB
    WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    )
    ) /
    (SELECT COUNT (DISTINCT PB.EMP_ID)
    FROM BOOK PB
    WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    WHERE MO.QUALIFIER > 4
    )
    )* 100, 2) AS PERCENTAGE
    FROM BOOK PB
    LEFT JOIN POSITION MO
    ON PB.EMP_ID = PO.EMP_ID
    INNER JOIN PHYS_LOCATION RD
    ON MO.HOUSED         = RD.SITE_ID
    WHERE MO.ACTUAL_END IS NULL
    GROUP BY RD.SITE;
    

    Why am I the overall percentage of all Sites as opposed to each percentage calculation for each site. I've grouped by Rd. SITE, so I assume he would calculate the percentages for each site. What I've done wrong?

    It's what you're asking. Your subquery scalar to get the percentage is not restricted by the current site. Add columns to filter to restrict the values selected for the calculation

    Published by: riedelme on May 8, 2013 07:26

  • Dynamic SQL query

    Hi all

    I have a procedure that takes as an input parameter v_emp_id which is of type varchar.

    emp_id are sent separated by commas to v_emp_id. Ex: v_emp_id = 7,2,1

    In my code I use a cursor for loop recover data from the table emp like this

    I'm in (select * from emp where emp_id in v_emp_id) loop
    -----
    end loop;

    It does not work. How do I use dynamic sql statements to retrieve data by using the CURSOR LOOP FOR only?

    Thanks in advance

    MR Marie wrote:

    How do I use dynamic sql statements to retrieve data by using the CURSOR LOOP FOR only?

    Not with dynamic sql statements. I suggest you use collections:

    SQL> create or replace
      2    procedure p1(
      3                 p_empno sys.OdciNumberList
      4                )
      5      is
      6      begin
      7          for v_rec in (select ename from emp where empno in (select * from table(p_empno))) loop
      8            dbms_output.put_line(v_rec.ename);
      9          end loop;
     10  end;
     11  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL> exec p1(sys.OdciNumberList(7566,7844,7900));
    JONES
    TURNER
    JAMES
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Difference between the static SQL query and dynamic SQL query.

    Hello

    Please explain the fundamental difference between static and dynamic sql queries. Please explain for example.

    Static: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/static.htm
    Dynamics: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm

  • Dynamic SQL query returning (problem with list of value)

    Hi, I have problems with my request. I want to do where statement based on my selectlist, but the problem is that I could not write the correct string in my where condition.

    : P61_STATUS has this following display, return value

    Bewerber Bewerber
    PRA_Kandidat PRA_Kandidat
    abgelehnt abgelehnt
    angenommen angenommen
    Thema-Thema
    join online
    Staaten Staaten
    Sky sky
    our our
    DECLARE
      q varchar2(4000);
      list_betreuer htmldb_application_global.vc_arr2;
      list_semester htmldb_application_global.vc_arr2;
      list_status htmldb_application_global.vc_arr2;
    
    BEGIN
    
     -- variable to store the list
     list_betreuer := HTMLDB_UTIL.STRING_TO_TABLE(:P61_BETREUER);
     list_semester := HTMLDB_UTIL.STRING_TO_TABLE(:P61_SEMESTER);
     list_status := HTMLDB_UTIL.STRING_TO_TABLE(:P61_STATUS);
    
     -- Query begins
     q:= 'select p1.name, p1.vorname , a1.tel, a2.tel, '; 
     q:= q||'ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name ';
     
     q:= q||'from person p1, person p2, adresse a1, adresse a2, ';
     q:= q||'zuordnungp_a zpa1,zuordnungp_a zpa2, ';
     q:= q||'abschlussarbeit ab, semester s ';
    
     q:= q||'WHERE ab.SEMESTER = s.OBJECTID (+) ';
     q:= q||'AND ab.STUDENT = p1.OBJECTID (+) ';
     q:= q||'AND ab.BETREUER = p2.OBJECTID (+) ';
    
     q:= q||'and p1.objectid = zpa1.person (+) ';
     q:= q||'and zpa1.adresse  = a1.objectid (+) ';
     q:= q||'and zpa1.art (+)= ''Privat'' ';
    
     q:= q||'and p1.objectid = zpa2.person (+) ';
     q:= q||'and zpa2.adresse  = a2.objectid (+) ';
     q:= q||'and zpa2.art (+)= ''Geschäft'' ';
    
    
     -- Loop for betreuer list
     FOR i in 1..list_betreuer.count
     LOOP
        IF i = 1 THEN
        q:= q||'AND (ab.betreuer = '||list_betreuer(i);
        ELSE
        q:= q||' OR ab.betreuer  = '||list_betreuer(i);
        END IF;
     END LOOP; if (list_betreuer.count>0)THEN q:= q||')'; END IF;
    
      -- Loop for semester list
     FOR i in 1..list_semester.count
     LOOP
        IF i = 1 THEN
        q:= q||'AND (ab.semester = '||list_semester(i);
        ELSE
        q:= q||'OR ab.semester = '||list_semester(i);
        END IF;
     END LOOP; if (list_semester.count>0)THEN q:= q||')'; END IF;
     
     -- Loop for status list
     FOR i in 1..list_status.count
     LOOP
        IF i = 1 THEN
        q:= q||'AND (ab.status = '||list_status(i)||'';
        ELSE
        q:= q||'OR ab.status = '||list_status(i)||'';
        END IF;
     END LOOP; if (list_status.count>0)THEN q:= q||')'; END IF;
     
      htp.p(q);
     return q;
     
    END;
    result
    select p1.name, p1.vorname , a1.tel, a2.tel, ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name from person p1, person p2, adresse a1, adresse a2, zuordnungp_a zpa1,zuordnungp_a zpa2, abschlussarbeit ab, semester s WHERE ab.SEMESTER = s.OBJECTID (+) AND ab.STUDENT = p1.OBJECTID (+) AND ab.BETREUER = p2.OBJECTID (+) and p1.objectid = zpa1.person (+) and zpa1.adresse = a1.objectid (+) and zpa1.art (+)= 'Privat' and p1.objectid = zpa2.person (+) and zpa2.adresse = a2.objectid (+) and zpa2.art (+)= 'Geschäft' AND (ab.status = abgegeben) 
    the problem is in this summary
    q:= q||'AND (ab.status = '||list_status(i)||'';
    This statement produce this following statement
    ab.status = abgegeben
    But what I need, is this statement
    ab.status = 'abgegeben';
    How can I get this statement?

    Thank you very much

    To use double quotes:

    q:= q||'AND (ab.status = '''||list_status(i)||'''';
    
  • Using CASE in a dynamic sql query

    Hello
    I want to create a dynamic query using the CASE statement to replace the below 2 SQL statements:

    +++++
    Select "create or replace the synonym ' |" SYNONYM_NAME | 'for'. TABLE_OWNER |'. ' || TABLE_NAME | » @'|| SUBSTR (Db_link, 1, 30) |';' OF USER_SYNONYMS where db_link is not null;
    Select "create or replace the synonym ' |" SYNONYM_NAME | 'for'. TABLE_OWNER |'. ' || TABLE_NAME |';' OF USER_SYNONYMS where the db_link is null;
    +++++

    While I have a unique select query which will give her create synonym statements for all with or without links db

    Using the example of CASE statement as below:
    SELECT
    FirstName, LastName,
    Salary, date of birth,
    ABOUT sex
    WHEN'm ' THEN 'male '.
    WHEN 'F' THEN 'woman '.
    END
    Employees


    I don't get how to write this CASE statement. Can someone guide me here?

    Thank you
    Malika

    "" The thread has been moved to Forum Home "database" SQL and PL/SQL+.

    Nicolas.

  • Dynamic SQL query to get the unique value of list in a column

    I have two tables: tblWorkers and tblSkills. tblWorkers has a column, skills, which is populated by a field of multiple-checkbox with one or more skill_IDs of tblSkills, so each tblWorkers.Skills consists of a list of one or more comma-delimited values. For any Skill_ID, I need to generate a list of all workers with the appropriate skills, so I tried to do something in the direction of SELECT WorkerName FROM tblWorkers WHERE IN of skills (skills, #FORM. Skill_ID #)... or WHERE skills (ListFind (skills, #FORM. Skill_ID #))... etc.? My results (once I have had data type mismatches of the road) return all workers, not just those with the desired skills. There must be an easy way to do... How people with a little more experience CF/SQL I do this?

    > each tblWorkers.Skills consists of a list of one or more comma-delimited values

    This is your problem. You store a list of values that you want to access power/query separately in a single column. You will have to burst in a separate table.
    TblWorkers

    TblSkills

    TblWorkerSkills
    mapping table of many workers with skills.

    If you do not change your data model now, you will constantly be butting your head against that.

  • select SQL query problem

    Hi friends,

    I have a view called 'risk_efforts' with the field user_id, user_name, wknd_dt, Etiquettemois, prod_efforts, unprod_efforts.

    Name Type
    -------------- -------------
    ROW_ID NUMBER
    USER_ID VARCHAR2 (14)
    VARCHAR2 (50) USER_NAME
    WKND_DT VARCHAR2 (8)
    ETIQUETTEMOIS VARCHAR2 (250)
    NUMBER OF PROD_EFFORTS
    NUMBER OF UNPROD_EFFORTS

    data are like this:
    When there is some data in prod_efforts, unprod_efforts will be null
    When there is some data in unprod_efforts, prod_efforts will be null

    for example:

    USER_ID, USER_NAME WKND_DT ETIQUETTEMOIS PROD_EFFORTS UNPROD_EFFORTS
    G666999 20100403 GTest KILLS null 3
    G666999 GTest 20100403 Mar 14 null

    now I want to combine these 2 rows in i.e 1 row o/p should be like this

    USER_ID, USER_NAME WKND_DT ETIQUETTEMOIS PROD_EFFORTS UNPROD_EFFORTS
    G666999 20100403 GTest KILLS 14 3

    I tried all combinations but couldn't make the query. Please help me with the exact SQL select query.

    Thank you
    Girish

    Welcome to the forum.

    First read this:

    Emergency in online messages

    Second, it is always helpful to provide the following information:

    1. oracle version (SELECT * FROM V$ VERSION)
    2. examples of data in the form to CREATE / INSERT commands.
    3. expected results
    4 explanation of the expected results (alias "business logic")
    5. use.

     tags for #2 and #3. See FAQ (Link on top right side) for details.
    
    You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
    
    I'm just wagering a guess here but what about this:
    

    SELECT ROW_ID
    USER_ID
    WKND_DT
    ETIQUETTEMOIS
    MAX (PROD_EFFORTS) AS PROD_EFFORTS
    MAX (UNPROD_EFFORTS) AS UNPROD_EFFORTS
    OF RISK_EFFORTS
    ROW_ID GROUP
    USER_ID
    WKND_DT
    ETIQUETTEMOIS

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
    
  • Recordset SQL query problem

    Hi there I try to execute the following set of records-

    < %
    Dim LiveProperties
    Dim LiveProperties_cmd
    Dim LiveProperties_numRows

    Set LiveProperties_cmd = Server.CreateObject ("ADODB.Command")
    LiveProperties_cmd. ActiveConnection = MM_recruta2_STRING
    LiveProperties_cmd.CommandText = "SELECT COUNT (PropertyID) As NumberofProperties, propertylive, propertylive WHERE propertylocation = 'y' FROM dbo.easytoletproperty GROUP BY propertylocation.
    LiveProperties_cmd. Prepared = true

    Set LiveProperties = LiveProperties_cmd. Run
    LiveProperties_numRows = 0
    % >

    However, when I test this situation, I get the following error:

    Provider Microsoft OLE DB for SQL Server error '80040e14 '.

    Incorrect syntax near the keyword 'FROM '.

    / PropertiesbyTown2.asp, line 358


    Any ideas as to what I did wrong?

    Thank you

    'Column 'dbo.easytoletproperty.propertylive' is invalid in the select list because it is not contained in the clause Group By or an aggregate function'

    Fix. You have used an aggregate function, then all other columns that are not part of an aggregate must be grouped together by using the group by clause.

  • SQL query problem

    Hi all

    I have table T_TEST with column Date_Time and email...

    Select TO_CHAR(date_time,'DD-MON-YY HH:MM:SS') Date_Time, email T_TEST

    Date_Time E-mail
    1 JUNE 13 12:06:29[email protected]
    1 JANUARY 14 01:06:31[email protected]
    1ST FEBRUARY 14 03:00[email protected]
    1ST FEBRUARY 14 01:09[email protected]
    MARCH 2, 11 07:00[email protected]
    JUNE 9, 10 11:00[email protected]

    I need to later / recent DATA-data date time

    the final out put only on files

    Date_Time E-mail
    1ST FEBRUARY 14 03:00[email protected]

    Please help me on this...

    Hello

    Try it below:

    with t as

    (

    Select to_date (1 June 13 12:06:29 ',' DD-MON-YY HH12:MI:SS') Date_Time,' [email protected]' email of all the double union

    Select to_date (1 January 14 01:06:31 "," DD-MON-YY HH12:MI:SS'),' [email protected]' Union double all the

    Select to_date (1 February 14 03:00 "," DD-MON-YY HH12:MI:SS'),' [email protected]' Union double all the

    Select to_date (1 February 14 01:09 ',' DD-MON-YY HH12:MI:SS'),' [email protected]' of the double

    )

    Select to_char (date_time, "DD-MON-YY HH12:MI:SS) Date_Time, email from t where to_char (date_time," DD-MON-YY HH12:MI:SS) in (select to_char (max (date_time), "DD-MON-YY HH12:MI:SS") t);

    OUTPUT:

    DATE_TIME EMAIL

    --------------------------- --------------

    1st February 14 03:00 [email protected]

  • SQL query problem finding difference in documents

    Hi all
    I use oracle 10g. I need emergency aid to find the difference in documents based on the date:

    I have sales of the table as below:

    seller SALES_COUNT DATE
    JOHN 20 04/01/2012
    DENNY 15 04/01/2012
    JOHN 30 04/02/2012
    DENNY 30 04/02/2012
    JOHN 45 04/03/2012
    DENNY 50 04/03/2012


    SALES_COUNT is up to man including the date of sale. Its similar cumulative number. John has total sales of 01/04/2012 to 03/04/2012 is 50 and same case for Denny. This SALES_COUNT will keep increasing with dates as sales continue to add in the table for each salesperson.
    But I want to have seprate for each seller counties.
    for example: JOHN SALES_COUNT 04/02/2012 is 30-20 = 10
    JOHN SALES_COUNT 03/04/2012 is 45-30 = 15
    DENNY SALES_COUNT, 02/04/2012 is 30-15 = 15
    JOHN SALES_COUNT 03/04/2012 is 50-30 = 20

    Please help me with this scenario and let me know if you need clarification. I would much appreciate your help.

    Thank you.

    This gives you what you want?

    with t as (
         select 'JOHN' salesman, 20 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 15 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 45 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 50 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
    )
    select salesman,
           sales_count sales_todate,
           sale_date,
           sales_count - lag(sales_count, 1, 0) over (partition by salesman order by sale_date) daily_sales
    from t
    
    SALESMAN,SALES_TODATE,SALE_DATE,DAILY_SALES
    DENNY,15,4/1/2012,15
    DENNY,30,4/2/2012,15
    DENNY,50,4/3/2012,20
    JOHN,20,4/1/2012,20
    JOHN,30,4/2/2012,10
    JOHN,45,4/3/2012,15
          
    
  • Dynamic PL SQL query

    Hello

    I want to run and store the results of a dynamic sql query in a strored procedure.

    I get the following variables of the user running: v_column_names, v_table_name, v_col, v_value

    The query will be like:

    v_query: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;

    for example v_column_names: = 'ACCOUNT_NUM, SYSTEM_ID, ENTITY_ID ';

    v_table_name: = 'ACCOUNT '.

    v_col: = 'COUNTRY_CODE ';

    v_value: = "USA";

    Here is what I tried

    DECLARE

    v_column_names VARCHAR (200): = 'ENTITY_ID, SYSTEM_ID, ACCOUNT_NUM;

    v_table_name VARCHAR (200): = 'ACCOUNT '.

    v_col VARCHAR (200): = 'COUNTRY_CODE ';

    v_value VARCHAR (200): = "'USA"';

    TYPE column_record () IS RENDERING

    VARCHAR2 (200) C1: = null;

    C2 VARCHAR2 (200): = null;

    C3 VARCHAR2 (200): = null

    );

    TYPE st_table IS TABLE OF column_record INDEX DIRECTORY.

    pk_table st_table;

    NUMBER of v1: = 1;

    BEGIN

    v_select: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;

    EXECUTE IMMEDIATE v_select COLLECT LOOSE pk_table.

    I'm IN 1.pk_table.count LOOP

    DBMS_OUTPUT. Put_line (pk_table (v1). (C1);

    DBMS_OUTPUT. Put_line (pk_table (v1). (C2);

    DBMS_OUTPUT. Put_line (pk_table (v1). (C3);

    v1: = v1 + 1;

    END LOOP;

    END;

    The number of column names in v_column_names is dynamic, so I need a way to store the results and then manipulate them.

    I look forward to your reply.

    EDIT: The real question:

    1. in the settings I have pass the table name and the value of the primary key of the row I want to delete.

    2. He then checks if this line is referenced anywhere, removes the reference, and then deletes the current line. This can go, until all the rows that are referenced are removed.

    The above code, I have provided a small part of the largest of stored procedure.

    Thank you all, I found the tips very helpful. I found a solution to my problem:

    Oracle - how to build queries DELETE in PL/SQL, based on the tables of the FK relations? -Stack overflow

    It generates all removal requests to remove a specific line.  Not what I wanted, but this does not solve my problem.

    The reason why is that I discovered that we do not use the ON DELETE CASCADE that we don't remove a record accidentally, I know we have an option to restore, but it is just in case something goes wrong.

Maybe you are looking for

  • LabVIEW for signal N9010A Agilent analyzer Analyzer

    Hello I have filtered signal in Labview, I want to see in the Agilent EXA, N9010A signal Analyzer. Is there software support/drivers to interface, helps that I can send this signal USB cable to monitor signals and display it in the signal Analyzer di

  • function Panel will help in html

    My hardware of CVI Core 1 says I can create help in HTML for my fact instrument driver custom information. The following link mentions also that but I can't seem to get the HTML code to display. What I am doing wrong?

  • Input string to the box Structure will always default

    I have a 16 digit serial data stream which I am analysis in order to get the units of annuncator / '= 81 cm, 82 kg = Lb inches and cm 83 = N' by using the subset of the string. This string is then passed to the structure of the case. When the series

  • PIX 520 model CO or MAKE

    Gentlemen Last night I was reading my release notes for my 16 MG ISA Flash card before installing in my PIX 520. The release notes indicate that I have to check if I have a 520 PIX "CO" or "MAKE". A worm show command does not reveal this? I have a sm

  • How can I add a line in a list of access control?

    We have a user VLAN allows connectivity to the LAN VIRTUAL printer.  Connect printers and need to connect snmp. New printers were brought, and they need to open port 443.  I was under the impression that I could insert a line in an ACL (below). I cop