Help needed dynamic query

Hai I want dynamic query for framing
CREATE TABLE PI4 (COR varchar2(1),dep varchar2(3),cod_rc varchar2(2))

insert into pi4(dep,cod_rc) values('A01','5C')

insert into pi4(dep,cod_rc) values('DAC','5L')
HORN must be updated using dynamic query
as below
UPDATE PI4         
        SET
     PI4.COR = ’O’
WHERE
     PI4.DEP IN ('A01','A02','A03')
OR
     (
     PI4. dep IN ('DAC','FTS','G12')
     AND
     PI4.COD_RC = '5L'
     )
sql_stament is that the variable must be set to above code.

Pls help


S

Check below the code where the CO value is assigned dynamically to a p_cor variable

DECLARE
v_sql_statement VARCHAR2(32767) := NULL;
p_cor VARCHAR2(10) := 'O';
BEGIN
v_sql_statement := 'UPDATE PI4 SET PI4.COR ='||p_cor||' WHERE (PI4.DEP IN (''A01'',''A02'',''A03'') OR (PI4. dep IN (''DAC'',''FTS'',''G12'') AND PI4.COD_RC = ''5L''))';
EXECUTE IMMEDIATE v_sql_statement;
END;

If you do not need dynamic query to perform the update:

See the code below:

DECLARE
p_cor VARCHAR2(10) := 'O';
BEGIN
UPDATE PI4 SET PI4.COR =p_cor WHERE PI4.DEP IN ('A01','A02','A03') OR (PI4. dep IN ('DAC','FTS','G12') AND PI4.COD_RC = '5L'));
END;

Published by: AP on July 27, 2010 03:39

Published by: AP on July 27, 2010 04:51: end tag code included

Tags: Database

Similar Questions

  • help needed in query select

    Hello

    I use the apex of oracle 10g 3.2
    I use a select statement inside a cursor in an anonymous PL/SQL process. The output of the query is like that.

    Method_id patient_id result index_repeat
    39 123 12 0
    29 123 23 0
    39 123 32 1

    Now what I want, that is if there is more then a method_id as 39 occurs twice with index_repeat 0 and 1, then take only with index 39 repeat 1 I mean the output of what I want is the select query

    Method_id patient_id result index_repeat
    29 123 23 0
    39 123 32 1

    I use the following query

    Select method_internal_index, result, patient_id_code, index_repeat
    of t_files_data_exp
    where f_id =: P56_F_ID

    F_ID is the primary key.

    Thank you
    Olivier

    Don't know what exactly you need. When I read your condition sounds like all you need is the following;

    select  method_internal_index
           ,patient_id_code
           ,result
           ,index_repeat
    from    t_files_data_exp
    where   f_id=:P56_F_ID
    and     index_repeat = 1
    

    However, I suspect that what you need is the following;

    select * from
    (
      select  *
             ,row_number() over (partition by method_id order by index_repeat desc) rn
      from    t_files_data_exp
      where   f_id=:P56_F_ID
    )
    where rn = 1
    

    because I assume that the INDEX_REPEAT could be 2 or 3 or more!

  • Need help tuninng a dynamic query

    Hello

    We have following question

    Select s.* s bose_sites.registration_crm_serial_number

    R2 bose_sites.registration_crm_serial_number left on join

    s.serialnr = r2.shipserialnr

    where s.shipserialnr is null

    and (r2.serialnr = ' 052378332000138AE' or (s.serialnr =)

    (( "052378332000138AE" and s.shipserialnr is null))

    which takes about 40 seconds to execute with the values highlighted in bold being dynamic values

    If anyone can help reduce the run time on this request.

    There are indexes created on table

    INDEX_NAME INDEX_TYPE

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

    IDX_REG_CRM_SER_NUM_CPC NORMAL

    IDX_REG_CRM_SER_NUM_SHIPDATE NORMAL

    IDX_REG_CRM_SER_NUM_PARENT_ID NORMAL

    IDX_REG_CRM_SER_NUM_ID NORMAL

    is it possible that we can capture a dynamic query using DBMS_SQLTUNE

    all suggestions will be useful.

    Hello

    You have one table here

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

    Schema name: SYS

    SQL ID: cf2875zz4q4nd

    SQL text: select s.* bose_sites.registration_crm_serial_number s

    R2 bose_sites.registration_crm_serial_number left on join

    s.serialnr = r2.shipserialnr

    where s.shipserialnr is null

    and (r2.serialnr = '052378332000138AE' or (s.serialnr =

    S.shipserialnr and "052378332000138AE" is null))

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

    then why don't you go for a simple query

    HTH

  • Need help with a query result

    Oracle Version: 11.2.0.2.0

    I need assistance with the output of the query. Here is the table.

    With Tbl_Nm as

    (

    Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select * from tbl_nm

    I need the output below.

    PQR2 UK MC 2600 1 OCTOBER 2012 04:45

    ABC1 US NY 3500 October 1, 2012 06:45

    LMN3 UK BT 2500 November 1, 2012 07:45

    The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.

    I've tried a few and got stuck. Help, please. Not able to get a balance '.

    This question is a bit similar to needing help with a query result

    With Tbl_Nm as

    (

    Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1

    where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)

    So maybe you'd then

    ORDER BY DECODE(flag,'D',9,1) ASC...

    to get the Ds at the end of the list.

    or

    ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...

    HTH

  • need help with the query, thx

    Hello
    I need a little help with the query I have to write;
    the table has 4 columns:
    col1               col2         col3       col4
    emp_name     empl_id    salary      year
    
    content of data:
    
    col1               col2         col3       col4
    smith             12           1200      1999
    smith             12           1340      2000
    smith             12           1500      2001
    jones             13           1550      1999 
    jones             13           1600      2000
    aron              14           1200      2002
    what I am asking is the following result: salary according to the latest available year
    i.e.
    smith         12         1500        2001
    jones         13         1600        2000
    aron          14         1200        2002
    ID appreciate some guidance on how to achieve
    Thank you
    Rgds
    select *from
    (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc)  rn  from 
    ) where rn=1
    
  • need help for this query

    Hi gurus

    need help with this query,

    I want to display the records in the table emp
    SQL> Select Deptno,sal,sal/SUMSAL Percent,rn
      2  From  ( Select emp.*,Sum(Sal) Over() "SUMSAL",Row_number() Over(Order by sal Desc) rn
      3   From emp
      4        )
      5  /
    
          EMPNO     DEPTNO        SAL    PERCENT         RN
    --------- ---------- ---------- ---------- ----------
         7839         10       5000 .172265289          1
         7902         20       3000 .103359173          2
         7788         20       3000 .103359173          3
         7566         20       2975 .102497847          4
         7698         30       2850 .098191214          5
         7782         10       2450 .084409991          6
         7499         30       1600 .055124892          7
         7844         30       1500 .051679587          8
         7934         10       1300 .044788975          9
         7521         30       1250 .043066322         10
         7654         30       1250 .043066322         11
         7876         20       1100 .037898363         12
         7900         30        950 .032730405         13
         7369         20        800 .027562446         14
    
    14 rows selected.
                   
     
    I want just the records
          EMPNO     DEPTNO        SAL    PERCENT         RN
    ---------- ---------- ---------- ---------- ----------
          7839         10       5000 .172265289          1
          7902         20       3000 .103359173          2
          7788         20       3000 .103359173          3
          7566         20       2975 .102497847          4
          7698         30       2850 .098191214          5
    with sum (Percent) of remaing records.....
        Others                          .420327304  
    Thank you

    Published by: SeenuGuddu on February 27, 2011 03:39
    with a as
    (
    Select
    Empno, Deptno ,sal, sal/SUMSAL Percent,
    case when rn<=5 then rn else null end rnm
    From  (Select emp.*, Sum(Sal) Over() "SUMSAL",
    Row_number() Over(Order by sal Desc) rn
    From emp)
    )
    select
    case when max(rnm) is not null then to_char(max(empno)) else 'Others:' end empno,
    case when max(rnm) is not null then max(deptno) else null end deptno,
    case when max(rnm) is not null then max(sal) else null end sal,
    to_char(sum(percent), '90.99') percent,
    max(rnm) rn
    from a
    group by rnm order by rnm
    
    EMPNO                                    DEPTNO                 SAL                    PERCENT RN
    ---------------------------------------- ---------------------- ---------------------- ------- ----------------------
    7839                                     10                     5000                     0.17  1
    7902                                     20                     3000                     0.10  2
    7788                                     20                     3000                     0.10  3
    7566                                     20                     2975                     0.10  4
    7698                                     30                     2850                     0.10  5
    Others:                                                                                  0.42                         
    
    6 rows selected
    
  • dynamic query for package does not work

    Dear members,

    I have problems with a package in the creation and analysis of a dynamic query in the WHERE clause. Here is an example of what I'm trying to do:

    PROCEDURE test_status_proc)
    wtd_cursor ON cur_type
    date_1 IN date
    date_2 IN DATE
    status in VARCHAR2,
    flag in VARCHAR2)

    IS

    status_sql VARCHAR2 (250): = NULL;
    flag_sql Varchar2 (100): = NULL;

    BEGIN


    Status of the IF = 'A' THEN
    lv_status_sql: = 'A ';
    lv_flag_sql: = 'Y ';
    END IF;
    Status of the 'I' = IF THEN
    lv_status_sql: = 'A ';
    lv_flag_sql: = 'n';
    END IF;

    Status of the 'R' = IF THEN
    lv_status_sql: = "R";
    lv_flag_sql: ='* ';
    END IF;

    Status of the IF = n THEN
    lv_status_sql: = 'n';
    lv_flag_sql: ='* ';
    END IF;

    IF status_code = 'IRN' THEN
    "lv_status_sql: = '('' N'','' R'');
    lv_status_sql: = lv_status_sql | ' OR (s.status = s.flag = "A" AND "N")';
    lv_usecalc_sql: ='* ';
    END IF;

    Status of the = IF'* ' THEN
    lv_status_sql: ='* ';
    lv_flag_sql: ='* ';
    END IF;

    OPEN FOR Test_cursor

    SELECT * from test_status s
    WHERE
    s.Daytime BETWEEN date_1 AND date_2
    S.status AND decode (lv_status_sql,'* ', s.status, lv_status_sql)
    S.flag AND decode (lv_flag_sql,'* ', s.flag, lv_flag_sql);

    The problem I have is especially with the condition 'IRN '. The suite WHERE the part of the clause looks like the following in the lv_status_sql, but the query returns all the values:

    -(', 'R') OR (s.status = 'A' AND s.flag =' only)

    Any help would be much appreciated.

    Kind regards

    dreporter wrote:

    Thanks for your reply and I completely understand your frustration. The problem is sometimes it is very difficult to describe all of the problem due to several reasons. Please take a look at my last post to see if that makes sense.

    If you really need SQL dynamic - true dynamic SQL which includes dealing with dynamic number of bind variables - then DBMS_SQL are an excellent interface to use.

    You can generate the dynamic SQL statement based on the question of whether the filter criteria is null (do not use) or not null (use as a predicate). For example

    if someParam10 is not null then
      // someParam10 needs to be used as a filter predicate
      dynamicSQL := dynamicSQL || ' and some_col_10 = :someParam10 ';
    end if;
    

    This statement can then be analyzed using the DBMS_SQL interface. The binding of values uses the same logic that was used to create predicates. For example

    if someParam10 is not null then
      // someParam10 is used and needs to be bound
      DBMS_SQL.Bind( myCursor, 'someParam10', someParam10 );
    end if;
    

    So, with this approach simplistic, you can easily create a dynamic SQL with variable predicates, dynamically bind these and run the slider.

    Bind variables are used in the dynamic SQL statements, as there are very few threats of SQL injection. And the basic principles observed for shareable SQL creation - the same set of parameters not null to filter, will result in the same SQL statement, which allows the cursor within the Pool shared for this SQL statement to be reused.

    So, technically, dynamic SQL is not a major problem (if used correctly). The major problem is that if really necessary to address the requirements of the business at hand.

    The problem I have with many comments here want to use dynamic SQL statements, is that it is used as one would use a file i/o interface.

    For file IO you want standard Open(), Read(), Write() and Close() calls. And you, the appellant, simply pass the name of the file and the data to write or to receive the data read.

    Similarly, these posters want to use SQL to open a table and read and write the data column - and do it by calling simply (and dynamically) by specifying the name of the table and column. Approaches to dynamic SQL based on one such concept is wrong. And shows that much of the ignorance of what a RDBMS is and how to use an RDBMS.

  • Sort on dynamic query problem!

    Hello

    I have a dynamic query written in pl/sql, when I check "Sort" for each field in the report attribute, error message resurrected as "ORA-01785: ORDER BY item must include the number of an expression in the SELECT list.
    If I do not check sort, it works very well. In my applications, I need all the fields sorted by user, how do I solve this problem?

    My query as below:

    declare
    Ask varchar2 (2000): = "select";
    s_class varchar2 (1000);
    cursor c1 is select * from demo_preference;
    Start
    for c1_val looping c1
    If c1_val.login is not null then
    query: query = | » ' || 'login ' | ',';
    end if;
    If c1_val.id is not null then
    query: query = | » ' || 'id ' | ',';
    end if;
    .......
    end loop;
    query: = SUBSTR (query, 1, length (query)-1);

    s_class: = ' (NVL (: P2_class, "%" |)) ''null%'') = ''%'' || "zero percent" OR
    EXISTS (SELECT 1 FROM apex_collections WHERE collection_name = "P2CLASSCOL" AND class = c001))';

    query: query = | » ' || ' from ming.reg_report_view1 where '.
    || ' ' || s_class;
    Return (Query);
    end;

    Maybe the internal column used when you clicked the sort is not indicated in the report. Try to use aliases when you build the query string, it might help apex internally to identify a column even if its order is changed to another user. After all, the order of the columns in the code is dynamic and I assume that even the number of displayed columns can vary that could sort on a column that is identified by a number not valid.

    How about somewhere, displaying the report query so that you know what is the exact query processing, it could give you the best information on the problem.

    If the problem persists, use a collection that is extracted these record using the same query string, then replace the report to view the collection and then set the sort column on. This way Summit could get confused about which columns are being sorted and it would just sort on a c001... C050 column as if it were a string (Yes problems with the number of sort columns when you do this).

  • Dynamic query with wildcard

    Hello

    I have a table1 as below

    ID (NUMBER), keyword (VARCHAR2)
    ----------------------------------------------------
    1, HAS
    2, B
    3, C

    Another table2

    Name (VARCHAR2)
    --------------------------
    Alice
    Bob
    Jack

    I need to write a stored procedure to check if the 2 mactched of the char keyword table1 table name. How to write the dynamic query in my PL/SQL in a stored procedure so that I can generate query similar to

    SELECT * from table2 where name like '%x %' where I need to replace X by the tank in table1

    Help, please.

    Thanks in advance,
    Marry

    I need to write a stored procedure to check if the 2 mactched of the char keyword table1 table name

    You could simply join the tables:

    SQL> with table1  as
    (
     select 1 id, 'A' keyword from dual union all
     select 2 id, 'B' keyword from dual union all
     select 3 id, 'C' keyword from dual
    ),
    table2 as (
     select 'Alice' name from dual union all
     select 'Bob' name from dual union all
     select 'Jack' name from dual
    )
    --
    --
    select * from table1, table2 where name like '%' || keyword  || '%'
    
            ID KEYWORD NAME
    ---------- ------- -----
             1 A       Alice
             2 B       Bob  
    
    2 rows selected.
    
  • Get the dynamic query alias name

    Hi all

    I have a plsql function using a dynamic query.
    And the function takes an entire sql query as a parameter.

    The main problem is that the function must get what aliases or columns were interviewed.

    For example,.
    FUNCTION_GET_QUERY_ALIAS ('SELECT 1 AS col1, col2 FROM DUAL 2 AS')
    Inside the function, he must find the alias name COL1 and COL2.

    I would be grateful for any help.

    I modified print_table as fact and function to meet your needs.

    SQL> CREATE OR REPLACE TYPE my_column_object AS OBJECT(ruw_number integer, column_name VARCHAR2(1000), column_val VARCHAR2(1000))
      2  /
    
    Type created.
    
    SQL> CREATE OR REPLACE TYPE my_table_type AS TABLE OF my_column_object
      2  /
    
    Type created.
    
    SQL> CREATE OR REPLACE FUNCTION print_table( p_query in varchar2 ) RETURN my_table_type PIPELINED
      2  AS
      3      l_theCursor     INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
      4      l_columnValue   VARCHAR2(4000);
      5      l_status        INTEGER;
      6      l_descTbl       DBMS_SQL.DESC_TAB;
      7      l_colCnt        NUMBER;
      8      l_rcount           INTEGER := 0;
      9  BEGIN
     10      DBMS_SQL.PARSE(  l_theCursor,  p_query, dbms_sql.native );
     11
     12      DBMS_SQL.DESCRIBE_COLUMNS( l_theCursor, l_colCnt, l_descTbl );
     13
     14      FOR i IN 1 .. l_colCnt
     15      LOOP
     16          DBMS_SQL.DEFINE_COLUMN(l_theCursor, i, l_columnValue, 4000);
     17      end loop;
     18
     19      l_status := DBMS_SQL.EXECUTE(l_theCursor);
     20
     21      WHILE ( DBMS_SQL.FETCH_ROWS(l_theCursor) > 0 )
     22      LOOP
     23             l_rcount := l_rcount + 1;
     24          FOR i IN 1 .. l_colCnt
     25          LOOP
     26              DBMS_SQL.COLUMN_VALUE( l_theCursor, i, l_columnValue );
     27
     28              PIPE ROW(my_column_object(l_rcount,l_descTbl(i).col_name,l_columnValue));
     29          END LOOP;
     30      END LOOP;
     31
     32     RETURN;
     33  end;
     34  /
    
    Function created.
    
    SQL> select * from table(print_table('select * from emp'))
      2  /
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             1 EMPNO                7369
             1 ENAME                SMITH
             1 JOB                  CLERK
             1 MGR                  7902
             1 HIREDATE             17-DEC-80
             1 SAL                  800
             1 COMM
             1 DEPTNO               20
             1 DIV                  10
             2 EMPNO                7499
             2 ENAME                ALLEN
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             2 JOB                  SALESMAN
             2 MGR                  7698
             2 HIREDATE             20-FEB-81
             2 SAL                  1600
             2 COMM                 300
             2 DEPTNO               30
             2 DIV                  10
             3 EMPNO                7521
             3 ENAME                WARD
             3 JOB                  SALESMAN
             3 MGR                  7698
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             3 HIREDATE             22-FEB-81
             3 SAL                  1250
             3 COMM                 500
             3 DEPTNO               30
             3 DIV                  10
             4 EMPNO                7566
             4 ENAME                JONES
             4 JOB                  MANAGER
             4 MGR                  7839
             4 HIREDATE             02-APR-81
             4 SAL                  2975
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             4 COMM
             4 DEPTNO               20
             4 DIV                  10
             5 EMPNO                7654
             5 ENAME                MARTIN
             5 JOB                  SALESMAN
             5 MGR                  7698
             5 HIREDATE             28-SEP-81
             5 SAL                  1250
             5 COMM                 1400
             5 DEPTNO               30
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             5 DIV                  10
             6 EMPNO                7698
             6 ENAME                BLAKE
             6 JOB                  MANAGER
             6 MGR                  7839
             6 HIREDATE             01-MAY-81
             6 SAL                  2850
             6 COMM
             6 DEPTNO               30
             6 DIV                  10
             7 EMPNO                7782
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             7 ENAME                CLARK
             7 JOB                  MANAGER
             7 MGR                  7839
             7 HIREDATE             09-JUN-81
             7 SAL                  2450
             7 COMM
             7 DEPTNO               10
             7 DIV                  10
             8 EMPNO                7788
             8 ENAME                SCOTT
             8 JOB                  ANALYST
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             8 MGR                  7566
             8 HIREDATE             19-APR-87
             8 SAL                  3000
             8 COMM
             8 DEPTNO               20
             8 DIV                  10
             9 EMPNO                7839
             9 ENAME                KING
             9 JOB                  PRESIDENT
             9 MGR
             9 HIREDATE             17-NOV-81
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
             9 SAL                  5000
             9 COMM
             9 DEPTNO               10
             9 DIV                  10
            10 EMPNO                7844
            10 ENAME                TURNER
            10 JOB                  SALESMAN
            10 MGR                  7698
            10 HIREDATE             08-SEP-81
            10 SAL                  1500
            10 COMM                 0
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            10 DEPTNO               30
            10 DIV                  10
            11 EMPNO                7876
            11 ENAME                ADAMS
            11 JOB                  CLERK
            11 MGR                  7788
            11 HIREDATE             23-MAY-87
            11 SAL                  1100
            11 COMM
            11 DEPTNO               20
            11 DIV                  10
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            12 EMPNO                7900
            12 ENAME                JAMES
            12 JOB                  CLERK
            12 MGR                  7698
            12 HIREDATE             03-DEC-81
            12 SAL                  950
            12 COMM
            12 DEPTNO               30
            12 DIV                  10
            13 EMPNO                7902
            13 ENAME                FORD
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            13 JOB                  ANALYST
            13 MGR                  7566
            13 HIREDATE             03-DEC-81
            13 SAL                  3000
            13 COMM
            13 DEPTNO               20
            13 DIV                  10
            14 EMPNO                7934
            14 ENAME                MILLER
            14 JOB                  CLERK
            14 MGR                  7782
    
    RUW_NUMBER COLUMN_NAME          COLUMN_VAL
    ---------- -------------------- --------------------
            14 HIREDATE             23-JAN-82
            14 SAL                  1300
            14 COMM
            14 DEPTNO               10
            14 DIV                  10
    
    126 rows selected.
    
    SQL>
    

    Thank you
    Knani.

    Published by: Karthick_Arp on September 23, 2008 12:11 AM

  • apostrophe in dynamic query

    Hi all;

    Can u please help me on the following dynamic query code? I know that I'm missing the single quote around 2 dates, but could not understand where to put it! I tried to put 2 or 3 citations around 2 bind vars but in vain.

    To create a dynamic query to simulate the following:
    Select
    EMPNO, ENAME, JOB, MGR, HIREDATE from emp where HIREDATE > = to_date('01/01/1981','MM/DD/YYYY') and DATERECRUTEMENT < = to_date('12/31/1982','MM/DD/YYYY');


    dynamics of code:

    declare
    v_q varchar2 (4000);

    Start

    v_q: = "select ENAME, JOB, MGR, EMPNO, HIREDATE from emp;

    V_q: = V_Q
    || ' where HIREDATE > = '
    || ' to_date (' |: P_DATE1 |) ',' ||''' MM/DD/YYYY "' | ' )'
    || "and HIREDATE < = '".
    || ' to_date (' |: P_DATE2 |) ',' ||''' MM/DD/YYYY "' | ' )';
    -end of the sql
    v_q: = v_q | « ; » ;


    dbms_output.put_line ("East V_Q" |) V_Q);
    end;


    Thank you.

    Zen
    declare
        v_q varchar2(4000);
        v_rec emp%rowtype;
        v_cur sys_refcursor;
    begin
        v_q :='select EMPNO,ENAME,JOB,MGR,HIREDATE from emp ';
        V_q := V_Q  || 'where HIREDATE >= to_date(:P_DATE1,''MM/DD/YYYY'') and HIREDATE <= to_date(:P_DATE2,''MM/DD/YYYY'')';
        dbms_output.put_line ('V_Q is ' || V_Q);
        open v_cur
          for v_q
          using '01/01/1981',
                '12/31/1982';
        loop
          fetch v_cur
            into v_rec.empno,
                 v_rec.ename,
                 v_rec.job,
                 v_rec.mgr,
                 v_rec.hiredate;
          exit when v_cur%notfound;
          dbms_output.put_line('empno = ' || v_rec.empno);
          dbms_output.put_line('ename = ' || v_rec.ename);
          dbms_output.put_line('job = ' || v_rec.job);
          dbms_output.put_line('mgr = ' || v_rec.mgr);
          dbms_output.put_line('hiredate = ' || to_char(v_rec.hiredate,'MM/DD/YYYY'));
          dbms_output.put_line('====================');
        end loop;
        close v_cur;
    end;
    /
    V_Q is select EMPNO,ENAME,JOB,MGR,HIREDATE from emp where HIREDATE >=
    to_date(:P_DATE1,'MM/DD/YYYY') and HIREDATE <= to_date(:P_DATE2,'MM/DD/YYYY')
    empno = 7499
    ename = ALLEN
    job = SALESMAN
    mgr = 7698
    hiredate = 02/20/1981
    ====================
    empno = 7521
    ename = WARD
    job = SALESMAN
    mgr = 7698
    hiredate = 02/22/1981
    ====================
    empno = 7566
    ename = JONES
    job = MANAGER
    mgr = 7839
    hiredate = 04/02/1981
    ====================
    empno = 7654
    ename = MARTIN
    job = SALESMAN
    mgr = 7698
    hiredate = 09/28/1981
    ====================
    empno = 7698
    ename = BLAKE
    job = MANAGER
    mgr = 7839
    hiredate = 05/01/1981
    ====================
    empno = 7782
    ename = CLARK
    job = MANAGER
    mgr = 7839
    hiredate = 06/09/1981
    ====================
    empno = 7839
    ename = KING
    job = PRESIDENT
    mgr =
    hiredate = 11/17/1981
    ====================
    empno = 7844
    ename = TURNER
    job = SALESMAN
    mgr = 7698
    hiredate = 09/08/1981
    ====================
    empno = 7900
    ename = JAMES
    job = CLERK
    mgr = 7698
    hiredate = 12/03/1981
    ====================
    empno = 7902
    ename = FORD
    job = ANALYST
    mgr = 7566
    hiredate = 12/03/1981
    ====================
    empno = 7934
    ename = MILLER
    job = CLERK
    mgr = 7782
    hiredate = 01/23/1982
    ====================
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Export a dynamic query to excel

    Hello

    I want to export the result to a dynamic query to Excel button.
    I have a model of search where users want to export the query results by clicking a button in an excel file.
    Is this possible?

    Hello Dan,.

    Yes, a query as session variable works fine. Thank you very much for the help!

  • Urgent help of SQL query

    Hello

    I need assistance with SQL... My version of the database is Oracle 10 g Release 1.2.

    I have two tables with the same exact structure as follows...

    create table t1 (cust_id, number (5), zone_number number (2), part_number varchar2 (10))
    create table t2 (cust_id, number (5), zone_number number (2), part_number varchar2 (10))


    I need a query that would give me a two count indictment by pairs of customer between t1 and t2...

    1. part_number County matches between the same areas in table 1 and table 2 for the pairs of customers

    for customer 1 and 10 for zone 1 this total shoulb be 2 because there are two matches part A numbers between 1 and 10 for Zone 1 cust and B.

    for customer 1 and 10 for zone 2 this total shoulb be 0 because between 1 and 10 for Zone 2 cust, there is no part number match

    for customer 1 and 20 for the zone 1 this total shoulb be 0 because between 1 and 20 for Zone 1 cust, there is no part number match

    for 1 client and client 20 zone 2 this total shoulb be 0 because between 1 and 20 to Zone 2 cust is a part number, it's 'F'

    for 1 client and client 20 zone 3 of this total shoulb be 0 because there is no zone 3 for client 1

    same way
    .. Cust 2 and cust 10 zone2 and Zone 1 figures account
    .. 2 and cust 20 zones 1, 2 and 3 counts


    2. the unique total part nmbers between the same areas for customers in table 1 pairs and the table2

    for example

    part numbers only between 1 and 10 for zone 1 cust are A, B and C so the count should be 3
    part numbers only between 1 and 10 for zone 2 cust are B, F, D, and E the county should be 3
    unique piece between 1 and 20 for the zone 1 cust numbers A, B, C and G so the count should be 4
    and so on so forth




    insert into t1 values (1, 1, 'A')
    insert into t1 values (1, 1, 'B')
    insert into t1 values (1, 1, "C")
    insert into t1 values (1, 2, 'B')
    insert into t1 values (1, 2, 'F')
    insert into t1 values (1, 2, has ')
    insert into t1 values (1, 2, 'E')
    insert into t1 values (2, 1, 'F')
    insert into t1 values (2, 2, 'G')
    insert into t1 values (2, 2, 'H')

    insert into t2 values (10, 1, 'A')
    insert into t2 values (10, 1, 'B')
    insert into t2 values (10, 2, null)
    insert into t2 values (20, 1, 'G')
    insert into t2 values (20, 2, 'F')
    insert into t2 values (20, 2, 'H')
    insert into t2 values (20, 3, 'I')
    insert into t2 values (20, 3, 'J')

    My query result should be as follows...

    cust1 cust2 area pn_match_count total_unique_pn_count

    1 10 1 2 3
    1 10 2 0 4
    1 20 1 0 4
    1 20 2 1 5
    1 20 3 0 2
    2 10 1 0 3
    2 10 2 0 2
    2 20 1 0 2
    2 20 2 1 3
    2 20 3 0 2

    I would appreciate your help in the drafting of this query.

    Thanks in advance

    Or leave the 'where' clause, so we get each combination of customer:

    SQL> with c as
      2    (select distinct t1.cust_id cust1, t2.cust_id cust2, t1.zone_number zone, t1.part_number p1, t2.part_number p2
      3       from t1, t2
      4       where t1.zone_number=t2.zone_number
      5         and t1.part_number = t2.part_number
      6     union
      7     select distinct t1.cust_id cust1, t2.cust_id cust2, t1.zone_number zone, t1.part_number p1, null p2
      8       from t1, t2
      9       where not exists (select 1 from t2 t02 where t02.zone_number=t1.zone_number
     10                           and t02.cust_id = t2.cust_id
     11                           and t02.part_number = t1.part_number)
     12     union
     13     select distinct t1.cust_id cust1, t2.cust_id cust2, t2.zone_number zone, null p1, t2.part_number p2
     14       from t1, t2
     15       where not exists (select 1 from t1 t01 where t01.zone_number=t2.zone_number
     16                           and t01.cust_id = t1.cust_id
     17                           and part_number = t2.part_number))
     18  select cust1, cust2, zone, sum(decode(p1,p2,1,0)) pn_match_count, count(*) unique_pn_count
     19    from c
     20    group by cust1, cust2,zone;
    
         CUST1      CUST2       ZONE PN_MATCH_COUNT UNIQUE_PN_COUNT
    ---------- ---------- ---------- -------------- ---------------
             1         10          1              2               3
             1         10          2              1               5
             1         20          1              0               4
             1         20          2              1               5
             1         20          3              0               2
             2         10          1              0               3
             2         10          2              1               3
             2         20          1              0               2
             2         20          2              1               3
             2         20          3              0               2
    
    10 rows selected.
    
  • Please can someone help, need password CNU9497P2C

    I have the same problem and its driving me crazy... I need the BIOS password because I can't access to this

    [number of Series edited by Moderator]

    Please can someone help, need password

    HP MINI CQ10

    Sweb try.

    e9lovox27e

    3rd letter tiny L.

    4th and 6th letter lowercase o.

    Use this code to go into the BIOS.

    Disable all passwords that are enabled.

    If demand for CURRENT password using this code.

    Request NEW password just press ENTER.

    If asked to hit just to CHECK password to enter.

    Save and exit.

    REO

    I must inform you that these services are not endorsed by HP, and that HP is not responsible for any damages that may occur to your system using these services. Please be aware that you do so at your own risk.

  • Collection of the dynamic query

    Hi All-

    I'm trying to get the value of the collection through the dynamic query but I am facing some problem please let me know that I hurt.

    Created a function like below to run the dynamic query to select statement

    create or replace FUNCTION rfunGetColumnValue (
                  ColumnName VARCHAR2,
                  TableName  VARCHAR2,
                  DefaultValue OUT VARCHAR2,
                  Criteria VARCHAR2)
           RETURN VARCHAR2
    IS
           ReturnValue VARCHAR2 (32767 byte) ;
           Stmt        VARCHAR2 (32767 byte) ;
    BEGIN
           stmt := 'begin        
    select '|| ColumnName || ' into  :1  from table(:2) ' ||NVL
           ( Criteria, ' ') ||
           '       
    Fetch First Row only ;        
    EXCEPTION                                   
    WHEN OTHERS THEN                                          
    :2 := SQLERRM;
    end;'
           ;
           dbms_output.put_line (stmt) ;
           EXECUTE IMMEDIATE stmt USING OUT ReturnValue, OUT DefaultValue;
           --select Valueinto into Returnvalue from dual;
           RETURN ReturnValue;
    END;
    

    Now, I created a folder in the Package

    create or replace PACKAGE Collection_PKG
    is
    type Bank_rec is RECORD
    (
    SNO           NUMBER(10),    
    BANKID        NUMBER(5),    
    BANKNAME       VARCHAR2(50),    
    BANKSC         VARCHAR2(50),    
    ADDEDIT       varchar2(1),    
    COMPID        number(5),    
    ISBULK        number(1),    
    ROWNO         number(10),    
    ERROR         VARCHAR2(500)  
    );
    
    
    TYPE Bank_tbl IS TABLE OF Bank_rec;
    --type Bank_cur is ref cursor return Bank_rec;
    
    
    end Collection_PKG;
    
    end Collection_PKG;
    end Collec
    tion_PKG;
    

    Now, when I'm Trying the code below

    DECLARE
      V_EXECQUERYPARAM XMLTYPE:= XMLTYPE('<QueryParam>
      <BankXML>
        <Bank>
          <BankID>0</BankID>
          <BankSC><![CDATA[RCB]]></BankSC>
          <BankName><![CDATA[Royal challenger Bank]]></BankName>
          <IsBulk>0</IsBulk>
          <AddEdit>A</AddEdit>
        </Bank>
      </BankXML>
    </QueryParam>');
    BEGIN
     Rspbanksave(
        v_SPParamList => V_EXECQUERYPARAM  );
    
    
    END; 
    

    create or replace PROCEDURE rspBankSave (
                  v_SPParamList XMLTYPE DEFAULT NULL)
    IS
           V_Addedit VARCHAR2 (1 CHAR) ;
           Bank_tbl Collection_PKG.BANK_TBL := Collection_PKG.BANK_TBL () ;
    BEGIN
           
           SELECT Row_number () OVER (ORDER BY 1),
                  XT.BankID,
                  XT.BankName,
                  XT.BankSC,
                  XT.AddEdit,
                  v_CompID,
                  XT.IsBulk,
                  CAST (0 AS NUMBER (5)),
                  CASE
                         WHEN MBank.BankID IS NOT NULL
                         THEN
                                CASE
                                       WHEN XT.BankSC     = MBank.BankSC
                                          AND XT.BankName = MBank.BankName
                                       THEN 'R104|Entry Already Exist,R114|Short Code Already Exist'
                                       WHEN XT.BankSC = MBank.BankSC
                                       THEN 'R114|Short Code Already Exist'
                                       WHEN XT.BankName = MBank.BankName
                                       THEN 'R104|Entry Already Exist'
                                END
                         ELSE NULL
                  END Bulk collect
           INTO   Bank_tbl
           FROM   XMLTABLE ('//QueryParam/BankXML/Bank' PASSING v_SPParamList COLUMNS BankID NUMBER (5)
                  PATH 'BankID', BankName                                                    VARCHAR2 (
                  50) PATH 'BankName', BankSC                                                VARCHAR2 (
                  50) PATH 'BankSC', AddEdit                                                 VARCHAR2 (
                  1) PATH 'AddEdit', IsBulk                                                  NUMBER (1)
                  PATH 'IsBulk') XT
           LEFT JOIN MBank
           ON     XT.BankID   != MBank.BankID
              AND v_CompID     = MBank.CompID
              AND (XT.BankSC   = MBank.BankSC
               OR XT.BankName  = MBank.BankName) ;
           v_TotalRowCount    := SQL%ROWCOUNT;
    
    
    
    
    
    
           IF (v_TotalRowCount > 0) THEN
                  
                         BEGIN
                               V_Addedit:=rfunGetColumnValue (ColumnName=> 'Upper(AddEdit)',TableName=>'table(Bank_tbl)',DefaultValue=>'',Criteria =>'');
                         END;
                         --SQL Code here
                  
           END IF;
           
    END rspBankSave;
    
    
    
    
    
    
    
    

    As I've suggested before:

    To get the name of the table the column

    and as others have:

    Type global temporary Tables vs. table

    If you give more context, more information about the bigger picture, more information about what you're trying to do and why you're going down the road you go down, you can return more useful information. But you seem reluctant to do.

    For the moment, your recent posts seem to just raise the same type of question - why are you doing this?

    The normal way to return data to a client is a refcursor.

    It is the most effective way.

    Not through collections that you seem to be put on the must-do approach.

Maybe you are looking for

  • Cannot connect my Satellite S50-1007 to AP

    The specifications see the AP but error to connect, WLAN is INTEL 2200BG, but I tried with an Asus USB and same error occurs.

  • the history of z820 and xeon e5!

    Hello there I was looking for good processor for z820 but I found these 3 types 1 E5-2650 20 M Cache, 2.00 GHz 8 Core CPU MPN QA82 2 E5-2650 20 M Cache, 2.00 GHz 8 Core CPU MPN QB7V 3 E5-2650 20 M Cache, 2.00 GHz 8 Core CPU MPN QARE I asked if they r

  • preblem when I start my pc (very slow)

    I want HP 4 model: 4-1056tx product: B9K48PA #AB1 Windows 7 Home Edition When I start my pc and it shows me the office but I can not do anythink I just waithing for 15 min or 10 min sometimes it was still initializing. Thank you.

  • Why can't I add a printer Network Wizard "add printer"?

    What about windows XP. A network printer mysteriously stopped working. When I use the wizard of windows 'add printer' does not fill any device on my network. Why? What I can do to add a printer. An error message is this printer not found on the serve

  • WTH is going on here?

    I spent a day of unbearable, trying to figure out just how the hell am I to solve this problem. To be concise; overtime, I hit 'print settings' in my PS5 PS printer dialog box crashes. To back up a little; I upgraded my OS to Yosemite 10.10 then as a