IN parameter is the string of column names I want to SELECT delimited

Hi guys,.

Please bare with me. Not a pro at writing stored procedures.

What I try to do is to pass a parameter of 'IN' to the proc. The setting is a varchar2 which is a comma-delimited string.
I want to put this string in the SELECT statement.

This setting is called "P_SelectFields".

The value in the passage in the proc is like:
P_SelectFields = ' CUSTOMERS SUM (CLI_SERVED) AS SUM (EI_INTC) + SUM (NEI_INTC) AS INTERVENTIONS,
SUM (TOT_EMPRTN) AS EMP_RETURN, SUM (TOTAL_RTS) AS SCHOOL_RETURN
"


That's what I've got and I know that it works, if I put the string instead of the parameter it works. !

PROCEDURE GET_NATIONAL_TOTAL_RESULTS (P_SelectFields IN varchar2, P_AGREEMENT_TYPE_IND AGREEMENT_TYPE.agreement_type_ind%TYPE, io_cursor in SYS_REFCURSOR)
IS
BEGIN
OPEN FOR Io_cursor

SELECT year_desc,
P_SelectFields - that's where I want my partameter go.

OF SPF_RESULT_VW
WHERE r_num = 1 - FILTER for the LAST PERIOD for EACH YEAR
and agreement_type_ind = P_AGREEMENT_TYPE_IND - desired FILTER FOR Agreement_type_ind
GROUP BY year_desc
ORDER BY year_desc
;

END GET_NATIONAL_TOTAL_RESULTS;


That's what I'm after you run the proc.

YEAR_DESC = 2011-2012
: B2 = SUM (CLI_SERVED) ACE, SUM (EI_INTC) CUSTOMERS + EMP_RETURN SUM (NEI_INTC) AS OF THE INTERVENTIONS, SUCH AS SUM (TOT_EMPRTN), SUM (TOTAL_RTS) SCHOOL_RETURN

Where is ': B2 = "come from?".

What can I do to make my parameter is "picked up" by the proc?

Thank you

Firstly: in relational databases, there is no distinction between 'fields '. Tables is not 'fields', they have columns.
It is my experience that that call columns 'fields' basically treats the database as a flat file system. It's a very bad idea!

If you want to pass as a parameter column names, you need dynamic SQL.
However, PL/SQL was invented to reduce the analysis and using of the dynamic SQL, you'll at least soft-parse each statement.

Dynamic SQL is obviously in the documentation, but most people here think that they don't need to read the documentation.

So, for once
glance

OPEN io_cursor FOR
'SELECT year_desc,'||
P_SelectColumns||
' FROM SPF_RESULT_VW '||
'WHERE r_num = 1 '|| --FILTER FOR LATEST PERIOD FOR EACH YEAR
'and agreement_type_ind = P_AGREEMENT_TYPE_IND '||-- FILTER FOR desired Agreement_type_ind
'GROUP BY year_desc '||
'ORDER BY year_desc'
;

Please note that I have renamed the parameter.

Tags: Database

Similar Questions

  • How cut the length of the string IE channel name here, if it exceeds 20 characters or letters. The channel name is dynamically analyzed the spreadsheet/xml file.

    How cut the length of the string IE channel name here, if it exceeds 20 characters or letters. The channel name is dynamically analyzed the spreadsheet/xml file.

    My Council of Europe in the .js file is

    function generateHTMLMarkup (i, channel) {}
    Alert ("this is lang" + str);
    var str ="";
    "Str += '.

    ";
    "Str += '.
    "+ ""+""+"
    ";
    Alert ("this is lang" + str);
    return str;

    }

    nerateHTMLMarkup: function (i, channel) {}
    Alert ("this is lang" + str);
    var str ="";
    "Str += '.

    ";
    str += "" +
    "" +
    "" + channel ['name'] + "" +.
    "" + "
    ";
    "Str += '.
    "+ "" + "
    ";
    Alert ("this is lang" + str);
    return str;

    etc.

    Give mthe rhythm and the exact code where Ihave tio get implemented.

    in the code, replace change

    channelName var = channel ['name'];

    TO

    channelName var = channel ['name'];

  • error when the type of the parameter is the string

    I want to create a task, and the procedure has a parameter type is string. It get the error ORA-06550 and PLS-00103.


    BEGIN
    DBMS_SCHEDULER. () CREATE_JOB

    job_name = > 'JOB_TEST ',.

    job_type = > 'procedure_stockee ',.

    job_action = > ' SH. PKG_TEST. SP_TEST (seq_batchid.nextval, 'SYSTEM', extract (year sysdate), extract (month of sysdate))'.

    = start_date > to_date (18 February 2012 04:00 ',' dd-mm-yyyy hh24:mi:ss'),
    activated = > false,

    "repeat_interval = > ' FREQ = daily"


    );

    END;
    /

    Hello

    You use the type of work badly, your job type should be plsql_block, that is

    job_type-online "PLSQL_BLOCK."

    If you are using a type of employment procedure_stockee the job_action may contain the name of the stored procedure without arguments.

    -Nice

  • Use the string as instance name

    var character: Array = new Array();

    for (var i: int = 1; i < = 26; i ++)

    {

    If (I < 10)

    {

    Persona.push ("persona0" + i);

    }

    on the other

    {

    Persona.push ("persona" + i);

    }

    }

    //

    var personaclip = persona [4]; persona04

    var personainstance:MovieClip = new personaclip();

    addChild (personainstance);

    What I'm trying to do here, is first to create a table of all 26 clips that are already in the library and the value of export for actionscript, persona01 to persona26.

    Can I choose the number for the clip to use, which is persona04. I would like to add that, for the scene. So I first create the instance of the element persona04 through personainstance and then add it by addChild.

    But the variable personainstance is where I'm going wrong I get an error #1007 trying to create an instance on an element that is not a constructor. How can I make it clear that for the movieclip personainstance I want to select the clip of persona04 form the library? Guess I have to convert the string "persona04" in the name of the constructor, somehow.

    creating instances of dynamic class using strings
    -------------------------------------------------------------

    var ClassRef: Class = Class (getDefinitionByName ("className"));
    var classInstance: * = new ClassRef();
    addChild (classInstance);

  • Value of the item as column name to select

    Hello

    I have a problem with the selection of the columns in the query using elements. For example: I have a request:
    Select column_a table; or select table column_b;

    and I want to do something like this:
    n ' any item where I choose the column name
    -query: select column_from_item from the tale of

    Is this possible?
    My version of the apex: 4.0.2.00.07
    My version of db oracle: oracle 11g

    Hello

    Create a report... type... as a function returning the SQL statement...

    and then you source should be something like

    declare
       my_sql_statement varchar2(1000);
    begin
       my_sql_statement := 'select ' || :p1_x || ' from table';
       return my_sql_statement;
    end;
    

    Kind regards
    Shijesh

  • [SOLVED] Property of the label of the box = MySQL column name

    Hello!
    I'm trying to get the value of a column in a MySQL database to link to the label of a checkbox property.
    I use a Repeater to retrieve all records in the database - but what I really need, but the names of column to a table and not the lines/records.

    So, is it possible to get the values of the column names in a MySQL via a PHP request directly, or I have to create a
    an XML file separate that contain manually entered values?

    Thanks for your help!
    Kind regards
    Christo

    This has been resolved.

    See the code below
    Kenwio

    THE FLEX AND PHP CODE:

  • In SSMS, that means the space between an alias of the table and column name mean?

    Sometimes I see this: "d.PhaseKey" instead of this "d.PhaseKey".

    I'm sure this means something is wrong in the query or table - but this gives no indication of what is wrong?

    I'm not sure on how to interpret it.

    Hello

    We have dedicated support for Microsoft SQL Server Management Studio Express forums. I would have you post your query in the MSDN Forums for assistance on this issue.

    You can check the link to post your question:

    http://social.msdn.Microsoft.com/forums/en-us/home

    It will be useful.

  • Add the string at the end of the column name

    Hi all

    I wonder whether it is possible or not. I created a similar table to another table to help-


    create table table_name in select * from table_name1;
    Now, I want to differentiate the name of the column of the previous table column names. I want to add E at the end of all column names. Is it possible using sql Command in sql or Toad workshop without doing it manually as I have more than 100 columns in this table?



    Thanks in advance.



    Kind regards



    Pascal M

    Hello

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL> create table test_1(col1 number, col2 varchar2(30));
    
    Table created
    
    SQL> create table test_2 as select * from test_1;
    
    Table created
    
    SQL> desc test_2;
    Name Type         Nullable Default Comments
    ---- ------------ -------- ------- --------
    COL1 NUMBER       Y
    COL2 VARCHAR2(30) Y                         
    
    SQL>
    SQL> DECLARE
      2     v_table_name USER_TAB_COLUMNS.TABLE_NAME%TYPE := 'TEST_2';
      3     c_column_suffix CONSTANT VARCHAR2(1) := 'E';
      4  BEGIN
      5     FOR REG IN (SELECT UTC.COLUMN_NAME
      6                   FROM USER_TAB_COLUMNS UTC
      7                  WHERE utc.TABLE_NAME = v_table_name) LOOP
      8        EXECUTE IMMEDIATE 'ALTER TABLE ' || v_table_name || ' RENAME COLUMN ' ||
      9                          reg.column_name || ' TO ' ||
     10                          substr(reg.column_name,
     11                                 1,
     12                                 29) || c_column_suffix;
     13     END LOOP;
     14  END;
     15  /
    
    PL/SQL procedure successfully completed
    
    SQL> desc test_2;
    Name  Type         Nullable Default Comments
    ----- ------------ -------- ------- --------
    COL1E NUMBER       Y
    COL2E VARCHAR2(30) Y                         
    
    SQL>
    

    Kind regards

  • column name is in the original order after table1 less table2

    Windows XP/10.2.0.1.0

    Table1 with the names of the columns: PLAN, ID, COUNTER, TEXT, COMMAND
    Table2 with columns name: PLAN, ID, COUNTER

    SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = TABLE1
    LESS
    SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = TABLE2

    The above out put is STOPPED, TEXT. Is it possible that keep the original output in the form of TEXT, CONTROL column

    Thanks in advance

    Yes, since COLUMN_ID is no not part of your select clause, you have to actually change your query:

    SQL> select column_name from user_tab_columns where table_name='MYTBL2'
      2  minus
      3  select column_name from user_tab_columns where table_name='MYTBL1'
      4  order by column_id;
    order by column_id
             *
    ERROR at line 4:
    ORA-00904: "COLUMN_ID": invalid identifier
    
    SQL> select column_name
      2  from   (select column_name,column_id from user_tab_columns where table_name='MYTBL2'
      3          minus
      4          select column_name,column_id from user_tab_columns where table_name='MYTBL1')
      5  order by column_id;
    
    COLUMN_NAME
    ------------------------------
    C3
    C4
    

    Nicolas.

  • Having a column name as a variable in a query, problem!

    I have a problem with a simple query below


    SELECT * FROM DisneyWHERE Upper (COLNAME) AS SUPERIOR ('%' |) SEARCHSTRING. '%'); SELECT * FROM Disney
    WHERE Upper (COLNAME) AS SUPERIOR ('%' |) SEARCHSTRING. '%');

    My problem, the variable of column name is not recognized as a column for example name
    A user can select to display a set of characters from the database by user name, movies, etc (they selecting this function since a combobox), they then enter a search string (textbox)
    column name = user name
    SearchString = pluto

    SELECT * FROM Disney
    WHERE Upper (COLNAME) AS SUPERIOR ('%' |) SEARCHSTRING. '%');

    The problem is orac; e does not seem to be picking up this column name is a column name and seems to be a simple comparison. To make this more clear

    It "seems to match the username = pluto
    instead of find pluto in the username column.

    Someone at - it ideas how I can get around this. I have a strange feeling, it's something to do with pl/sql dynamic, but I am new to oracle, so I have no idea of how to write dynamic queries. Any help would be appreciated muchly

    I'm using oracle 11g and visual studio .net 2005

    user10372910 wrote:
    But it wouldn't just look for each column I'm sorry if I seem stupid that I have only just introduced to oracle and I used to use sql

    Sort of Yes and no.

    If colname is 'film' and the search string 'star wars' is the place where actually takes the clause...

    WHERE username as username
    AND the movie like 'star wars % % '.

    If username is not limited in any way and it limits just on film.

    Conversely if the column name is "username" and the search string is 'Bob Smith' then where clause evaluates actually to...

    WHERE username like ' %% of Bob Smith.
    AND the film as film

    then move is not limited in any way and simply limits on the user name.

  • How to get a list of column names

    Hello

    I need to test the list of column names that are present in the table with my column list who are in excel. Currently im using Toad, if you press f4 on the name of the table, it will display
    . But I need a sql query to check it out.
    I tried user_tables; not work and tried with information_schema.columns but table does not exist error coming.

    How to get those details using sql querry.

    SELECT column_name

    Of all_tab_cols

    WHERE table_name = 'name of the Table.

    or

    SELECT column_name

    Of all_tab_cols

    WHERE table_name = 'name of the Table.

    AND owner = 'name of the owner.

  • How to connect the vCO vRO action name programmatically?

    Anyone know if we can save name of the action by programming just as a workflow name can be made, something like Workflow.action.name?  This helps identify what action the failure occurred.

    Jörg have already said, there is not such a generation - in function. However, you can use the default, that Rhino javascript engine of capabilities to achieve what you're trying to do. Use this:

    //VRO's arguments.callee.name implementation will always return the String "Module + action name".
    //We remove the "Module" prefix. Remember: while this works with vRO 6 and 7, it may stop working if the RHINO implementation changes.
    var actionName = arguments.callee.name.substr(6);
    //Keyword this represents the module this action is part of. The Module scripting object provides access to the name property.
    System.log("The currently running action is: " + this.name + "." + actionName);
    

    Concerning

    Robert

  • Get the types of columns in a select statement

    Hello

    Is there a way to get the types of columns that results in a select statement?

    For example to force an analysis on this topic and then look for the types of columns resulting in the view v$?

    Best regards

    Klaus Mogensen

    declare
      c       number;
      d       number;
      col_cnt integer;
      rec_tab dbms_sql.desc_tab;
      col_num number;
    begin
      c := dbms_sql.open_cursor;
      dbms_sql.parse(c, 'select dummy, 33 x, sysdate now from dual', dbms_sql.native);
      dbms_sql.describe_columns(c, col_cnt, rec_tab);
      col_num := rec_tab.first;
      while col_num is not null
      loop
        dbms_output.put_line( rec_tab(col_num).col_name || ' ' ||
                              case rec_tab(col_num).col_type
                                when 1 then 'varchar2'
                                when 2 then 'number'
                                when 12 then 'date'
                                else '???? ' || rec_tab(col_num).col_type
                              end
                            );
        col_num := rec_tab.next(col_num);
      end loop;
      dbms_sql.close_cursor(c);
    end;
    /
    DUMMY varchar2
    X number
    NOW date
    
  • Coverting a line in the values in columns

    Hi friends Expert SQL,

    I have a line that contains 6 columns where I want the data to appear in the form of columns, as shown here:

    From:

    Select item1, item2, item3, amt1, amt2, amt3 in item_table, when sno = 1; <-returns 1 row as below

    ITEM1 ITEM2 ITEM3 AMT1 AMT2 AMT3
    ---------- ------------ ------------- ----------- ------------ ----------
    AAA BBB CCC 10,00 20,00 15,00


    Explanation of data: item1 (AAA) price is amt1 (10.00), item2 (BBB) price is amt2 (20 h 00) and item3 (CCC) price is amt3 (15.00). Ok.

    Now I want that data to be converted to columns, as shown here:

    TO:

    AMT ELEMENTS
    --------- ---------
    AAA 10.00
    BBB 20.00
    CCC 30.00


    Please help me guys, I want a SQL to display these data.

    I found a single query that converts a row of columns, but this is not my requirement: [for your reference only]

    SQL > select substr (the_string
    , decode (level, 1, 1, instr(the_string,',',1,level-1) + 1)
    , decode (instr(the_string,',',1,level), 0, length (the_string), instr(the_string,',',1,level) - decode (level, 1, 0, instr(the_string,',',1,level-1))-1)
    ) the_value
    from (select (select item1 |)) «, » || Item2. «, » || Item3 item_table where sno = 1) ELEMENTS
    the double)
    connect by level < = length (the_string) - length (replace(the_string,',')) + 1


    Thank you and best regards,
    Kiran
    WITH pivot_data
         AS (SELECT 'AAA' ITEM1,
                    'BBB' ITEM2,
                    'CCC' ITEM3,
                    '10.0' AMT1,
                    '20.0' AMT2,
                    '15.00' AMT3
               FROM DUAL)
    SELECT t1.items, t.amount
      FROM (SELECT NULL items, amount, ROWNUM rn
              FROM pivot_data UNPIVOT INCLUDE NULLS (amount
                              FOR items
                              IN (AMT1, AMT2, AMT3) )) t,
           (SELECT items, NULL amount, ROWNUM rn
              FROM pivot_data UNPIVOT INCLUDE NULLS (items
                              FOR amount
                              IN (ITEM1, ITEM2, ITEM3))) t1
     WHERE t.rn = t1.rn
    
    ITEMS     AMOUNT
    AAA     10.0
    BBB     20.0
    CCC     15.00
    
  • I have a photo n &amp; b and I want to select/display just the pixels to their real shadow and shade. How can I do this?

    Basically, if I have a photo of n & b and all the pixels fall into darkness of 100% (black) and the darkness of 0% (white), I want to select/display just the pixels that are between 40% darkness and darkness of 50% or 70% darkness and obscurity 80%. Is there a simple way to do this?

    1. create a level of gray as in the example above.

    2 place it on a layer above the image as shown, then merge down to create a single layer

    3. place a layer of white below

    4. return to the upper layer and double-click it to open the layer Style

    5 move the top right slider to the left to remove the values 0 to 35

    6 move the cursor on the top left to the right in order to eliminate the values 100 to 65

    Other values in grayscale and photo are between 40 and 60%

    Set the other parameters and apply the same technique.

    (To save you time, I can send you the scale.)

Maybe you are looking for

  • Installation of a card Mini PCI WLAN on Satellite A30

    Bought and installed card in the A30-104 correctly, but the PC then seems to go online and find to install the software. I can go online via ethernet, but it does not find the required software.No software or instructions not accompanying the card. a

  • Relationship between the samples through the second rate and sampling

    I was wondering if someone could clarify the relationship between the samples through second rate and sampling. I have USB6008 and USB6363 of the tips that I work with in Measurement Studio. For the nec USB6008 entry differential (up to four channels

  • Question Re: Folder AppData

    I was looking through the folders in my Standard account and I can't enter my AppData folder.  I have then connected on my administrator account and can not enter in the AppData folder either.  The folder is shaded on. Does anyone else have this prob

  • BlackBerry Q10 need to change my email id address

    I recently left a company, and the e-mail account on my blackberry is with this company. The e-mail account is now inactive. I want to change the name of the e-mail account, but I don't have the password for the account. So BB continues to send messa

  • How can you print a picture to animate cc?

    How can you print a picture to animate cc?  Flash print it is fine, I can not find a print option to animate and this seems to be a very practical and very important feature for any program, and it would be stupid to delete... Or move, but I can't fi