How to write Dynamic SQL for this SQL ?

EXECUTE IMMEDIATE 'select COUNT(*) from dba_Tab_privs@' ||db_link|| ' WHERE Grantee <> 'DELETE_CATALOG_ROLE'
AND Table_Name = 'LINK$'
AND Grantee NOT IN (SELECT Grantee
FROM dba_Role_privs
WHERE Granted_Role = 'DBA')' into i using x;

Hi bapalu,
I take that x is the name of your db_link?
If so,
DECLARE
   i      NUMBER;
   x      dba_db_links.db_link%TYPE;
   stmt   VARCHAR2(255);
BEGIN
   x := 'some_link';
   stmt :=
      'SELECT count(*)
         FROM dba_tab_privs@:db_link
        WHERE grantee <> ''DELETE_CATALOG_ROLE''
          AND table_name = ''LINK$''
          AND grantee NOT IN(SELECT grantee
                               FROM dba_role_privs
                              WHERE granted_role = ''DBA'')';
   EXECUTE IMMEDIATE REPLACE(stmt, ':db_link', x)
                INTO i;
   dbms_output.put_line('The count: ' || i);
END;Also, I think this is maybe not what you want:
AND table_name = ''LINK$''Regards
Peter

Similar Messages

  • How to write Select statement for this codition

    I need to check whether SGTXT contains BELNR value.
    SGTXT is a text field and It should be matched with BELNR
    How to write select statement for this.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT should have the given BELNR Value.
    Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.

    Hi,
    data temp(12).
    concatenate '%' belnr '%' into temp.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT like temp.
    If belnr is having multiple values,just create a internal table as follows.
    types : begin of ty,
            belnr....
            temp(12),
            end of ty.
    data itab_ type standard table of ty.
    data wa type ty.
    loop at itab into wa.
    concatenate '%' wa-belnr '%' into wa-temp.
    modify itab from wa index sy-tabix transporting temp.
    endloop.
    Change your select statement accordingly.
    Kindly reward poits if it helps.

  • How to write a PCR for this ?

    Hi SAP-HR Experts .
    Dear friends , My Company Requires a specific requiremnt that at the date of any Employee's
    B'day his one day salary should get doubled and he is entitled to get one leave on his B'day .
    I do not know how to write a PCR for this ?
    May some Body tell me how to meet this requirement Please .
    tell me please step by step how to go through ...
    It will be great help for me .
    Best regards : rajneeesh

    I think you can make it with something like this:
    Write a PCR in schema, you can call the rule with "actio";
    000860 ACTIO 9BIR AR               Birthday
    Rule 9BIR
    9BIR Rule for Birthday
            NUM=FG C   Set                   " F (fixed indicator for deadline calculation); G (Birth date from infotype 0002);C (complete months)
            NUM/12     División              " Number of completed months divided by  12
            NUMV0O2L   Off.Lng en arg.var.   " the last two places of the number are entered in the variable argument.
                                " if the rest is not 00, there is nothing to do
              00                             " if the rest is 00
                ZERO= N    AmtNumRteZeit = 0 "
                AMT=  1002 Set               " wagetype of  salary
                AMT/TKDIVI División          " divides the amount by  Partial Period Parameter Whole Month
                ADDWTI1002 Input table       " accumulates into 1002
    Example: an employee with birthday 01.01.1977 in IT0002
    Payrroll in january 08
    wagetype 1002 before rule 9BIR:
    3 1002 Salario Bas01                           30,33  30,00              909,90
    Rule 9BIR
    NUM=FG C   Set; NUM= 372
    NUM/12        ; 372/12= 31 rest=00
    AMT=1002      ; AMT= 909,90
    AMT/TKDIVI    ; 909,90/31= 29,35
    ADDWTI1002    ; 909,90 + 29,35= 939,25
    wagetype 1002 before rule 9BIR:
    3 1002 Salario Bas01                           30,33  30,00              939,25
    Hope this helps. Manuel

  • How  to write  a  query  for this output

    I have a string ' if i know good acting , I am a hero '
    now if 'hero' is present in the string it will return ' i am hero' else
    'you are hero'
    How to write a sql query to return the same .

    SQL> select (case
    2 when '&a' like '%hero%' then 'I am hero'
    3 ELSE 'u r hero'
    4 end) output from dual;
    Enter value for a: if i know good acting , I am a hero
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
    OUTPUT
    I am hero
    SQL> /
    Enter value for a: jkhkh
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'jkhkh' like '%hero%' then 'I am hero'
    OUTPUT
    u r hero
    Hope this helps.

  • How to use dynamic query for this ??

    hi , i am new to ABAP. i got a requirement to write  dynamic query for the following code.
    kindly address. two set of queries are same.but condition is different.
    .IF p_psd EQ ' '.
    *C--End of change DF 1232137- (Transport # :CIDK980530 )
    *C--FETCH THE Deliverd Quantiity and Material Number
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng IN s_dqt
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
        IF sy-subrc = 0.
          SORT t_afpo BY aufnr matnr pwerk.
    *C--FETCH THE OBJECT NUMBER
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_aufk BY aufnr objnr.
    *C--FETCH THE Target Quantiity
            SELECT aufnr "ORDER number
                   gamng "Total order quantity target quantity
                   FROM afko
                   INTO TABLE t_afko
                   FOR ALL ENTRIES IN t_afpo
                   WHERE aufnr = t_afpo-aufnr
                   AND   gamng IN s_tqt.
            IF sy-subrc = 0.
              SORT t_afko BY aufnr .
            ENDIF.
          ENDIF.
        ELSE.
          MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
          LEAVE LIST-PROCESSING.
        ENDIF.
    *C--Begin of change DF 1232137- (Transport # :CIDK980530 )
      ENDIF.
      IF p_psd EQ c_x.
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng > 0
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
    if sy-subrc = 0.
    *C--FETCH THE OBJECT NUMBER
        IF  NOT t_afpo[] IS INITIAL.
          SORT t_afpo BY aufnr matnr pwerk.
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
        IF NOT t_afpo[] IS INITIAL.
    *C--FETCH THE Target Quantiity
          SELECT aufnr "ORDER number
                 gamng "Total order quantity target quantity
                 FROM afko
                 INTO TABLE t_afko
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr
                 AND   gamng <> t_afpo-wemng .
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
      ELSE.
        MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
        LEAVE LIST-PROCESSING.
      ENDIF.
    Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tags

    Hi friend,
    Try using MACRO and dynamic WHERE condition.
    Group simialr Select statements under a Macro.
    Build a dynamic where by checking conditions
    Call macro passing dynamic where condition.
    TABLES afpo.
    DATA: str TYPE string.
    *Macro definition
    DEFINE operation.
      select single *
           from afpo into afpo
           where (&1).    " Dynamic condition
    END-OF-DEFINITION.
    *Build dynamic WHERE by checking some conditions
    *If conditon 
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
    *Else
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
    *Endif.
    *Call Macro passing dynamic WHERE condition
    operation str.

  • How  to write select query for this

    Hi,
    I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement  query .
    When i try to write the select statement and trying to run i am getting error.
    select * from Table
    where emo_no = '1,2,3'
    this is how i write query please suggest me how  to write query for selecting multiple values from the drop down box.
    Thanks

    select * from Table
    where emo_no in ( 1,2,3)
    for integer values
    select * from Table
    where emo_no in ('1','2','3')
    for characters
    If we talk about large scale applications that may have millions of records, I would suggest this.
    declare @t table (v int)
    insert into t (v) values (1)
    insert into t (v) valves (2)
    insert into t (v) values (3)
    select *
    from table
         inner join @t t on table.emo_no = t.v
    Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
    This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
    create table #t (v int)
    insert into #t (v) values (1)
    insert into #t (v) valves (2)
    insert into #t (v) values (3)
    create index ix_t on #t (v)
    select *
    from table
         inner join #t t on table.emo_no = t.v
    drop table #t
    Pardon any syntax errors and careful using a drop statement.
    Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
    Probably too much info  ;-)
    Byron Mann
    [email protected]
    [email protected]
    Software Architect
    hosting.com | hostmysite.com
    http://www.hostmysite.com/?utm_source=bb

  • How to write a query for this data??

    In this table i have column dob which is DATE type,for example 12-jan-89 I want output like this
       Year              Day
    12-jan-89         Thusrs_day
    12-jan-90          Friday
    upto
    12-jan-14        sunday

    krishnagopi wrote:
    No not like that ,I want up to 2014 year
    Ok, so lets say you have table like this
    SQL> create table my_table(dob date);
    Table created.
    SQL> insert into my_table (dob) values( to_date('12-jan-1989', 'dd-mon-yyyy'));
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from my_table;
    DOB
    12-JAN-89
    You can write a query like this
    select dob + (level -1) dob
          , to_char(dob + (level -1), 'fmDay') day_
       from my_table
    connect
         by level <= (dob + interval '25' year) - dob + 1;

  • How to write a class for this?

    how do i write a different class for this? how do i implement the "a.add(b)"? it code is to test basic arithmetic operations.
              System.out.print ("Arithmetic: enter two integer numbers: ");
              Integer a = new Integer (Integer.parseInt(kbd.readLine()));
              Integer b = new Integer (Integer.parseInt(kbd.readLine()));
              System.out.println (a + "+" + b + "-" + b + "*" + a + "/" + a + "%" + b + " is: "                                    + a.add(b).sub(b).mul(a).div(a).rem(b));                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    public class arthOperation{
         add()
              sub()
         sub(){
              mul()
         mul(){
              div()
         div(){
              rem()
         rem(){
    is it write?

  • How to write dynamic actions for delimiting child subtype of IT0021

    Hi ,
    I need the dynamic actions for the below scenario:
    In IT0021 , there is a child subtype '02'. This needs to be delimited to a new subtype 'XX' when the child reaches a certain age.
    The above process needs to be automated..as in when the new subtype 'XX' is created, it should check the fields like date of birth , last name and on saving it , the corresponding child subtype screen should be called where the user can modify the end date and delimit the child subtype.
    Please help me with the required dynamic actions..
    Thanks.

    Hi,
    Just try this.
    INFTY     SUBTY      FIELDN      FC NO.      STEP VARIABLE FUNCTION
    0021      02      Field Name      P       TabName-FldName>=age
    0021     XX               I         INS, 0021,XX/I
    Regards,
    Srini.

  • How to write a DTD for this scenario?

    hi,
    consider the following xml
    <set after = "A">
    <item name="A" ></item>
    <item name="B" ></item>
    </set>
    The DTD for the "item" element is
    <!ATTLIST item name (A | B| C| D| E ) #REQUIRED >
    The attribute "after" of "set" can hold a single valid name like
    <set after = "A">
    or
    a collection of valid names seperated by coma like <set after = "A,B,C">
    how to write DTD for the "after" attibute such that it will contain a single valid name or collection of names?
    Regards,
    Ajay.

    I could be wrong, but I'm pretty sure that DTD doesn't support that. You're probably better off declaring the name attribute to be of type PCDATA and tokenizing the value manually in code.

  • How to write a query for this situation

    Hi ,
    Can any one help me to write a query.I have a table with three columns like char_id_1,char_id_2,char_id_3,these data have to insert into some other table but in the target table the data should be comma seperated like (10,8,2),here blank space indicates null.In source table the columns are numbers,but in target table it is varchar2.
    source table:
    CHAR_ID_1 CHAR_ID_2 CHAR_ID_3
    10 8 2
    7 1 5
    4 11
    6 1
    2 8
    6 12 7
    Target table:
    CHAR_IDS
    10,8,2
    7,1,5
    4,11
    6,1
    2,8
    6,12,7

    I started doing it to_char way, and thought of some different version, and ended up with an ugly solution which works only if you have three columns. Thought of not posting, but posting it anyway:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> with t as(
      2      select 10 c1,8 c2,2 c3 from dual union all
      3      select 7,1,5 from dual union all
      4      select 4,null,11 from dual union all
      5      select null,6,1 from dual union all
      6      select 2,8,null from dual union all
      7      select null,8,null from dual union all
      8      select null,null,10 from dual union all
      9      select 2,null,null from dual union all
    10      select null,null,null from dual union all
    11      select 6,12,7 from dual )
    12  --
    13  select nvl2(c1,
    14              c1 || nvl2(c2,',' || c2 || nvl2(c3,',' || c3,null),nvl2(c3,',' || c3,null)),
    15              nvl2(c2, c2 || nvl2(c3,','|| c3,null),nvl2(c3,c3,null))) col_concat
    16  from t;
    COL_CONCAT
    10,8,2
    7,1,5
    4,11
    6,1
    2,8
    8
    10
    2
    6,12,7
    10 rows selected.
    SQL>

  • How to write a query for this

    I have 2 tables
    emp_master (emp_id, emp_name)
    dept_master (dept_id, dept_name, emp_id (references emp_id in emp_master)Now there are 30 departments and each department can have maximum 5 employees.
    Now I want a query that would list a department and all its employees in one line and if there are less than 5 employees it would show null for the rest of columns.
    Dept_id emp_1 emp_2 emp_3 emp_4 emp_5
    1 1 2 -- -- --
    2 3 4 5 6 7
    3 8 -- -- -- --
    Please help me out
    Thanks...

    One solution may be
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> SELECT e.department_id, e.employee_id
      2    FROM employees e
      3   WHERE e.department_id IN (10, 20, 40, 60, 90)
      4  /
    DEPARTMENT_ID EMPLOYEE_ID
               90         100
               90         101
               90         102
               60         103
               60         104
               60         105
               60         106
               60         107
               10         200
               20         201
               20         202
               40         203
    12 rows selected
    SQL>
    SQL> SELECT ee.department_id, ee.emp_1, ee.emp_2, ee.emp_3, ee.emp_4, ee.emp_5
      2    FROM (SELECT MAX(CASE
      3                       WHEN MOD(r, 5) = 1 THEN
      4                        e.employee_id
      5                       ELSE
      6                        NULL
      7                     END) emp_1,
      8                 MAX(CASE
      9                       WHEN MOD(r, 5) = 2 THEN
    10                        e.employee_id
    11                       ELSE
    12                        NULL
    13                     END) emp_2,
    14                 MAX(CASE
    15                       WHEN MOD(r, 5) = 3 THEN
    16                        e.employee_id
    17                       ELSE
    18                        NULL
    19                     END) emp_3,
    20                 MAX(CASE
    21                       WHEN MOD(r, 5) = 4 THEN
    22                        e.employee_id
    23                       ELSE
    24                        NULL
    25                     END) emp_4,
    26                 MAX(CASE
    27                       WHEN MOD(r, 5) = 0 THEN
    28                        e.employee_id
    29                       ELSE
    30                        NULL
    31                     END) emp_5,
    32                 e.department_id
    33            FROM (SELECT row_number() over(PARTITION BY department_id ORDER BY employee_id) r,
    34                         department_id,
    35                         employee_id
    36                    FROM employees
    37                   WHERE department_id IN (10, 20, 40, 60, 90)) e
    38           GROUP BY e.department_id) ee
    39  /
    DEPARTMENT_ID      EMP_1      EMP_2      EMP_3      EMP_4      EMP_5
               10        200                                 
               20        201        202                      
               40        203                                 
               60        103        104        105        106        107
               90        100        101        102           
    SQL> Regards...

  • How to write  complex sql for this

    Hi ALL,
    I have a requirement like this
    I have 5 tables which i have to join to get the result
    but there no join column to 2 other table.
    I want to get all the applications using cobal,running on UNIX.
    How to write the query for this
    1.APP
    APP_i DESC
    1 Accounts
    2 Payments
    3 order transfer
    4 Order processing
    2.Techgy
    techid techdesc
    1 cobal
    2 Java
    3.APP_Techgy
    APP_I Techid
    1 1
    2 1
    3 1
    4 2
    4.Pltfrm
    pltfmid pltfrmdesc
    1 Windows NT
    2 UNIX
    5.APP_Pltfrm
    APP_I pltfrmid
    1 1
    2 1
    3 2
    4 2
    ouput must be
    APP_i Desc techDESC pltfrmdesc
    3 ordertranfer Cobal UNIX
    Thanks in advance

    This ('descr' in place of 'desc')?
    SQL> select a.app_i, a.descr, t.techdesc, p.pltfrmdesc
    from app_techgy atc,
       app a,
       techgy t,
       app_pltfrm ap,
       pltfrm p
    where atc.techid = t.techid
    and atc.app_i = a.app_i
    and atc.app_i = ap.app_i
    and ap.pltfrmid = p.pltfmid
    order by a.app_i
         APP_I DESCR                TECHDESC             PLTFRMDESC         
             1 accounts             cobal                windows nt         
             2 payments             cobal                windows nt         
             3 order transfer       cobal                unix               
             4 order processing     java                 unix               
    4 rows selected.

  • How to write Error message for select options?

    Hi
    i have this select option statement
    SELECT-OPTIONS: s_fevor FOR afko-fevor.
    how to write error message for this?
    Regards
    Smitha

    Error messages are displayed for Select-options mostly on two conditions:
    1) You needs to check wether a value is entered or not its done by:
    a)
    Select-options:SELECT-OPTIONS: s_fevor FOR afko-fevor Obligatory.
       In this case error message is automatically throwed by system.
    b) You can do this in Selection Screen events.
    Ex:
    AT SELECTION-SCREEN./AT SELECTION-SCREEN ON S_FEVOR.
    IF S_FEVOR-LOW IS INITIAL.
    MESSAGE 'XXXXX' TYPE 'E'.
    ENDIF.
    2) You need to Validate the entered value:
    You can do this in Selection Screen events.
    Ex:
    AT SELECTION-SCREEN./AT SELECTION-SCREEN ON S_FEVOR.
    SELECT FEVOR
                 FROM AFKO
                 INTO AFKO-FEVOR
                 UP TO 1 ROWS
    ENDSELECT.        
    IF SY-SUBRC NE 0.
    MESSAGE 'XXXXX' TYPE 'E'.
    ENDIF.
    Regards,
    Gurpreet

  • How to write a sql query to retrieve data entered in the past 2 weeks

    Hi,
    I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
    Thanks in advance.

    This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
    Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
    I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate".

Maybe you are looking for

  • Regarding BPM

    Hi All, I'am using BPM.(File-BPM-File) I'am getting data from 2 files for that I've used 2 receive steps with in the fork. 1st receive step for Control data from one file and i use option start process for this receive step. 2nd receive step for deta

  • Markers on clips don't move with project when switching media drives

    Here's an odd one. I'm editing a project in Premiere Pro CS6 and in order to avoid carrying drives back and forth between two editing locations, I cloned the footage drive and have one duplicate drive in each location. I'll call them location A and B

  • Unable to open Adobe

    How can I open my adobe for reading materials.

  • 3.4 gig Free on my Zen Xtra 60gig and this wonderful firmware won't allow anymore transf

    I am beginning to really hate Creative and how they choose Microsoft over their loyal customers. I cannot transfer anymore music to my ZenXtra 60 even though I have 3.4 gig free. I keep getting error messages saying library is full or I get just an e

  • Help on connecting to laptop

    I just got this new windows 8 laptop and when i try to add my HP Officejet 4500 G510n-z printer wireless, and it wont work, like its say cant find printer