Set date as column name
Hi All. Does anybody know how to get the date of every Friday based on a given quarter and set it as the column name. For instance with quarter 1 the column names would be
1/6/2006
1/13/2006
1/20/2006
1/27/2006
etc
Thank you!
Hi,
Try something like :
1 select day# as FRIDAY
2 from
3 (select fist_day_q+rownum-1 day#
4 from
5 (select trunc(sysdate,'q') fist_day_q,
6 last_day(add_months(trunc(sysdate,'q'),2)) last_day_q
7 from dual)
8 connect by level <= last_day_q - fist_day_q +1)
9* where to_char(day#,'d')=5
SQL> /
FRIDAY
06/01/06
13/01/06
20/01/06
27/01/06
03/02/06
10/02/06
17/02/06
24/02/06
03/03/06
10/03/06
17/03/06
FRIDAY
24/03/06
31/03/06
13 rows selected.Nicolas.
Similar Messages
-
iam not able to insert data into datagrid corresponding to the column names..as iam inserting both data and column names programatically..ie iam not able to co relate the data with the column names.plzzz help me asap
A DataGrid is row-based rather than cell-based with each row
corresponding to an item in an underlying collection (specified in the
dataProvider property). In order to add data to a DataGrid you
manipulate the underlying collection, rather than the grid directly.
Based on the limited description of your problem I would imagine you
would need to create dynamic objects with property names that correspond
to the dataFields of your dynamically created datagrid columns.
So if you had created columns with dataFields "alpha", "beta" and
"gamma" on your datagrid, you could create an item in your grid by
adding the following object to your dataProvider:
var gridItem : Object = new Object();
gridItem.alpha = "alphaValue";
gridItem.beta = "betaValue";
gridItem.gamma = "gammaValue"; -
Date as column names in a table
SELECT days all_fridays
FROM (
SELECT TO_DATE('0101', 'DDMM') + LEVEL - 1 days
FROM dual CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(TO_DATE('3112', 'DDMM'), 'DDD'))
WHERE to_char(days, 'DY') = 'FRI'Using the above query I'm getting the date's of all 'FRIDAY' day for the current year.
Please help me with a query or pl/sql block that can create a table (t) with these dates as column names.
Also, Can we create a table with dates as column names?
Thank YouWe are all more than welcome to help if you can post your information here. Please don't forget to identify your Oracle version (ex: 10.2.0.4) and post things like the sample data and layout using \ tags (See FAQ for more information on use of tags).
Thanks! -
Hi All,
Can we have substr(date) as column name. I am trying to create a query where in I need to achieve something like this
select s.xyz Today,
s.abcd "6 Months ago" || to_char(add_months(sysdate,-6),'Mon rrrr') ||')'
from sales_tab s
Any idea.
Thanks,BarbaraBoehmer wrote:
SCOTT@orcl12c> CREATE TABLE sales_tab
2 (xyz NUMBER,
3 abcd NUMBER)
4 /
Table created.
SCOTT@orcl12c> INSERT INTO sales_tab VALUES (1234, 24563)
2 /
1 row created.
SCOTT@orcl12c> VARIABLE g_ref REFCURSOR
SCOTT@orcl12c> DECLARE
2 v_sql VARCHAR2(32767);
3 BEGIN
4 v_sql := 'SELECT xyz "Today",
5 abcd "6 Months ago ('
6 || TO_CHAR (ADD_MONTHS (SYSDATE, -6), 'Mon YYYY')
7 || ')"
8 FROM sales_tab';
9 OPEN :g_ref FOR v_sql;
10 END;
11 /
PL/SQL procedure successfully completed.
SCOTT@orcl12c> PRINT g_ref
Today 6 Months ago (Feb 2013)
1234 24563
1 row selected.
Ok.
Exactly what I was talking about. Creating a customized, date dependent column header in the report. -
How to set FK to column name only, after engineering
Hi everyone,
On Logical model I have 2 tables, first one is Clients T085CLI with CODCLI as PK, the second one is Contacts T085CTO with CODCTO as PK and CODCLI as FK. After doing the engineering on T085CTO I get the following names, CODCTO (PK) and T085CLI_CODCLI (FK), but I would like the FK name as CODCLI only, without T085CLI_ prefix. Is there a configuration in somewhere to fix this?
I do appreciate if someone of you can help me with this.
Thanks in advance.
Oracle SQL Developer Data Modeler version 4.0.0.820Hi,
You should be able to do this by setting the template for foreign key columns in your model.
Go to the Browser, right-click over the entry for your Design and select Properties.
This will display the Design Properties dialog. In the tree in the left-hand panel select Settings > Naming Standard > Templates.
Update the entry for Column Foreign Key to {ref column}
David -
Hi Guys,
The data is like in the format below:
Item ID
COMM
PL
AC
RV
ESTB_ID
1
Q4-2013
Q4-2013
3
2
Q4-2013
Q4-2013
3
12
Q3-2013
Q3-2013
Q4-2013
3
The requirement is to group the data by establishment id and the no of items commissioned, planned, revised and actual in a quarter.
The result set should be like:
ESTB_ID
Item ID
PL Q3-2013
AC Q3-2013
RV Q3-2013
PL Q4-2013
AC Q4-2013
RV Q4-2013
3
1
0
0
0
1
0
1
3
2
0
0
0
1
0
1
3
12
1
0
0
0
1
0
What is the best way of achieving this result?
ThanksTake a look at the links in the FAQ:
Re: 4. How do I convert rows to columns?
Especially: PL/SQL 101 : Cursors and SQL Projection
and How to pipeline a function with a dynamic number of columns? -
JTable can't display column names and scroll bar in JDialog !!
Dear All ,
My flow of program is JFrame call JDialog.
dialogCopy = new dialogCopyBay(frame, "Bay Name Define", true, Integer.parseInt(txtSourceBay.getText()) ,proVsl ,300 ,300);
dialogCopy.setBounds(0, 0, 300, 300);
dialogCopy.setVisible(true); Then,I set the datasource of JTable is from a TableModel.
It's wild that JTable can diplay the data without column names and scroll bar.
I have no idea what's going wrong.Cause I follow the Sun Tutorial to code.
Here with the code of my JDialog.
Thanks & Best Regards
package com.whl.panel;
import com.whl.vslEditor.vslDefine;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
public class dialogCopyBay extends JDialog {
vslDefine glbVslDefine;
int lvCnt = -1;
JTable tableCopyBay;
int bgnX = 0;
int bgnY = 30;
int tableWidth = 100;
int tableHeight = 100;
public dialogCopyBay(Frame frame, String title, boolean modal, int sourceBay,
vslDefine pVslDefine, int ttlWidth, int ttlHeight) {
super(frame, title, true);
Container contentPane = getContentPane();
System.out.println("dialogCopyBay Constructor");
glbVslDefine = null;
glbVslDefine = pVslDefine;
copyBayModel copyBay = new copyBayModel((glbVslDefine.getVslBayStructure().length - 1),sourceBay);
tableCopyBay = new JTable(copyBay);
tableCopyBay.setPreferredScrollableViewportSize(new Dimension(tableWidth, tableHeight));
JScrollPane scrollPane = new JScrollPane(tableCopyBay);
scrollPane.setViewportView(tableCopyBay) ;
tableCopyBay.setFillsViewportHeight(true);
tableCopyBay.setBounds(bgnX, bgnY, tableWidth, tableHeight);
tableCopyBay.setBounds(10, 10, 100, 200) ;
contentPane.setLayout(null);
contentPane.add(scrollPane);
contentPane.add(tableCopyBay);
class copyBayModel extends AbstractTableModel {
String[] columnNames;
Object[][] dataTarget;
public copyBayModel(int rowNum ,int pSourceBay) {
columnNames = new String[]{"Choose", "Bay Name"};
dataTarget = new Object[rowNum][2];
for (int i = 0; i <= glbVslDefine.getVslBayStructure().length - 1; i++) {
if (pSourceBay != glbVslDefine.getVslBayStructure().getBayName() &&
glbVslDefine.getVslBayStructure()[i].getIsSuperStructure() == 'N') {
lvCnt = lvCnt + 1;
dataTarget[lvCnt][0] = false;
dataTarget[lvCnt][1] = glbVslDefine.getVslBayStructure()[i].getBayName();
System.out.println("lvCnt=" + lvCnt + ",BayName=" + glbVslDefine.getVslBayStructure()[i].getBayName());
public int getRowCount() {
return dataTarget.length;
public int getColumnCount() {
return columnNames.length;
public String getColumnName(int col) {
return columnNames[col];
public Object getValueAt(int rowIndex, int columnIndex) {
return dataTarget[rowIndex][columnIndex];
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
public boolean isCellEditable(int row, int col) {
if (col == 1) {
// Bay Name Not Allow To modify
return false;
} else {
return true;
public void setValueAt(Object value, int row, int col) {
dataTarget[row][col] = value;
fireTableCellUpdated(row, col);Dear DB ,
I am not sure what you mean.
Currently,I don't undestand which code is error.
And I also saw some example is add JTable and JScrollPane in JDialog.
Like Below examle in Sun tutorial
public class ListDialog extends JDialog implements MouseListener, MouseMotionListener{
private static ListDialog dialog;
private static String value = "";
private JList list;
public static void initialize(Component comp,
String[] possibleValues,
String title,
String labelText) {
Frame frame = JOptionPane.getFrameForComponent(comp);
dialog = new ListDialog(frame, possibleValues,
title, labelText);
* Show the initialized dialog. The first argument should
* be null if you want the dialog to come up in the center
* of the screen. Otherwise, the argument should be the
* component on top of which the dialog should appear.
public static String showDialog(Component comp, String initialValue) {
if (dialog != null) {
dialog.setValue(initialValue);
dialog.setLocationRelativeTo(comp);
dialog.setVisible(true);
} else {
System.err.println("ListDialog requires you to call initialize " + "before calling showDialog.");
return value;
private void setValue(String newValue) {
value = newValue;
list.setSelectedValue(value, true);
private ListDialog(Frame frame, Object[] data, String title,
String labelText) {
super(frame, title, true);
//buttons
JButton cancelButton = new JButton("Cancel");
final JButton setButton = new JButton("Set");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ListDialog.dialog.setVisible(false);
setButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ListDialog.value = (String) (list.getSelectedValue());
ListDialog.dialog.setVisible(false);
getRootPane().setDefaultButton(setButton);
//main part of the dialog
list = new JList(data);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
setButton.doClick();
JScrollPane listScroller = new JScrollPane(list);
listScroller.setPreferredSize(new Dimension(250, 80));
//XXX: Must do the following, too, or else the scroller thinks
//XXX: it's taller than it is:
listScroller.setMinimumSize(new Dimension(250, 80));
listScroller.setAlignmentX(LEFT_ALIGNMENT);
//Create a container so that we can add a title around
//the scroll pane. Can't add a title directly to the
//scroll pane because its background would be white.
//Lay out the label and scroll pane from top to button.
JPanel listPane = new JPanel();
listPane.setLayout(new BoxLayout(listPane, BoxLayout.Y_AXIS));
JLabel label = new JLabel(labelText);
label.setLabelFor(list);
listPane.add(label);
listPane.add(Box.createRigidArea(new Dimension(0, 5)));
listPane.add(listScroller);
listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
//Lay out the buttons from left to right.
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
buttonPane.add(Box.createHorizontalGlue());
buttonPane.add(cancelButton);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(setButton);
//Put everything together, using the content pane's BorderLayout.
Container contentPane = getContentPane();
contentPane.add(listPane, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.SOUTH);
pack();
public void mouseClicked(MouseEvent e) {
System.out.println("Mouse Click");
public void mousePressed(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
public void mouseReleased(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
public void mouseEntered(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
public void mouseExited(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
public void mouseDragged(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
public void mouseMoved(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
* This is here so that you can view ListDialog even if you
* haven't written the code to include it in a program.
} -
I want to display the patameters entered by the user as column names in interactive / classic report.
For example i enter the parameters as date, 10-03-2011, 11-03-2011 and 12-03-2011.
How i can display these dates as column names in report ?
SanjayIn a classic report, set the Headings Type (in the Report Attributes tab) to Custom and set the Heading to
&Px_PARAM1.
&Px_PARAM2.
&Px_PARAM3.
etc... -
Excel 2013 connect to a cube, and Power View concatenate the column name by default
Hi Guys,
Currently, we met a problem with excel services to connect to a cube, when we develope a Excel 2013 Powerview report, the data model column name is concatenate into terrible name by default. e.g. Dim TimeDate Date, Dim TimeTime HierachyYear -Month.
But when start up the data model with Powerpivot, everything gone well. We knew that it can be manual update the name as workaround, but we need to do it every time we create a new powerview with the data model.
Is that any other solution we can do with?
Please help.
JohnnyHi,
As this question is more related to PowerView Report, I suggest you can create a new post in the PowerView forum, you will get more helpful information from there.
PowerView Forum:
https://social.technet.microsoft.com/Forums/en-US/home?forum=powerview
Best Regards
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Jerry Guo
TechNet Community Support -
Possible to set a default column value to an expression?
Hi,
Is it possible to set a default column name to an expression when creating a table?
For example, I wish to set the default value of a column to read from another table's column and do some arithmetic....is this possible?
Thanks.Yes, you can, with trigger Before Insert for Each row
But be carefull, you can hit the mutating table problem... -
How to set column names when not using object of row data in constructer
hello i am using JTable constructer as
public JTable(int numRows,
int numColumns)
can i set column names for the columns .How?hi,
sure you can: Create a subclass of DefaultTableModel and overwrite the method public String getColumnName(int) which returns the column name of a specific column. Then use this subclass as the data model for the table.
best regards, Michael -
Calculation Field to be mapped to different data object's column name in Oracle BAM 12c
Hi,
I am having a challenge to enable drill down to 2nd level report by passing calculation field as parameter.
As an alternative, I am thinking to point calculation field to another data object’s column name and generate report so that I would be able to pass that as parameter to drilling report view.
Is there any way to map calculation field to different Data object’s column name? Thanks in advance.
Regards
Amik Basu1. Yes, you can.
SQL> create table ÜÝÞ( ßàá number(10));
Table created.
SQL> insert into ÜÝÞ values (10);
1 row created.1.1 and 1.2 and 2. You can choose UTF as your default character set. It allows the user of non-English characters in VARCHAR columns in your whole database. It is not per tablespace.
SQL> create table ÜÝÞ( ßàá varchar2(100));
Table created.
SQL> insert into ÜÝÞ values ('âãäçìé');
1 row created. -
Im getting an error when running a procedure that includes this code.
I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
DECLARE @retval AS DECIMAL(12,2)
DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
DECLARE @sqlcmd AS NVARCHAR(150)
DECLARE @paramdef NVARCHAR(150)
SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
--default
SET @retval = 0.0;
EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
SELECT @retval
DECLARE @return_value DECIMAL(12,2)
EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
@SpreadKey = 1,
@MonthNumber = 4
SELECT 'Return Value' = @return_value
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
>> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
the shoe size, the phone number or something else at run time of this entity.
In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point.
Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity.
Do you know that SQL is a declarative language? This family of languages does not use local variables!
Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.
Think about how silly this is:
SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental.
We need to see the DDL so we can re-write this mess. Want to fix it or not?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Set the column name of a table in a list box
is there any code to set the column name of a table in a list box at oracle devloper 6i?
pls help.I dont want to go for pl/sql . It should work any table.You want Dynamic SQL without using PL/SQL? Tricky. I'm sure there's a possible way using some very complex and convoluted XML functionality of SQL but in reality you are asking for something that isn't natural to SQL queries, especially if you are expecting a dynamic number of columns to be produced for each row of data. SQL expects a table structure, including output formats, to be a defined number of columns with any number of rows, not a defined number of rows with any number of columns.
Perhaps if you explain why you need this sort of functionality then we may be able to offer a better solution.
;) -
Bulk Load data without specifying column names in control file
I am totally new to the world of Oracle databases and am having some trouble doing some basic data imports from a csv file. I have a large amount of data in an excel spreadsheet (a couple hundred columns by varying numbers of rows from 2- several thousand) which I want to import into my Oracle 11g Database. Currently I am trying to use sql loader and specify the import syntax in the control file. From the examples I've seen so far, it seems you must specify the columns individually for what you are importing. This is simply not reasonable for several hundred columns of data.
Is there sql loader syntax (or a better method all together) to import a comma delimited csv or excel spreadsheet into an oracle database where it automatically generates a table and columns based on the data in the target import file? Even if I must first create the table in the database, my key issue is being able to generate the column names during import to match the column headers in the import file. I appreciate any help you could provide.
FYI here is my first meager attempt at importing a comma delimited csv, here is my ctl file:
load data
infile 'C:\filepath\mock_data.csv'
into table allData
fields terminated by "," optionally enclosed by '"'
It says Syntax error at line 4. Expecting "(", found end of file.
I suspect there is more at issue here than a missing "("You have to create the control file to map to the table.
Since you would already have created the tables, you could generate the controlfiles based on the table structures.
See the "unloader.zip" file under the Files link at http://asktom.oracle.com
-- it has scripts to create unload a table to a flat file and to create the SQLLoader controlfile to reload that data to another target database. It would be the second set of scripts that you can use.
Hemant K Chitale
Maybe you are looking for
-
Firefox don't open but it apears in task manager
When i click on firefox icon... nothing happens. I'll go to task manager and there it is... firefox. But it won't open...
-
Windows 8.1 Pro Shutdown / Sleep power still running
Windows 8.1 Pro cant Shutdown / Sleep . i think is BIOS problem... i want a flash BIOS tools laptop model : v480 (20143) BIOS: H1ET75WW (1.18)
-
IPhoto version 9.5.1 (latest)
Hello all, When i upgraded iPhoto to version 9.5.1, I lost all my latest photos. Does anyone know what happened?
-
ITunes cannot connect to my iPhone4. Unknown error (0xE8000003).
iTunes cannot connect to my iPhone4. Unknown error (0xE8000003).
-
Closing Illustrator Window!
Is there ANY keystroke that will send the EMPTY Illustrator window to the dock after you have saved your work? Can't find a solution to get rid of the darn blank window that obscures other windown behind it - you know like a cmd. W! so I can work i